docs(i18n): update i18n usage (#4129)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
|
import { LOCALES, useI18N } from '@affine/i18n';
|
||||||
// src/resources/en.json
|
// src/resources/en.json
|
||||||
// {
|
// {
|
||||||
// 'Text': 'some text',
|
// 'Text': 'some text',
|
||||||
@@ -16,7 +16,7 @@ import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
|||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const i18n = useI18N();
|
||||||
const changeLanguage = (language: string) => {
|
const changeLanguage = (language: string) => {
|
||||||
i18n.changeLanguage(language);
|
i18n.changeLanguage(language);
|
||||||
};
|
};
|
||||||
@@ -24,9 +24,20 @@ const App = () => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>{t['Workspace Settings']()}</div>
|
<div>{t['Workspace Settings']()}</div>
|
||||||
|
<>
|
||||||
<button onClick={() => changeLanguage('en')}>{t('Switch to language', { language: 'en' })}</button>
|
{LOCALES.map(option => {
|
||||||
<button onClick={() => changeLanguage('zh-Hans')}>{t('Switch to language', { language: 'zh-Hans' })}</button>
|
return (
|
||||||
|
<button
|
||||||
|
key={option.name}
|
||||||
|
onClick={() => {
|
||||||
|
changeLanguage(option.tag);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{option.originalName}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user