-
Notifications
You must be signed in to change notification settings - Fork 76
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
[l10n] Enable lingui, string extraction #810
Conversation
babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary
babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary
babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary
babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary
…#742) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in #810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors)
…ansible#742) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in ansible#810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors) (cherry picked from commit 9f88cbc)
…ansible#742) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in ansible#810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors) (cherry picked from commit 9f88cbc)
…ansible#742) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in ansible#810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors) (cherry picked from commit 9f88cbc)
…ansible#742) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in ansible#810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors) (cherry picked from commit 9f88cbc)
0e73243
to
344fc89
Compare
Testing...
|
Cc @ZitaNemeckova this should be ready :) Cc @ShaiahWren and @jerabekjiri read the Examples section in the description above please, we had to change the marker from |
…#742) (#858) * package.json: sort .scripts many scripts now, sort by name no other changes * package.json: update dependencies, devDependencies the point is to update to webpack5, but it depends on and is depended on by redhat cloud services and patternfly needs new webpack, while new sass needs new patternfly and webpack needs loaders the rest is minor (not updating husky - newer versions don't autoinstall) * webbpackConfig.serve -> webpackConfig.devServer * fonts: use type: asset/resource instead of file-loader * @redhat-cloud-services/frontend-components*: fix import paths * add missing style-loader used in production * switch style-loader and mini-css-extract-plugin around style-loader: css ends up in js bundles, about 2x as big takes about half the time to run mini-css-extract-plugin: css ends up in dist/css, about half the size takes about 2x longer given that, we care more about size in production and more about speed in development, switching around :) + ensure only css, sass and scss are treated as css-like * .babelrc: add typescript plugin, use for .js, .jsx, .ts, .tsx lingui relies on babel to transform the code, so we need babel to understand typescript this also allows us to use proper typescript as a linter, independent of the compiler and it speeds up the dev build by a factor of ~2 also removed plugin-proposal-object-rest-spread and plugin-proposal-class-properties as they are part of preset-env now * webpack watchOptions: ignore vim swapfiles when watching * get_human_size: unmark string, fixed in #810 babel uses a different compile order and get_human_size.ts and paths.ts are 2 files which need _ at module load time 810 adds the lingui helper, so, this is just temporary * package.json: add lint:ts, runs tsc; add skipLibCheck skipLibCheck typescript config is needed because typescript fails on 89 node_modules/@types/webpack/index.d.ts errors seems to be a conflict between new typescript (4.3.5, current) and old @types/webpack, temporary problem because it's a dep of frontend-components-config └─┬ @redhat-cloud-services/frontend-components-config@4.3.3 └─┬ clean-webpack-plugin@3.0.0 └── @types/webpack@4.41.30 * remove devServer override, the original works better in dev handles index redirect and publicPath and thus no need for common.webpack, as the last import was the path * add fork-ts-checker-webpack-plugin https://github.com/TypeStrong/fork-ts-checker-webpack-plugin the plugin runs typescript for type checking during the compilation, it's not fatal in development (changes will apply despite the errors), it is fatal in production (dist/ won't get emitted when there are errors) (cherry picked from commit 9f88cbc)
.linguirc
Outdated
"include": ["<rootDir>/src"] | ||
}], | ||
"format": "po", | ||
"locales": ["en", "cs"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@himdel do you mind adding "es", "fr", "nl", "ja", "zh"
to this list?
I tested this out and it appear to work properly:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated :)
(I also had to add it to the list in src/l10n.js
, but I'll look into updating that to read the list of available locales from locales/
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, so that the compiled language files get imported by the UI. Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
…ettext:compile tasks pretty much just adds default lingui config and deps
…ded .po to prettierignore
…ctivate the translation
get_human_size - use plural correctly for the number of bytes czech translation should have 3 plurals, english 2 paths - use t`` now +extract, clean old string, translate, compile
perl -i -npe 's/\b_\`/t\`/g' src/**
rg '\bt`' | cut -f1 -d: | sort -u | while read fn; do (echo '0a'; echo 'import { t } from '\''@lingui/macro'\'';'; echo '.'; echo 'wq') | ed "$fn"; done
src/l10n.ts:13:30 - error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. 13 const { messages } = await import(`src/../locale/${locale}.js`); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extraction trims trailing whitespace detect: rg \\bt'`'.*' `' fixed all of them by adding params inside, or adding and extra `{' '}` react bit
needed for Trans
(rebase issue between ansible#790 and ansible#810)
(rebase issue between ansible#790 and ansible#810)
…lization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since ansible#810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. This makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param (Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch.) No-Issue (but really AAP-4750)
…lization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since ansible#810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750)
…lization; `?lang=` to force language (#3225) * Support `?pseudolocalization=true|false` to enable/disable pseudolocalization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since #810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750) * Allow ?lang=ja to override detected language, ?lang= to unset it Visiting the UI with `?pseudolocalization=true` sets `localStorage.test_l10n = true`, and `?pseudolocalization=false` does `delete localStorage.test_l10n`. Now, also `?lang=ja` sets `localStorage.override_l10n = 'ja'`, and `?lang=` does `delete localStorage.override_l10n`. This allows the user to override the language by adding an URL param, and the UI will remember the choice until unset. Also adding two `console.debug` messages when pseudolocalization or langugage override are enabled, with URLs to disable again.
…lization; `?lang=` to force language (ansible#3225) * Support `?pseudolocalization=true|false` to enable/disable pseudolocalization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since ansible#810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750) * Allow ?lang=ja to override detected language, ?lang= to unset it Visiting the UI with `?pseudolocalization=true` sets `localStorage.test_l10n = true`, and `?pseudolocalization=false` does `delete localStorage.test_l10n`. Now, also `?lang=ja` sets `localStorage.override_l10n = 'ja'`, and `?lang=` does `delete localStorage.override_l10n`. This allows the user to override the language by adding an URL param, and the UI will remember the choice until unset. Also adding two `console.debug` messages when pseudolocalization or langugage override are enabled, with URLs to disable again. (cherry picked from commit 6ba2b97)
…lization; `?lang=` to force language (ansible#3225) * Support `?pseudolocalization=true|false` to enable/disable pseudolocalization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since ansible#810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750) * Allow ?lang=ja to override detected language, ?lang= to unset it Visiting the UI with `?pseudolocalization=true` sets `localStorage.test_l10n = true`, and `?pseudolocalization=false` does `delete localStorage.test_l10n`. Now, also `?lang=ja` sets `localStorage.override_l10n = 'ja'`, and `?lang=` does `delete localStorage.override_l10n`. This allows the user to override the language by adding an URL param, and the UI will remember the choice until unset. Also adding two `console.debug` messages when pseudolocalization or langugage override are enabled, with URLs to disable again. (cherry picked from commit 6ba2b97)
…lization; `?lang=` to force language (#3225) (#3245) * Support `?pseudolocalization=true|false` to enable/disable pseudolocalization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since #810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750) * Allow ?lang=ja to override detected language, ?lang= to unset it Visiting the UI with `?pseudolocalization=true` sets `localStorage.test_l10n = true`, and `?pseudolocalization=false` does `delete localStorage.test_l10n`. Now, also `?lang=ja` sets `localStorage.override_l10n = 'ja'`, and `?lang=` does `delete localStorage.override_l10n`. This allows the user to override the language by adding an URL param, and the UI will remember the choice until unset. Also adding two `console.debug` messages when pseudolocalization or langugage override are enabled, with URLs to disable again. (cherry picked from commit 6ba2b97)
…lization; `?lang=` to force language (#3225) (#3244) * Support `?pseudolocalization=true|false` to enable/disable pseudolocalization Pseudlocalization (>>marking<< strings marked for translation, instead of actually translating them), is supported since #810 by setting `localStorage.test_l10n = true` in the browser console and reloading the page. > Note: the current lingui implementation needs `npm run gettext:extract; npm run gettext:compile` for any new strings before they appear as marked. We should try to remove that limitation during the i18next switch. This PR makes it easier to enable/disable by setting a `?pseudolocalization=true/false` URL param, which gets used to set/unset `localStorage.test_l10n`. (Thus, after using `?pseudolocalization=true` once, you will see it until you explicitly set `?pseudolocalization=false`, even when visiting URLs without the param.) No-Issue (but really AAP-4750) * Allow ?lang=ja to override detected language, ?lang= to unset it Visiting the UI with `?pseudolocalization=true` sets `localStorage.test_l10n = true`, and `?pseudolocalization=false` does `delete localStorage.test_l10n`. Now, also `?lang=ja` sets `localStorage.override_l10n = 'ja'`, and `?lang=` does `delete localStorage.override_l10n`. This allows the user to override the language by adding an URL param, and the UI will remember the choice until unset. Also adding two `console.debug` messages when pseudolocalization or langugage override are enabled, with URLs to disable again. (cherry picked from commit 6ba2b97)
Depends on #742(merged)Fixes AAH-803
This adds
gettext:extract
andgettext:compile
tasks, and switches to the browser-preferred language when available.Workflow:
gettext:extract
to extract translatable strings fromsrc/
intolocale/*.po
*.po
files get uploaded to a translation service (outside automation)*.po
files get downloaded from the service and merged in (usemsgmerge
to resolve conflicts if necessary)gettext:compile
to createlocale/*.js
files for eachpo
counterpartsrc/l10n.ts
to import the right one at runtimeThis also removes the temporary l10n function from #677,
and renames the callers from
_`str`
tot`str`
, and adds the appropriate import.(lingui/js-lingui#1113)
And updates typescript module version to allow dynamic imports.
And fixes any string ending with a space - extract trims trailing whitespace, so we can't have
t`Strings `
end in a whitespace (we'll need a linter for that, added to AAH-804,rg \\bt'`'.*' `'
detects them).Current language is autodetected based on browser settings, and compared with the list of
availableLanguages
insrc/l10n.js
.It may be easier to install https://chrome.google.com/webstore/detail/locale-switcher/kngfjpghaokedippaapkfihdlmmlafcc for switching.
Examples:
Translating where a string result is expected (no jsx):
(translators will see
Hello {data}
, translate to something likeHola {data}
resulting inHola untranslated
in the UI)❗ Prefer using variables in string substition:
t`Hello ${data.data}`
is using an expression, not a simple variable, so the translators will seeHello {0}
, they won't know what{0}
means without context.Translating where a JSX result is expected (string with html):
(translators will see
Hello <0>World</0>: {data}
, translate toHola <0>mundo</0>: {data}
resulting in Hola mundo: untranslated)Translating plurals:
(translators will see
{myCount, plural, one {# byte} other {# bytes}}
, translate to something like{myCount, plural, one {# byt} few {# byty} other {# bytů}}
, yielding0 bytů, 1 byt, 2 byty, ..., 5 bytů
depending onmyCount
)