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

i18n: adds translation support #307

Merged
merged 1 commit into from
Jul 5, 2021
Merged

Conversation

mb-wali
Copy link
Contributor

@mb-wali mb-wali commented Jun 22, 2021

related issue inveniosoftware/react-invenio-forms/issues/6

Uploads.mp4

Dependencies

  • i18next
  • i18next-browser-languagedetector (detect user language)
  • i18next-scanner (extract translation keys/values)
  • i18next-conv (converts files from gettext (.mo/.po) to i18next's json format and vice versa)

Mark for translation

import created instance in your package.
import i18next from '../i18next';

Mark for translation

--- <List.Item>Storage available</List.Item>
+++ <List.Item>{i18next.t('Storage available')}</List.Item>

Extract translations

To scan your code, extract translation keys/values, and merge them into i18n resource files.

npm run i18n-scan

Create/update .pot file, this file is pushed to transifex

converts source language file from JSON to .pot

npm run i18n-conv-json

Convert/update .po files to json.

once translation is pulled from transifex, the format is .po, in order to convert these files to JSON format run following command.

npm run i18n-conv-po --lang="<lang>"

Convert/update all the .po files for all available languages

npm run i18n-conv-po-all

src/lib/i18next.js Outdated Show resolved Hide resolved
@mb-wali mb-wali marked this pull request as draft June 22, 2021 09:08
Copy link
Contributor

@ntarocco ntarocco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed with @zzacharo and it looks a nice implementation, it is maybe missing a little bit more "plumbing".

To extract all the translations, it looks like that we can use 18next-scanner (to be tested!!!). It could be added as a command in the package.json.
Then we will have to document how to upload the extracted keys to Transifex, and we might need some config file here for the Transifex integration.

At the end, when we download the .po catalog from Transifex with the translations, we found that we could use i18next-gettext-converter, again to be tested and integrated in the package.json.

What do you think?

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/lib/index.js Outdated Show resolved Hide resolved
@mb-wali
Copy link
Contributor Author

mb-wali commented Jun 24, 2021

We have discussed with @zzacharo and it looks a nice implementation, it is maybe missing a little bit more "plumbing".

To extract all the translations, it looks like that we can use 18next-scanner (to be tested!!!). It could be added as a command in the package.json.
Then we will have to document how to upload the extracted keys to Transifex, and we might need some config file here for the Transifex integration.

At the end, when we download the .po catalog from Transifex with the translations, we found that we could use i18next-gettext-converter, again to be tested and integrated in the package.json.

What do you think?

I like it, sounds like a plan. I will start digging into this. Thanks

@mb-wali mb-wali force-pushed the i18next branch 5 times, most recently from bcc7bd0 to 6f6fa45 Compare June 28, 2021 12:19
i18next-scanner.config.js Outdated Show resolved Hide resolved
i18next-scanner.config.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
src/lib/i18next.js Outdated Show resolved Hide resolved
@mb-wali mb-wali force-pushed the i18next branch 4 times, most recently from f48b5bc to a526762 Compare June 29, 2021 13:23
@mb-wali mb-wali marked this pull request as ready for review June 30, 2021 10:06
Copy link
Member

@zzacharo zzacharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks very good @mb-wali !!! Just some small comments but the flow seem neat!

i18next-scanner.config.js Outdated Show resolved Hide resolved
i18next-scanner.config.js Outdated Show resolved Hide resolved
@@ -17,6 +17,9 @@
"postlink-dist": "cd dist && rm -rf node_modules",
"unlink-dist": "cd dist && npm unlink && rm package*",
"watch": "NODE_ENV=development rollup --watch -c",
"i18n-scan": "i18next-scanner --config i18next-scanner.config.js src/**/*.{js,jsx}",
"i18n-conv-json": "i18next-conv -l en -s ./src/lib/translations/en/translations.json -t ./src/lib/translations/translations.pot",
"i18n-conv-po": "i18next-conv -l $npm_config_lang -s ./src/lib/translations/$npm_config_lang/messages.po -t ./src/lib/translations/$npm_config_lang/translations.json",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we will need to have i18n-conv-po-all function to compile all the .po files for all available languages...Maybe the configured languages could be set here as a config variable https://docs.npmjs.com/cli/v7/configuring-npm/package-json#config

"i18n-scan": "i18next-scanner --config i18next-scanner.config.js src/**/*.{js,jsx}",
"i18n-conv-json": "i18next-conv -l en -s ./src/lib/translations/en/translations.json -t ./src/lib/translations/translations.pot",
"i18n-conv-po": "i18next-conv -l $npm_config_lang -s ./src/lib/translations/$npm_config_lang/messages.po -t ./src/lib/translations/$npm_config_lang/translations.json",
"i18n-conv-po-all": "node ./getTextConverter.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mb-wali what about merging the i18n-conv-po and this command by simply adding an extra argument e.g --all to comply also with what tx command is using for pulling all languages? I can approve this PR if you think this is a lot of work to be done now and we can open an issue for that :)

@zzacharo zzacharo merged commit 7003810 into inveniosoftware:master Jul 5, 2021
@mb-wali mb-wali deleted the i18next branch January 28, 2022 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants