-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Translations API only seems to be working for "src/pages" directory #4341
Comments
Thanks, you are 100% right, there is a problem. I see what is happening and it will be fixed tomorrow. |
Thank you very much for the quick response! Kudos to the Docusaurus team! |
thanks Will be fixed by #4345 Please add your site to the showcase when it's ready ;) we want i18n sites there |
I believe that's perfect for now! We'll begin using it as soon as it's merged and available. Thanks a lot!
Will do :) |
merged, let me know if |
Using I'll let you know if we come across any other difficulties using the translations API, as we continue to use it through our website. I hope Docusaurus keeps on improving as it currently is! |
thanks ;) |
🐛 Bug Report
I'm currently working on a project that uses Docusaurus v2 to generate documentation pages. We've been following the updates regarding the i18n functionalities to be released in
2.0.0-alpha.71
(as per the documentation).Our site needs to be available at multiple languages (the default locale is portuguese, but it should support at least english and spanish), and so, we've followed the tutorial on Docusaurus website that gives some details on how to setup the project (specially considering directories structure) for multiple languages and how to use the translation APIs.
As of the current release (
2.0.0-alpha.70
), the i18n functionalities are not entirely available, so we decided to use the@canary
tag until the next release comes out, in order to begin using and checking the i18n functionalities to translate our site.The translation of the markdown files is working just fine (placing the translated files under
i18n/<locale>/<pluginName>-<pluginId>/current
folder). The translation of the navbar, footer and sidebar information is working fine as well.However, we also need to translate some text that is in
.js
files (React components). In order to so, we've surrounded the text we wanted translated with<Translate>
tags. After running thedocusaurus write-translations
command, thecode.json
was indeed created, but it only contained entries for translating the text of the files under thesrc/pages
directory. All of the other files within thesrc
directory (including files on the root of thesrc
directory and files within subfolders of thesrc
directory) were left unnacounted for in thecode.json
file (even though<Translate>
tags were also placed in them) - which seems to differ from the explanation given in the tutorial.I did some searching to check if there were any issues regarding this limitation, but couldn't find any. Is this supposed to be the expected behavior of the translation API? Or is it a known problem that should be investigated in order to be solved? Or am I missing something and there is already a solution to this?
Personally, I believe it would be a little bit inadequate that only files under the
src/pages
could get translated, since that would take away many of the capabilities of reusing React components throughout the application. It also feels a little strange to me that I'd have to add a page in my site if I wanted to get some text translated - specially considering that a React component could be used in many places of the application.Have you read the Contributing Guidelines on issues?
Yes.
To Reproduce
I can't share the project I'm working on, but I've set up a small Docusaurus project that reproduces the problem we are facing.
git clone https://github.com/JHKroger00/translation-i18n.git
yarn
(to install dependencies)yarn docusaurus write-translations --locale pt
src
directory) that have<Translate>
tags, but are outside thesrc/pages
directory, don't have their text translated (the entries are not added to thecode.json
file ini18n/pt
folder).yarn start --locale pt
(for this setup, I left the default locale as english and chose portuguese as another language)Translation Test
andAnother Translation Test
at the bottom of the page)Expected behavior
The
code.json
file should contain entries for translating all the text that was surrounded by<Translate>
tags (for all files under thesrc
directory).Actual Behavior
The
code.json
file only contains entries for translating the text surrounded by<Translate>
tags for the files undersrc/pages
directory (all the other subfolders of thesrc
are apparently ignored).Here is a snapshot of the homepage of the site showing the problem with the translations (some parts were purposely left untranslated because I did not want to spend too much time writing translations that wouldn't make much difference).
Here is a snapshot of the
code.json
file showing that entries outside thesrc/pages
folder were not added (the entries showed correspond to text that is in thesrc/pages/index.js
file).If you want to check the files themselves, I've added
<Translate>
tags to thesrc/pages/index.js
file (which do get translated), and to thesrc/components/test.js
andsrc/anotherTest.js
files (which do not get translated, even though the latter is in the root of thesrc
directory).Your Environment
package.json
shows2.0.0-alpha.4162e6dcd
as@docusaurus/core
dependency)npx @docusaurus/init@latest init website classic
Reproducible Demo
Given the dependencies of the project (since we are using the @canary version), I wasn't able to set up the demo in SandBox. So, the reproducible demo repo that should be used can be found at https://github.com/JHKroger00/translation-i18n.git.
After cloning the repo, the steps to reproduce explained above ("To Reproduce" section) should be enough to showcase the problem.
I have set up the project with
npx @docusaurus/init@latest init website classic
and followed the instructions given on the tutorial.I've also run the command
yarn add @docusaurus/@core@canary
to use the upcoming release (instead of the current version).The text was updated successfully, but these errors were encountered: