Add support for classical gettext style localization.
Wrap any message with __('Text to translate'). This localization
function is passed down in React context from App file, and is
automatically updated with correct message strings, user preference is
set in local.language state.
Important gotcha is to check for context changes in every of
shouldComponentUpdate calls, otherwise that part of app will stay in
English.
We're using custom grep-based script to extract messages from source
code, as none of the solutions are working with jsx files properly.
After inserting new messages in source code with __() function, run
npm run i18n extract, which would create a template.pot file in
app/i18n.
Update main.pot in Crowdin project. That would add new keys to
Crowdin.
Translate those keys into supported languages
Hit build&download in Crowdin and place .po files into app/i18n naming
them e.g. like ru.po.
Run npm run i18n extract again, it would convert new .po files to
.json, and place them into the same folder. Make sure that .po files
comming from Crowdin have correct headers, Crowdin sometimes strips them
out, which would cause conversion to json to fail. Only the .json files
have to be commited.
This whole process could be automated via crowdin-cli and API, possibly
in a CircleCI job, but I don't feel like doing it at the moment.
One problem with this implementation, is that available languages are
hardcoded in various places. However it is not easy to fix it, as we
currently don't have a single place settings, which would both be
available on the client and server side. Once it is fixed, it would be
fairly easy to replace hardcoded languages.
Add support for classical gettext style localization. Wrap any message with
__('Text to translate')
. This localization function is passed down in React context from App file, and is automatically updated with correct message strings, user preference is set inlocal.language
state.Important gotcha is to check for context changes in every of
shouldComponentUpdate
calls, otherwise that part of app will stay in English.We're using custom grep-based script to extract messages from source code, as none of the solutions are working with jsx files properly.
In addition to that, our project recived an opensource license from Crowdin: https://crowdin.com/project/shrimpjs
Localization workflow:
__()
function, runnpm run i18n extract
, which would create a template.pot file in app/i18n.npm run i18n extract
again, it would convert new .po files to .json, and place them into the same folder. Make sure that .po files comming from Crowdin have correct headers, Crowdin sometimes strips them out, which would cause conversion to json to fail. Only the .json files have to be commited.This whole process could be automated via crowdin-cli and API, possibly in a CircleCI job, but I don't feel like doing it at the moment.
One problem with this implementation, is that available languages are hardcoded in various places. However it is not easy to fix it, as we currently don't have a single place settings, which would both be available on the client and server side. Once it is fixed, it would be fairly easy to replace hardcoded languages.
Closes: #297