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

Translated sidebar no longer translated once versioned #2266

Closed
arnaud4d opened this issue Feb 4, 2020 · 6 comments
Closed

Translated sidebar no longer translated once versioned #2266

arnaud4d opened this issue Feb 4, 2020 · 6 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. v1 This issue is for Docusaurus 1

Comments

@arnaud4d
Copy link

arnaud4d commented Feb 4, 2020

🐛 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 :

@arnaud4d arnaud4d added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Feb 4, 2020
@phimage
Copy link

phimage commented Feb 5, 2020

Maybe the passed reference directory is not correct here

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));
  });

@phimage
Copy link

phimage commented Feb 10, 2020

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

getLocalizedString(metadata) {

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;
  }

@tochi-y
Copy link

tochi-y commented Mar 3, 2020

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.

@yangshun yangshun added v1 This issue is for Docusaurus 1 difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. and removed status: needs triage This issue has not been triaged by maintainers labels Jun 5, 2020
@slorber
Copy link
Collaborator

slorber commented Jun 10, 2021

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.

@slorber slorber closed this as completed Jun 10, 2021
@brianlagunas
Copy link

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?

@slorber
Copy link
Collaborator

slorber commented Dec 8, 2022

@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
Labels
bug An error in the Docusaurus core causing instability or issues with its execution difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. v1 This issue is for Docusaurus 1
Projects
None yet
Development

No branches or pull requests

6 participants