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

feat!: migrate to i18n 0.6.0 #11

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 3 additions & 2 deletions .storybook/decorators/withLang.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import {Story as StoryType, StoryContext} from '@storybook/react';
import {I18N} from '@yandex-cloud/i18n';

import {setLang} from '../../src/utils';

export function withLang(Story: StoryType, context: StoryContext) {
const lang = context.globals.lang;

I18N.setDefaultLang(lang);
setLang(lang);

return <Story key={lang} {...context} />;
}
5 changes: 3 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import '@yandex-cloud/uikit/styles/styles.scss';

import {ThemeProvider, MobileProvider} from '@yandex-cloud/uikit';
Expand All @@ -7,9 +8,9 @@ import {CloudTheme} from './theme';
import {withTheme} from './decorators/withTheme';
import {withMobile} from './decorators/withMobile';
import {withLang} from './decorators/withLang';
import {I18N} from '../src/utils/i18n';
import {setLang} from '../src/utils/i18n';

I18N.setDefaultLang(I18N.LANGS.en);
setLang('en');

const withContextProvider = (Story, context) => {
const theme = context.globals.theme;
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"@yandex-cloud/uikit": "^2.0.0",
"@yandex-cloud/i18n": "^0.4.0",
"@yandex-cloud/i18n": "^0.6.0",
"bem-cn-lite": "^4.0.0",
"react": "^16.0.0 || ^17.0.0"
},
Expand All @@ -56,7 +56,7 @@
"@types/lodash": "^4.14.170",
"@types/react": "^17.0.47",
"@yandex-cloud/eslint-config": "^1.0.1",
"@yandex-cloud/i18n": "^0.4.0",
"@yandex-cloud/i18n": "^0.6.0",
"@yandex-cloud/prettier-config": "^1.0.0",
"@yandex-cloud/stylelint-config": "^1.1.1",
"@yandex-cloud/tsconfig": "^1.0.0",
Expand Down
10 changes: 7 additions & 3 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {i18n, I18N} from '../utils';
import {i18n, setLang} from '../utils';

import en from './en.json';
import ru from './ru.json';

export type LANGS = 'ru' | 'en';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename this type to Lang?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed


const COMPONENT = 'dashkit';

i18n.registerKeyset(I18N.LANGS.en, COMPONENT, en);
i18n.registerKeyset(I18N.LANGS.ru, COMPONENT, ru);
i18n.registerKeyset('en', COMPONENT, en);
i18n.registerKeyset('ru', COMPONENT, ru);

setLang('en');

export default i18n.keyset(COMPONENT);
12 changes: 11 additions & 1 deletion src/utils/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import {I18N} from '@yandex-cloud/i18n';

import type {LANGS} from '../i18n';
export {LANGS} from '../i18n';

export const i18n = new I18N();

export {I18N} from '@yandex-cloud/i18n';
/**
* Preferred method to set language.
* @param lang
* @return {void}
*/
export const setLang = (lang: LANGS) => {
i18n.setLang(lang);
};