-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from xsolla/PAYMENTS-18897
feat(PAYMENTS-18897): infrastructure for translations
- Loading branch information
Showing
22 changed files
with
278 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/app/contexts/localization-context/localization-context-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { FC, ReactNode, useEffect, useState } from 'react'; | ||
import { LocalizationContext } from './localization-context.ts'; | ||
import { Languages } from '../../localization/languages.enum.ts'; | ||
import { loadMessages } from '../../localization/load-localization.ts'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
export const LocalizationContextProvider: FC<{ children: ReactNode }> = ({ children }) => { | ||
const [currentLocale, setCurrentLocale] = useState<Languages>(Languages.EN); | ||
const [messages, setMessages] = useState(null); | ||
|
||
useEffect(() => { | ||
loadMessages(currentLocale).then((data) => setMessages(data.default)); | ||
}, [currentLocale]); | ||
|
||
return ( | ||
<LocalizationContext.Provider value={{ currentLocale, setCurrentLocale }}> | ||
<IntlProvider locale={currentLocale} messages={messages}> | ||
{messages && children} | ||
</IntlProvider> | ||
</LocalizationContext.Provider> | ||
); | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/app/contexts/localization-context/localization-context.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Languages } from '../../localization/languages.enum.ts'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
export interface ILocalizationContext { | ||
currentLocale: Languages; | ||
setCurrentLocale: Dispatch<SetStateAction<Languages>>; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/app/contexts/localization-context/localization-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import { ILocalizationContext } from './localization-context.interface.ts'; | ||
|
||
export const LocalizationContext = React.createContext<ILocalizationContext>( | ||
{} as ILocalizationContext, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export enum Languages { | ||
CN = 'cn', | ||
DE = 'de', | ||
EN = 'en', | ||
ES = 'es', | ||
FR = 'fr', | ||
JA = 'ja', | ||
KO = 'ko', | ||
PT = 'pt', | ||
RU = 'ru', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Languages } from './languages.enum.ts'; | ||
|
||
export async function loadMessages( | ||
locale: Languages, | ||
): Promise<{ default: Record<string, string> }> { | ||
switch (locale) { | ||
case Languages.CN: | ||
return import(`@translations/cn.json`); | ||
case Languages.DE: | ||
return import(`@translations/de.json`); | ||
case Languages.EN: | ||
return import(`@translations/en.json`); | ||
case Languages.ES: | ||
return import(`@translations/es.json`); | ||
case Languages.FR: | ||
return import(`@translations/fr.json`); | ||
case Languages.JA: | ||
return import(`@translations/ja.json`); | ||
case Languages.KO: | ||
return import(`@translations/ko.json`); | ||
case Languages.PT: | ||
return import(`@translations/pt.json`); | ||
case Languages.RU: | ||
return import(`@translations/ru.json`); | ||
default: | ||
return import(`@translations/en.json`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Hello world" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello-world": "Привет мир" | ||
} |
Oops, something went wrong.