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

[l10n] Enable lingui, string extraction #810

Merged
merged 16 commits into from
Sep 2, 2021
Merged

Conversation

himdel
Copy link
Collaborator

@himdel himdel commented Aug 16, 2021

Depends on #742 (merged)
Fixes AAH-803

This adds gettext:extract and gettext:compile tasks, and switches to the browser-preferred language when available.

Workflow:

  1. run gettext:extract to extract translatable strings from src/ into locale/*.po
  2. those *.po files get uploaded to a translation service (outside automation)
  3. updated *.po files get downloaded from the service and merged in (use msgmerge to resolve conflicts if necessary)
  4. run gettext:compile to create locale/*.js files for each po counterpart
  5. webpack automatically builds each locale js into a separate bundle
  6. using a dynamic import in src/l10n.ts to import the right one at runtime

This also removes the temporary l10n function from #677,
and renames the callers from _`str` to t`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 in src/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):

import { t } from '@lingui/macro';
const data = "untranslated";
const string = t`Hello ${data}`;

(translators will see Hello {data}, translate to something like Hola {data} resulting in Hola 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 see Hello {0}, they won't know what {0} means without context.

Translating where a JSX result is expected (string with html):

import { Trans } from '@lingui/macro';
const data = "untranslated";
const MyComponent = () => (
  <Trans>Hello <b>World</b>: {data}</Trans>
);

(translators will see Hello <0>World</0>: {data}, translate to Hola <0>mundo</0>: {data} resulting in Hola mundo: untranslated)

Translating plurals:

import { plural } from '@lingui/macro';
const myCount = 123;
const string = plural(myCount, {
  one: '# byte',
  other: '# bytes',
}); // yields 0 bytes, 1 byte, 2 bytes, ... depending on myCount

(translators will see {myCount, plural, one {# byte} other {# bytes}}, translate to something like {myCount, plural, one {# byt} few {# byty} other {# bytů}}, yielding 0 bytů, 1 byt, 2 byty, ..., 5 bytů depending on myCount)

himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 17, 2021
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
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 18, 2021
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
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 20, 2021
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
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 27, 2021
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
himdel added a commit that referenced this pull request Aug 30, 2021
…#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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 31, 2021
…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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 31, 2021
…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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 31, 2021
…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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Aug 31, 2021
…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)
@himdel himdel force-pushed the l10n-lingui branch 2 times, most recently from 0e73243 to 344fc89 Compare August 31, 2021 19:48
@himdel himdel changed the title [WIP] [l10n] Enable lingui, string extraction [l10n] Enable lingui, string extraction Aug 31, 2021
@himdel
Copy link
Collaborator Author

himdel commented Aug 31, 2021

Testing...

deliberately left a cs locale available, (we have others now)
you can edit locale/fr.po to translate a string,
run npm run gettext:compile,
and as long as webpack is running and the browser is set to use the language, it will :)

@himdel
Copy link
Collaborator Author

himdel commented Aug 31, 2021

Cc @ZitaNemeckova this should be ready :) (hm, the spec is passing locally, I'll fix that bit tomorrow)

Cc @ShaiahWren and @jerabekjiri read the Examples section in the description above please, we had to change the marker from _ to t, and we can also do translated string with html/react inside and plurals now :)

ZitaNemeckova pushed a commit that referenced this pull request Sep 1, 2021
…#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"],
Copy link
Member

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:

image

Copy link
Collaborator Author

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/.)

Copy link
Member

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!

@himdel himdel mentioned this pull request Sep 2, 2021
5 tasks
Copy link
Member

@ZitaNemeckova ZitaNemeckova left a 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
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`);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@himdel himdel merged commit 685591f into ansible:master Sep 2, 2021
@himdel himdel deleted the l10n-lingui branch September 2, 2021 14:39
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Sep 6, 2021
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Sep 6, 2021
ZitaNemeckova pushed a commit that referenced this pull request Sep 7, 2021
* NamespaceDetail, DeleteGroupModal: remove dead variables

(rebase issue between #790 and #810)

* DateComponent: wrap any "updated <DC/>" in Trans, whole
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Jan 25, 2023
…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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Jan 25, 2023
…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)
himdel added a commit that referenced this pull request Jan 30, 2023
…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.
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Jan 30, 2023
…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)
himdel added a commit to himdel/ansible-hub-ui that referenced this pull request Jan 30, 2023
…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)
himdel added a commit that referenced this pull request Jan 30, 2023
…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)
himdel added a commit that referenced this pull request Jan 30, 2023
…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)
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.

None yet

3 participants