-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Comments
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 EDIT: 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));
}); |
There is another issue. If the page is not modified in the version then the markdown do not exist. In SideNav.js getLocalizedString we try to get localized string using this unknown id
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;
} |
I got this problem too, and wish it would be resolved. I did a workaround referring @phimage 's comments.
It properly worked. But this is just a workaround. |
The Docusaurus team is actively working on Docusaurus v2. After a very long alpha, Docusaurus v2 is now in beta. 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. |
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? |
@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: |
🐛 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
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 :
translated non-versioned page (next) in FR, sidebar labels and title are translated:
https://docusaurus.io/docs/fr/next/custom-pages
translated versioned page (1.1.4) in FR, sidebar labels and title are NOT translated:
https://docusaurus.io/docs/fr/custom-pages
The text was updated successfully, but these errors were encountered: