Skip to content

Commit 6272971

Browse files
authored
Merge pull request #573 from GetStream/customizing-streami18n
adding customization to Streami18n i18nextConfig and fixing copy-translations typescript creation
2 parents eb5c4f1 + 830c111 commit 6272971

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"analyze": "yarn build -- --stats && webpack-bundle-analyzer build/bundle-stats.json",
2222
"build": "rm -rf lib && yarn run --silent build-translations && bob build && yarn run --silent copy-translations",
2323
"build-translations": "rm -rf .tmpi18ncache || true && mkdir .tmpi18ncache && yarn run babel --config-file ./babel.i18next-extract.json 'src/**/*.{js,jsx,ts,tsx}' --out-dir '.tmpi18ncache/' && rm -rf .tmpi18ncache && prettier --write 'src/i18n/*.{js,ts,tsx,md,json}' .eslintrc.json .prettierrc .babelrc",
24-
"copy-translations": "echo '\u001b[34mℹ\u001b[0m Copying translation files to \u001b[34mlib/typescript/i18n\u001b[0m' && cp -R -f ./src/i18n ./lib/typescript/src && echo '\u001b[32m✓\u001b[0m Done Copying Translations'",
24+
"copy-translations": "echo '\u001b[34mℹ\u001b[0m Copying translation files to \u001b[34mlib/typescript/i18n\u001b[0m' && cp -R -f ./src/i18n ./lib/typescript/lib && echo '\u001b[32m✓\u001b[0m Done Copying Translations'",
2525
"docs": "styleguidist build",
2626
"docs-server": "styleguidist server",
2727
"eslint": "eslint '**/*.{js,md,ts,jsx,tsx}' --max-warnings 0",

src/utils/Streami18n.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import localeData from 'dayjs/plugin/localeData';
44
import LocalizedFormat from 'dayjs/plugin/localizedFormat';
55
import relativeTime from 'dayjs/plugin/relativeTime';
66
import updateLocale from 'dayjs/plugin/updateLocale';
7-
import i18n, { TFunction } from 'i18next';
7+
import i18n, { FallbackLng, TFunction } from 'i18next';
88

99
import enTranslations from '../i18n/en.json';
1010
import frTranslations from '../i18n/fr.json';
@@ -181,6 +181,16 @@ type Options = {
181181
translationsForLanguage?: typeof enTranslations;
182182
};
183183

184+
type I18NextConfig = {
185+
debug: boolean;
186+
fallbackLng: false | FallbackLng;
187+
interpolation: { escapeValue: boolean };
188+
keySeparator: false | string;
189+
lng: string;
190+
nsSeparator: false | string;
191+
parseMissingKeyHandler: (key: string) => string;
192+
};
193+
184194
/**
185195
* Wrapper around [i18next](https://www.i18next.com/) class for Stream related translations.
186196
* Instance of this class should be provided to Chat component to handle translations.
@@ -375,15 +385,7 @@ export class Streami18n {
375385
currentLanguage: string;
376386
DateTimeParser: typeof Dayjs | typeof moment;
377387
isCustomDateTimeParser: boolean;
378-
i18nextConfig: {
379-
debug: boolean;
380-
fallbackLng: false;
381-
interpolation: { escapeValue: boolean };
382-
keySeparator: false;
383-
lng: string;
384-
nsSeparator: false;
385-
parseMissingKeyHandler: (key: string) => string;
386-
};
388+
i18nextConfig: I18NextConfig;
387389

388390
/**
389391
* Constructor accepts following options:
@@ -411,7 +413,10 @@ export class Streami18n {
411413
*
412414
* @param {*} options
413415
*/
414-
constructor(options: Options = {}) {
416+
constructor(
417+
options: Options = {},
418+
i18nextConfig: Partial<I18NextConfig> = {},
419+
) {
415420
const finalOptions = {
416421
...defaultStreami18nOptions,
417422
...options,
@@ -471,6 +476,7 @@ export class Streami18n {
471476

472477
return key;
473478
},
479+
...i18nextConfig,
474480
};
475481

476482
this.validateCurrentLanguage();

0 commit comments

Comments
 (0)