Skip to content

Commit

Permalink
feat(lowcode-i18n-extract): add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Mar 18, 2024
1 parent 94fb579 commit a8afb59
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readdirSync } from 'fs';
import { join } from 'path';

const PUBLIC_PATH = '/lowcode-tools-public/';
const isProduction = process.env.NODE_ENV === 'production';

const headPkgList: string[] = [];
const pkgDirList = readdirSync(join(__dirname, 'packages')).filter(
Expand All @@ -21,18 +22,17 @@ export const alias = pkgDirList.reduce((pre, name) => {
export default defineConfig({
alias,
// autoAlias: true,
base: isProduction ? '/lowcode-tools/' : '/',
resolve: {
docDirs: ['docs'],
atomDirs: [{ type: 'lowcode-tools', dir: 'packages' }],
},
favicons: [`${PUBLIC_PATH}img/favicon.ico`],
publicPath: PUBLIC_PATH,
outputPath: `./dist${PUBLIC_PATH}`,
themeConfig: {
logo: `${PUBLIC_PATH}img/logo.svg`,
nav: [
{ title: '开发指南', link: '/guide' },
{ title: '组件总览', link: '/lowcode-tools/overview' },
],
nav: [{ title: '开发指南', link: '/guide' }],
},
ignoreMomentLocale: true,
mfsu: {
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pnpm install

Contributions of all types are more than welcome, if you are interested in contributing code, feel free to check out our GitHub [Issues][github-issues-link] to get stuck in to show us what you’re made of.

\[!\[]\[pr-welcome-shield]]\[pr-welcome-link]
[![][pr-welcome-shield]][pr-welcome-link]

[![][github-contrib-shield]][github-contrib-link]

Expand Down Expand Up @@ -103,3 +103,5 @@ This project is [MIT](./LICENSE) licensed.
[i18n-extract-github]: https://github.com/yuntijs/lowcode-tools/tree/master/packages/lowcode-i18n-extract/README.md
[i18n-extract-shield]: https://img.shields.io/npm/v/@yuntijs/lowcode-i18n-extract?color=369eff&labelColor=black&logo=npm&logoColor=white&style=flat-square
[i18n-extract-url]: https://www.npmjs.com/package/@yuntijs/lowcode-i18n-extract
[pr-welcome-link]: https://github.com/yuntijs/lowcode-tools/pulls
[pr-welcome-shield]: https://img.shields.io/badge/☁️_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
hero:
title: LowCode Tools
description: 云梯官方低码工具
description: 云梯官方低码工具集
actions:
- text: 立即上手
link: /lowcode-tools
link: /guide
- text: GitHub
link: https://github.com/yuntijs/lowcode-tools
features:
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.1.0",
"description": "Tools for low-code engine.",
"keywords": [
"yuntijs",
"lowcode",
"low-code",
"low-code engine",
"yunti-ui",
"tools"
],
"license": "MIT",
Expand Down Expand Up @@ -55,7 +56,7 @@
"@types/react-dom": "^17",
"@umijs/test": "^4",
"@yuntijs/lint": "^1.5.1",
"@yuntijs/ui": "^1.0.0-beta.7",
"@yuntijs/ui": "^1.0.0-beta.8",
"commitlint": "^18",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
Expand Down
4 changes: 3 additions & 1 deletion packages/lowcode-i18n-extract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<h1>Yunti Lowcode I18n Extract Tools</h1>

🌐 @yuntijs/lowcode-i18n-extract is an i18n extract tools for lowcode schema and inspired by [Kiwi](https://github.com/alibaba/kiwi).
🌐 [@yuntijs/lowcode-i18n-extract](https://www.npmjs.com/package/@yuntijs/lowcode-i18n-extract) is an i18n extract tools for schema of [lowcode engine](https://lowcode-engine.cn/index) inspired by [Kiwi](https://github.com/alibaba/kiwi).

English ・ [简体中文](./README.zh-CN.md)[Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-issues-link]

Expand Down Expand Up @@ -77,6 +77,8 @@ const schema = {
};

const { matches, schema: schemaWithI18n } = extractI18n(schema);
// matches are extracted i18n texts
// schemaWithI18n is scheam with i18n injected
```

<div align="right">
Expand Down
48 changes: 37 additions & 11 deletions packages/lowcode-i18n-extract/demo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/* eslint-disable no-console */
import { extractI18n } from '@yuntijs/lowcode-i18n-extract';
import { MonacoEditor } from '@yuntijs/ui';
import { Button, Flex } from 'antd';
import { Button, Flex, Tabs } from 'antd';
import React, { useState } from 'react';

import schemaData from '../tests/data/schema.json';

const LowcodeI18nExtractDemo: React.FC = () => {
const [schema, setSchema] = useState(JSON.stringify(schemaData, null, 2));
const [schemaExtracted, setSchemaExtracted] = useState<string>();
const [matches, setMatches] = useState<string>();
const onExtractI18nBtnClick = () => {
const { matches, schema: schemaWithI18n } = extractI18n(JSON.parse(schema));
console.log('matches =>', matches);
console.log('schemaWithI18n =>', schemaWithI18n);
setSchemaExtracted(JSON.stringify(schemaWithI18n, null, 2));
const results = extractI18n(JSON.parse(schema));
console.log('matches =>', results.matches);
console.log('schemaWithI18n =>', results.schema);
setSchemaExtracted(JSON.stringify(results.schema, null, 2));
setMatches(JSON.stringify(results.matches, null, 2));
};

return (
Expand All @@ -30,12 +32,36 @@ const LowcodeI18nExtractDemo: React.FC = () => {
Extract I18n Texts
</Button>
<h3>Results:</h3>
<MonacoEditor
height={450}
language="json"
readOnly
supportFullScreen={true}
value={schemaExtracted}
<Tabs
defaultActiveKey="schema"
items={[
{
key: 'schema',
label: 'schema',
children: (
<MonacoEditor
height={450}
language="json"
readOnly
supportFullScreen={true}
value={schemaExtracted}
/>
),
},
{
key: 'matches',
label: 'maches',
children: (
<MonacoEditor
height={450}
language="json"
readOnly
supportFullScreen={true}
value={matches}
/>
),
},
]}
/>
</Flex>
);
Expand Down
71 changes: 70 additions & 1 deletion packages/lowcode-i18n-extract/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
---
title: lowcode-i18n-extract
title: i18n-extract
order: 0
---

<a name="readme-top"></a>

<div align="center">

<h1>Yunti Lowcode I18n Extract Tools</h1>

🌐 [@yuntijs/lowcode-i18n-extract](https://www.npmjs.com/package/@yuntijs/lowcode-i18n-extract) is an i18n extract tools for schema of [lowcode engine](https://lowcode-engine.cn/index) inspired by [Kiwi](https://github.com/alibaba/kiwi).

</div>

## 📦 Installation

To install @yuntijs/lowcode-i18n-extract, run the following command:
Expand All @@ -23,6 +31,67 @@ const schema = {
};

const { matches, schema: schemaWithI18n } = extractI18n(schema);
// matches are extracted i18n texts
// schemaWithI18n is scheam with i18n injected
```

## 🤝 API

### `extractI18n(schema, options)`

#### `schema`

The full project schema of [lowcode engine](https://lowcode-engine.cn/index).

#### `options`

```ts
export interface ExtractI18nOptions {
/** schema 过滤器,可以过滤一些不需要提取中文的字段,不传使用默认的过滤器 `defaultSchemaFilter` */
schemaFilter?: <T = IPublicTypePageSchema>(
schema: IPublicTypeProjectSchema<T>
) => IPublicTypeProjectSchema<T>;
}
```

`defaultSchemaFilter`:

```ts
export const defaultSchemaFilter = <T = IPublicTypePageSchema>(
schema: IPublicTypeProjectSchema<T>
) => {
const pureSchmea = cloneDeep(schema);
const _filterChildren = (children: IPublicTypePageSchema['children']) => {
for (const key of Object.keys(children)) {
const value = (children as Record<string, any>)[key];
if (!value) {
continue;
}
// 过滤 table 等数据源静态数据
if (key === 'dataSource' && Array.isArray(value)) {
delete (children as Record<string, any>).dataSource;
}
if (typeof value === 'object') {
_filterChildren(value);
}
}
return children;
};
pureSchmea.componentsTree = pureSchmea.componentsTree?.map(container => {
const { props, state, methods, dataSource, lifeCycles, children } =
container as IPublicTypePageSchema;
// 默认仅提取以下几个字段中的中文
return {
props,
state,
methods,
dataSource,
lifeCycles,
children: _filterChildren(children),
} as T;
});
return pureSchmea;
};
```

## 🛝 Playground
Expand Down
14 changes: 13 additions & 1 deletion packages/lowcode-i18n-extract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
"keywords": [
"yuntijs",
"lowcode",
"i18n"
"low-code",
"low-code engine",
"i18n",
"extract",
"kiwi"
],
"homepage": "https://github.com/yuntijs/lowcode-tools",
"bugs": {
"url": "https://github.com/yuntijs/lowcode-tools/issues/new"
},
"repository": {
"type": "git",
"url": "https://github.com/yuntijs/lowcode-tools.git"
},
"license": "MIT",
"module": "dist/es/index.js",
"types": "dist/es/index.d.ts",
Expand Down
2 changes: 0 additions & 2 deletions packages/lowcode-i18n-extract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export interface ExtractI18nOptions {
schemaFilter?: <T = IPublicTypePageSchema>(
schema: IPublicTypeProjectSchema<T>
) => IPublicTypeProjectSchema<T>;
/** 批量提取文案时生成 key 值时的默认翻译源, 默认 Pinyin,可选 Pinyin/Google/Baidu/Bing */
defaultI18nKeyApi?: 'Pinyin' | 'Google' | 'Baidu' | 'Bing';
}

export const defaultSchemaFilter = <T = IPublicTypePageSchema>(
Expand Down
5 changes: 1 addition & 4 deletions packages/lowcode-i18n-extract/tests/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@
"bold": true,
"level": 1,
"bordered": false,
"children": {
"key": "i18n-s7vniwvk",
"type": "i18n"
},
"children": "国际化文案提取测试",
"ellipsis": true,
"__component_name": "Typography.Title"
},
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

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

0 comments on commit a8afb59

Please sign in to comment.