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

Gen3: Use i18next instead of loc #3689

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
51d69a0
poc use i18next
denysoblohin-okta Aug 9, 2024
564a821
lint fix
denysoblohin-okta Aug 9, 2024
4a07d89
set lang
denysoblohin-okta Aug 9, 2024
fc43412
don't conflict with odyssey
denysoblohin-okta Aug 9, 2024
74f3664
lint fix, no escape
denysoblohin-okta Aug 9, 2024
b03b8c7
lint fix
denysoblohin-okta Aug 9, 2024
56e7bec
fix fallback
denysoblohin-okta Aug 9, 2024
ff70cc8
fix transl
denysoblohin-okta Aug 9, 2024
ae2fb11
fix undefined bundle; emit lion error
denysoblohin-okta Aug 9, 2024
5f880af
lint fix
denysoblohin-okta Aug 9, 2024
2036015
jest mock fix
denysoblohin-okta Aug 9, 2024
628337d
lint fix
denysoblohin-okta Aug 9, 2024
d9acbfd
fix jest?
denysoblohin-okta Aug 9, 2024
df454f1
logic fix
denysoblohin-okta Aug 9, 2024
03259a5
fix for default language
denysoblohin-okta Aug 23, 2024
ee7ceb4
fix lint, plural
denysoblohin-okta Aug 23, 2024
2f2ea39
use own i18next instance
denysoblohin-okta Aug 23, 2024
dedc21f
Override global `loc` util
denysoblohin-okta Aug 26, 2024
1d1a12d
ini i18next instance automatically
denysoblohin-okta Aug 26, 2024
603f8ba
don't remove resources @ dev
denysoblohin-okta Aug 26, 2024
02ed5a4
fix tests
denysoblohin-okta Aug 26, 2024
913dfc0
fix test locUtil
denysoblohin-okta Aug 26, 2024
092db8b
.
denysoblohin-okta Aug 26, 2024
bcb74d6
fix test
denysoblohin-okta Aug 26, 2024
530dfbe
nit
denysoblohin-okta Aug 26, 2024
7d18b19
lint fix
denysoblohin-okta Aug 26, 2024
f662523
upd sizes
denysoblohin-okta Aug 27, 2024
62404a8
remove plural forms
denysoblohin-okta Aug 27, 2024
a73b129
remove getLocUtil
denysoblohin-okta Aug 27, 2024
bb4163a
move initDefaultLanguage into effect
denysoblohin-okta Aug 27, 2024
4153b35
move initDefaultLanguage to useOnce
denysoblohin-okta Aug 27, 2024
5e35244
nit
denysoblohin-okta Aug 27, 2024
c26d3b3
added tests
denysoblohin-okta Aug 27, 2024
118d13c
add test, lint fix
denysoblohin-okta Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
denysoblohin-okta committed Sep 9, 2024
commit 092db8b1929a31803f6fdf6cf62898823bb7e6f6
13 changes: 6 additions & 7 deletions src/util/Bundles.ts
Original file line number Diff line number Diff line change
@@ -221,18 +221,17 @@ export default {
this.currentLanguage = null;
},

loadLanguage: async function(language: string, overrides: i18nOptions, assets: Assets, supportedLanguages: string[]): Promise<void> {
loadLanguage: async function(
language: string, overrides: i18nOptions, assets: Assets, supportedLanguages: string[],
omitDefaultKeys?: (key: string) => boolean
): Promise<void> {
const parsedOverrides = parseOverrides(overrides);
const lowerCaseLanguage = language.toLowerCase();
const bundles = await getBundles(language, assets, supportedLanguages);
// Always extend from the built in defaults in the event that some
// properties are not translated.
// But don't reuse plural forms in English for other languages.
// See https://www.i18next.com/translation-function/plurals
const pluralSuffixes = ['_one', '_other'];
const loginTranslationsWithoutPlural = _.omit(login, (_, k) =>
pluralSuffixes.some(s => k.endsWith(s)));
this.login = _.extend({}, loginTranslationsWithoutPlural, bundles.login);
const loginFiltered = omitDefaultKeys ? _.omit(login, (_, k) => omitDefaultKeys(k)) : login;
this.login = _.extend({}, loginFiltered, bundles.login);
this.country = _.extend({}, country, bundles.country);
this.courage = _.extend({}, login, bundles.login);
if (parsedOverrides[lowerCaseLanguage]) {
4 changes: 1 addition & 3 deletions src/v3/src/util/languageUtils.ts
Original file line number Diff line number Diff line change
@@ -46,9 +46,7 @@ export const loadLanguage = async (widgetProps: WidgetProps): Promise<void> => {
// Don't reuse plural forms in English for other languages.
// See https://www.i18next.com/translation-function/plurals
const pluralSuffixes = ['_one', '_other'];
const omitDefaultKeys = (key: string) => {
return pluralSuffixes.some(s => key.endsWith(s))
};
const omitDefaultKeys = (key: string) => pluralSuffixes.some((s) => key.endsWith(s));
await Bundles.loadLanguage(languageCode, i18n, {
baseUrl: assetsBaseUrl,
rewrite: rewrite ?? ((val) => val),