-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): add react-i18next and associated boilerplate for interface … (
#3823) * feat(v2): add react-i18next and associated boilerplate for interface i18n * remove http backend * address comments from karrui * fix typo in types
- Loading branch information
Showing
11 changed files
with
216 additions
and
3 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
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
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,20 @@ | ||
import { initReactI18next } from 'react-i18next' | ||
import i18n from 'i18next' | ||
import LanguageDetector from 'i18next-browser-languagedetector' | ||
import ICU from 'i18next-icu' | ||
|
||
import { locales } from './locales' | ||
|
||
i18n | ||
.use(ICU) | ||
.use(LanguageDetector) | ||
.use(initReactI18next) // passes i18n down to react-i18next | ||
.init({ | ||
resources: locales, | ||
fallbackLng: 'en-SG', | ||
debug: true, | ||
interpolation: { | ||
escapeValue: false, // react already safes from xss | ||
}, | ||
}) | ||
export default i18n |
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,9 @@ | ||
import Translation from './types' | ||
|
||
export const enSG: Translation = { | ||
translation: { | ||
general: { | ||
slogan: 'Build secure government forms in minutes', | ||
}, | ||
}, | ||
} |
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 { ResourceLanguage } from 'i18next' | ||
|
||
import { enSG } from './en-sg' | ||
|
||
export const locales = { | ||
'en-SG': enSG as unknown as ResourceLanguage, | ||
} |
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,9 @@ | ||
interface Translation { | ||
translation: { | ||
general: { | ||
slogan: string | ||
} | ||
} | ||
} | ||
|
||
export default Translation |
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,9 @@ | ||
import 'react-i18next' | ||
|
||
import { enSG } from './locales/en-sg' | ||
|
||
declare module 'react-i18next' { | ||
interface CustomTypeOptions { | ||
resources: typeof enSG | ||
} | ||
} |
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