-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
[WIP] Use Crowdin translations for reactjs.org #873
Conversation
Deploy preview for reactjs failed. Built with commit a8ad83e https://app.netlify.com/sites/reactjs/deploys/5b02eb3db3127403e81a46bb |
eb12f68
to
4b6e332
Compare
36c015d
to
8d73f1b
Compare
8d73f1b
to
70b9bd5
Compare
9914d2c
to
31381a8
Compare
9fc77dd
to
753d2c7
Compare
a3c0aac
to
e759552
Compare
The approach I'm currently taking is not very satisfying. It relies a lot on symlinks (that may cause pain for Windows contributors) and it only translates one section of the site (not even including the home page). I spoke with Eric today about how it would be nice to translate more of the site (e.g. the home page, the side navs, even blog posts) and we came up with a rough plan that I will discuss with Dan on Monday as sort of a sanity check:
Eric is going to make the necessary changes to our Crowdin config file and then get back to me. I'll start making the necessary changes to our download script and Gatbsy configs. We will need to decide on a redirect strategy for old, non-localized URLs. We could update Gatsby to generate server-side redirects for these so that they automatically point to English. Netlify also supports conditional redirects based on the Accept-Language header and GeoIP. It would also be great if we could rely on these (on the server) and maybe use an in-browser redirect for the client. Either way, we'll want to make sure navigation within a locale keeps you within that locale and doesn't require client side redirects for every click. (This would probably break Gatsby's preloading anyway.) |
Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours has expired. Before we can review or merge your code, we need you to email cla@fb.com with your details so we can update your status. |
@bvaughn Could we restart this work with |
Hey @koba04! I kind of dropped the ball here because other things came up. Thanks for the ping. I'm going to see if we can find a way to finish it out. I agree that it's important. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
This was 'fixed' in #1605. Thanks Brian! |
Relates to PR #82
TODO
Pre-release checklist
yarn install
is failing on Circle CIMaybe I should fork the (root project) Gatsby config files and use a feature flag approach to conditionally require the translation capable ones. Maybe that way we could land this as a work-in-progress without being fully committed.
Post-release checklist
How does it work?
Only content from the
content/docs
directory is localized. All other sections/pages remain English only.Downloading content from Crowdin
This PR adds a new root directory,
crowdin
. This directory contains some JavaScript files as well as a symlink for the default language (English) that points to thecontent/docs
directory:A new Yarn task has been added (
yarn crowdin:download
) that uses the Crowdin API to download translations into an__exported__
subdirectory:Next the task identifies which languages have been translated past a certain threshold (specified by
crowdin/config.js
). For these languages, the script creates symlinks in the__translated__
subdirectory:Gatsby integration
A new (local)
gatsby-plugin-crowdin
plugin has been created that knows how to create localized links to certain sections of the website (e.g. things within the translated "/docs" directory).The
gatsby-source-filesystem
plugin has also been configured to read all content from thecrowdin/__translated__/
andcrowdin/__untranslated__/
(symlinked) directories rather thancontent
. This way it consumes translated content when available. (Crowdin provides default language fallbacks for pages/sections that have not yet been translated for any given locale.)This configuration is done via
gatsby-config.js
:Because of the default initial symlink (
crowdin/__translated__/en-US/docs
->content/docs
) Gatsby will still serve English content when run locally, even if the Crowdin script has not been run. This should enable fast iteration and creation of new content.Translations can be updated by running
yarn crowdin:download
(or automatically as part of CI deployment).Language selector
A new Yarn task (
yarn crowdin:update-languages
) has been added to determine which translated languages have been downloaded. (This task is automatically run beforeyarn dev
oryarn build
in order to just-in-time update the list.) The task writes a list of locales to a local JSON file,languages.json
:This
languages.json
list is imported into a translations page (pages/translations.js
) and used to create a list of links to translated docs.Locale persistence
By default, legacy links to docs pages (e.g.
/docs/hello-world.html
) are re-routed to a new page (docs-language-redirect.js
) that determines which locale to redirect to (e.g./en-US/docs/hello-world.html
). This is done as follows:localStorage
for the user's selected language. If one is found, it is used.navigator.languages
). If any have been translated, it is used.Each time a user visits a localized docs path, the website updates their currently selected language (in
localStorage
) so that subsequent visits (within this session or a new session) will restore their selected language.Netlify also supports conditional redirects based on the
Accept-Language
header and GeoIP. It might be nice to use these instead (when running on the server) to pre-empt the client side redirect. This would need to be tested though, to make sure the two work well together.