Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Ukrainian Localization for Solana Documentation #693

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Varavchik18
Copy link

Problem

Currently, the Solana documentation does not support any localization, including Ukrainian, despite the integration of Crowdin for translation management. This makes it difficult for non-English speaking users and developers to access the content in their native language.

Summary of Changes

This pull request adds Ukrainian localization for the Solana documentation. The translated files are placed in the docs/locales/uk directory, and the website may be updated to dynamically load the appropriate localized content based on the selected language.

If the Ukrainian language is selected, it will import documentation files from docs/locales/uk. If the language is not available, it defaults to the English documentation (/docs).

Additionally, this approach avoids the need for external platforms for translation management and ensures a smoother and more flexible localization experience.

  • Ukrainian translation added for all existing Solana documentation.
  • Dynamic loading of localized documentation based on the language selected on the website (note: this may be implemented in the solana-com repository in the future, and is not yet fully implemented).
  • Fallback to English documentation if the selected language folder is not found.

How Dynamic Import Can Be Implemented

To implement dynamic loading of localized content, the following modification can be made to the getStaticProps function in the solana-com repository:

export async function getStaticProps({ params, locale }) {
  const { slug = [] } = params;

  // define the base route for the requested content
  let route = `${RECORD_GROUPS.docs}/${slug.join("/")}`;

  // locate the current record being viewed (via the correctly formatted api route)
  if (locale !== 'en') {
    try {
      const localizedRoute = `/docs/locales/${locale}/${slug.join("/")}`;

      const localizedRecord = await ContentApi.getSingleRecord(localizedRoute, locale);

      if (localizedRecord) {
        route = localizedRoute;  
      }
    } catch (error) {
      console.error('Localized content not found, falling back to default docs path.');
    }
  }

  const record = await ContentApi.getSingleRecord(route, locale);

  // ensure the content record was found
  if (!record || !record.href) {
    return {
      notFound: true,
    };
  }

  // handle record redirects for altRoutes and external links
  const redirect = ContentApi.recordRedirectPayload(record, route, locale);
  if (redirect) return redirect;

  // serialize the content via mdx
  const source = await serializeMarkdown(
    record.body, 
    `${locale}-${record?.id}`,
  );

  // load the nav data
  const navData = await ContentApi.getNavForGroup("docs", locale);

  return {
    props: {
      ...(await serverSideTranslations(locale, ["common"])),
      record,
      source,
      navData,
    },
    revalidate: 60,
  };
}```

@Varavchik18 Varavchik18 requested a review from ZYJLiu as a code owner January 14, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant