Skip to content

Translated sidebar no longer translated once versioned #2266

Closed

Description

@arnaud4d

🐛 Bug Report

Sidebar is properly translated through i18n folder json files. But a versioned sidebar does not show its existing translations, despites version ids are added to both json files and versioned markdown files.

Have you read the Contributing Guidelines on issues?

yes

To Reproduce

  1. Translate your sidebar using the appropriate i18n folder json files
  2. Create a version using yarn run version
  3. Make sure versioned pages are translated, launch docusaurus and open a versioned translated page

Expected behavior

Sidebar labels and page title are translated

Actual Behavior

Sidebar labels and page title are not translated

Reproducible Demo

You can see the issue on docusaurus website :

Activity

  1. added
    bug
    status: needs triage
    on Feb 4, 2020
  2. phimage commented on Feb 5, 2020

    @phimage

    Maybe the passed reference directory is not correct here
    https://github.com/facebook/docusaurus/blob/a5996829efe759083be1689c349e13ef04f6806b/packages/docusaurus-1.x/lib/write-translations.js#L106

    and must be replaced by something like that

      glob.sync(`${versionedDocsDir}/*`).forEach(oneVersionDocsDir => {
        glob.sync(`${oneVersionDocsDir}/**`).forEach(file => translateDoc(file, oneVersionDocsDir));
      });

    but not sufficient

    This fix transform version-18.0/AFolder/version-18.0-myPage to AFolder/version-18.0-myPage
    The page id is version-18.0-myPage in versionned_docs/..18.0/AFolder/myPage.md
    but the versionned sidebars need version-18.0-AFolder/myPage not AFolder/version-18.0-myPage

    EDIT:
    a solution that edit the id to match with side bar ones by passing the version to translateDoc

      const translateDoc = (file, refDir, versionPrefix) => {
        const extension = nodePath.extname(file);
        if (extension === '.md' || extension === '.markdown') {
          let res;
          try {
            res = readMetadata.processMetadata(file, refDir);
          } catch (e) {
            console.error(e);
            process.exit(1);
          }
          if (!res) {
            return;
          }
          const metadata = res.metadata;
          var id = metadata.localized_id;
    
          if (versionPrefix) {
            id = versionPrefix+id.replace(versionPrefix,"");
          }
          translations['localized-strings'].docs[id] = {};
          translations['localized-strings'].docs[id].title = metadata.title;
    
          if (metadata.sidebar_label) {
            translations['localized-strings'].docs[id].sidebar_label =
              metadata.sidebar_label;
          }
        }
      };
      glob.sync(`${docsDir}/**`).forEach(file => translateDoc(file, docsDir));
      glob.sync(`${versionedDocsDir}/*`).forEach(oneVersionDocsDir => {
        var versionPrefix = oneVersionDocsDir.split('/').reverse()[0]+"-";
        glob.sync(`${oneVersionDocsDir}/**`).forEach(file => translateDoc(file, oneVersionDocsDir, versionPrefix));
      });
  3. phimage commented on Feb 10, 2020

    @phimage

    There is another issue. If the page is not modified in the version then the markdown do not exist.
    The is present in sidebar definition version-VERSION_NAME-PAGE_ORIGINAL_ID do not exists in translations files en.json (so not also in fr. jso, de.json, etc...)

    In SideNav.js getLocalizedString we try to get localized string using this unknown id
    https://github.com/facebook/docusaurus/blob/ef1af0a5be649aa630d913bdf212c620ec082156/packages/docusaurus-1.x/lib/core/nav/SideNav.js#L29
    we fallback into english version

    a dirt fix, try with original_id also (I think we want previous version translation instead of this one but it could work if no change)

      getLocalizedString(metadata) {
        let localizedString;
        const i18n = translation[this.props.language];
        const id = metadata.localized_id;
        const original_id = metadata.original_id || id;
        const sbTitle = metadata.sidebar_label;
    
        if (sbTitle) {
          localizedString =
            idx(i18n, ['localized-strings', 'docs', id, 'sidebar_label']) 
            || idx(i18n, ['localized-strings', 'docs', original_id, 'sidebar_label']) 
            || sbTitle;
        } else {
          localizedString =
            idx(i18n, ['localized-strings', 'docs', id, 'title']) 
            || idx(i18n, ['localized-strings', 'docs', original_id, 'title']) 
            || metadata.title;
        }
        return localizedString;
      }
  4. tochi-y commented on Mar 3, 2020

    @tochi-y

    I got this problem too, and wish it would be resolved.

    I did a workaround referring @phimage 's comments.

    • Replace all keys like version-0.0.1/ADirectory/version-0.0.1-doc1 in i18n/{locale}.json with version-0.0.1-ADirectory/doc1
    • If versioned markdown is not, copy existing old one

    It properly worked. But this is just a workaround.

  5. added
    v1
    difficulty: intermediate
    and removed
    status: needs triage
    on Jun 5, 2020
  6. slorber commented on Jun 10, 2021

    @slorber
    Collaborator

    The Docusaurus team is actively working on Docusaurus v2.

    After a very long alpha, Docusaurus v2 is now in beta.
    We believe that the v2 beta is already better than v1, and v2 is ready for maintstream adoption.

    Apart from critical issues and security fixes, we don't plan to invest much time on Docusaurus v1 anymore.

    We are all closing v1 issues.
    Maybe the current issue is already fixed in Docusaurus v2.
    Please try to upgrade, and if the issue is still there on Docusaurus v2, open a new issue.

  7. brianlagunas commented on Dec 4, 2022

    @brianlagunas

    I’ve recently started moving from docfx to Docusaurus. During my testing today, I have run into this same issue. If I provide the repo, can the team check it out or should I open a new issue?

  8. slorber commented on Dec 8, 2022

    @slorber
    Collaborator

    @brianlagunas this is an old Docusaurus v1 issue, and you are likely using Docusaurus 2.0, so what you encounter is likely a different thing. Please create a v2 small repro and open a new issue is you think something doesn't work as expected.

    FYI sidebar items translations work for our own website with versioning enabled, see https://docusaurus.io/fr/docs/2.0.1

    Take also a look at the current limitations of i18n, some things are not yet translatable:
    #4542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdifficulty: intermediatev1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions