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
ini i18next instance automatically
  • Loading branch information
denysoblohin-okta committed Sep 9, 2024
commit 1d1a12d47a7c7d34666f6c38079fc43cf9909c47
2 changes: 1 addition & 1 deletion src/v3/src/components/Widget/index.tsx
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ export const Widget: FunctionComponent<WidgetProps> = (widgetProps) => {
};
}, [brandColors, customTheme, languageDirection]);

// create i18next instance and load default language (once)
// load default 'en' language (once)
initDefaultLanguage();

// on unmount, remove the language
53 changes: 21 additions & 32 deletions src/v3/src/util/i18next.ts
Original file line number Diff line number Diff line change
@@ -14,38 +14,27 @@ import i18next from 'i18next';

import config from '../../../config/config.json';

// Instance of i18next
let i18ni: ReturnType<typeof i18next['createInstance']> | undefined;
const i18ni = i18next.createInstance();

// eslint-disable-next-line import/no-mutable-exports
export { i18ni as i18next };

export const initI18next = () => {
if (i18ni) {
// Already initialized
return;
}
const ns = ['login', 'country'];
const defaultNS = 'login';

const ns = ['login', 'country'];
const defaultNS = 'login';
i18ni.init({
defaultNS,
ns,
fallbackLng: config.defaultLanguage,
load: 'currentOnly',
keySeparator: false,
nsSeparator: ':',
interpolation: {
prefix: '{',
suffix: '}',
// No need to escape
// Need to use raw value for phone numbers containing `&lrm;`
// React is already safe from XSS
escapeValue: false,
skipOnVariables: false, // to handle translations that use nesting
},
});

// Create and init i18next instance
i18ni = i18next.createInstance();
i18ni.init({
defaultNS,
ns,
fallbackLng: config.defaultLanguage,
load: 'currentOnly',
keySeparator: false,
nsSeparator: ':',
interpolation: {
prefix: '{',
suffix: '}',
// No need to escape
// Need to use raw value for phone numbers containing `&lrm;`
// React is already safe from XSS
escapeValue: false,
skipOnVariables: false, // to handle translations that use nesting
},
});
};
export { i18ni as i18next };
2 changes: 1 addition & 1 deletion src/v3/src/util/languageUtils.test.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

// import { initDefaultLanguage, loadLanguage, unloadLanguage } from './languageUtils';
// import { loadLanguage, unloadLanguage } from './languageUtils';

// describe('languageUtils Tests', () => {

4 changes: 1 addition & 3 deletions src/v3/src/util/languageUtils.ts
Original file line number Diff line number Diff line change
@@ -16,12 +16,10 @@ import config from '../../../config/config.json';
import { LanguageCode } from '../../../types';
import Bundles from '../../../util/Bundles';
import { WidgetProps } from '../types';
import { i18next, initI18next } from './i18next';
import { i18next } from './i18next';
import { getLanguageCode, getSupportedLanguages } from './settingsUtils';

export const initDefaultLanguage = () => {
initI18next();

// Load translations for default language from Bundles to i18next
const languageCode = Bundles.currentLanguage ?? config.defaultLanguage;
const isDefaultLanguage = !Bundles.currentLanguage;