Feat/left menu i18n (#407)

* feat(i18n): add left menu i18n

* chore(i18n): add missing ComingSoon

* chore(i18n): update docs

* fix: lint
This commit is contained in:
Whitewater
2022-09-12 19:17:59 +08:00
committed by GitHub
parent fc1b3f345c
commit f81459d4c0
6 changed files with 35 additions and 16 deletions

View File

@@ -103,7 +103,8 @@
"datasource:db-services", "datasource:db-services",
"components:ui", "components:ui",
"components:icons", "components:icons",
"library:feature-flags" "library:feature-flags",
"datasource:i18n"
] ]
}, },
{ {

View File

@@ -1,14 +1,15 @@
import { useMemo } from 'react';
import { Virgo, PluginHooks } from '@toeverything/framework/virgo';
import { Cascader, CascaderItemProps } from '@toeverything/components/ui';
import { Protocol } from '@toeverything/datasource/db-service';
import { TurnIntoMenu } from './TurnIntoMenu';
import { import {
AddViewIcon, AddViewIcon,
DeleteCashBinIcon, DeleteCashBinIcon,
TurnIntoIcon, TurnIntoIcon,
UngroupIcon, UngroupIcon,
} from '@toeverything/components/icons'; } from '@toeverything/components/icons';
import { Cascader, CascaderItemProps } from '@toeverything/components/ui';
import { Protocol } from '@toeverything/datasource/db-service';
import { useTranslation } from '@toeverything/datasource/i18n';
import { PluginHooks, Virgo } from '@toeverything/framework/virgo';
import { useMemo } from 'react';
import { TurnIntoMenu } from './TurnIntoMenu';
interface LeftMenuProps { interface LeftMenuProps {
anchorEl?: Element; anchorEl?: Element;
@@ -21,10 +22,11 @@ interface LeftMenuProps {
export function LeftMenu(props: LeftMenuProps) { export function LeftMenu(props: LeftMenuProps) {
const { editor, anchorEl, hooks, blockId, onClose } = props; const { editor, anchorEl, hooks, blockId, onClose } = props;
const { t } = useTranslation();
const menu: CascaderItemProps[] = useMemo( const menu: CascaderItemProps[] = useMemo(
() => [ () => [
{ {
title: 'Delete', title: t('Delete'),
callback: () => { callback: () => {
editor.commands.blockCommands.removeBlock(blockId); editor.commands.blockCommands.removeBlock(blockId);
}, },
@@ -32,7 +34,7 @@ export function LeftMenu(props: LeftMenuProps) {
icon: <DeleteCashBinIcon />, icon: <DeleteCashBinIcon />,
}, },
{ {
title: 'Turn into', title: t('Turn into'),
subItems: [], subItems: [],
children: ( children: (
<TurnIntoMenu <TurnIntoMenu
@@ -48,7 +50,7 @@ export function LeftMenu(props: LeftMenuProps) {
icon: <TurnIntoIcon />, icon: <TurnIntoIcon />,
}, },
{ {
title: 'Add A Below Block', title: t('Add A Below Block'),
icon: <AddViewIcon />, icon: <AddViewIcon />,
callback: async () => { callback: async () => {
const block = await editor.getBlockById(blockId); const block = await editor.getBlockById(blockId);
@@ -66,14 +68,14 @@ export function LeftMenu(props: LeftMenuProps) {
}, },
}, },
{ {
title: 'Divide Here As A New Group', title: t('Divide Here As A New Group'),
icon: <UngroupIcon />, icon: <UngroupIcon />,
callback: () => { callback: () => {
editor.commands.blockCommands.splitGroupFromBlock(blockId); editor.commands.blockCommands.splitGroupFromBlock(blockId);
}, },
}, },
], ],
[editor, hooks, blockId, onClose] [t, editor, hooks, blockId, onClose]
); );
// const filterItems = ( // const filterItems = (

View File

@@ -1,9 +1,11 @@
import { styled } from '@toeverything/components/ui'; import { styled } from '@toeverything/components/ui';
import { useTranslation } from '@toeverything/datasource/i18n';
export const LayoutSettings = () => { export const LayoutSettings = () => {
const { t } = useTranslation();
return ( return (
<StyledText> <StyledText>
<p>Layout Settings Coming Soon...</p> <p>{t('ComingSoon')}</p>
</StyledText> </StyledText>
); );
}; };

View File

@@ -2,10 +2,13 @@
## Usages ## Usages
- Update missing translations into the base resources, a.k.a the `src/resources/en.json`
- Replace literal text with translation keys
```tsx ```tsx
import { useTranslation } from '@toeverything/datasource/i18n'; import { useTranslation } from '@toeverything/datasource/i18n';
// base.json // src/resources/en.json
// { // {
// 'Text': 'some text', // 'Text': 'some text',
// 'Switch to language': 'Switch to {{language}}', // <- you can interpolation by curly brackets // 'Switch to language': 'Switch to {{language}}', // <- you can interpolation by curly brackets
@@ -33,7 +36,14 @@ const App = () => {
}; };
``` ```
## How to sync translations ## How the i18n workflow works?
- When the `src/resources/en.json`(base language) updated and merged to the develop branch, will trigger the `languages-sync` action.
- The `languages-sync` action will check the base language and add missing translations to the Tolgee platform.
- This way, partners from the community can update the translations.
- Finally, the `languages-download` action will regularly download the latest translation resources from the Tolgee platform.
## How to sync translations manually
- Set token as environment variable - Set token as environment variable

View File

@@ -2,7 +2,7 @@
"$schema": "../../../node_modules/nx/schemas/project-schema.json", "$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/datasource/i18n/src", "sourceRoot": "libs/datasource/i18n/src",
"projectType": "library", "projectType": "library",
"tags": ["datasource"], "tags": ["datasource:i18n"],
"targets": { "targets": {
"build": { "build": {
"executor": "@nrwl/web:rollup", "executor": "@nrwl/web:rollup",

View File

@@ -20,5 +20,9 @@
"Import Workspace": "Import Workspace", "Import Workspace": "Import Workspace",
"Export Workspace": "Export Workspace", "Export Workspace": "Export Workspace",
"Last edited by": "Last edited by {{name}}", "Last edited by": "Last edited by {{name}}",
"Logout": "Logout" "Logout": "Logout",
"Delete": "Delete",
"Turn into": "Turn into",
"Add A Below Block": "Add A Below Block",
"Divide Here As A New Group": "Divide Here As A New Group"
} }