Skip to content

Commit

Permalink
Update: update some expression of proposal
Browse files Browse the repository at this point in the history
Signed-off-by: chouchongYHMing <121396869+chouchongYHMing@users.noreply.github.com>
  • Loading branch information
chouchongYHMing committed Sep 10, 2024
1 parent 06fd0f6 commit 68c1bac
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions docs/i18n-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ creation-date: 2024-08-19

## Summary

Internationalization (also called i18n) is essential for software that aims to become global. During the development of the Karmada dashboard, we encountered inefficiencies, errors, and lack of engineering rigor in manually maintaining translation content (also called locales files). To solve these issues and meet the i18n needs of the Karmada dashboard project, we developed a ready-to-use automated i18n tool.
Internationalization (aka i18n) is essential for software that aims to become global. During the development of the Karmada dashboard, we suffered from low efficiency、 easy to make mistakes、lack of engineering due to maintaining i18n translation (aka locales) manually. To solve these issues and meet the i18n needs of the Karmada dashboard project, we developed a out-of-the-box automated i18n tool.

<!--
国际化(也称为i18n)对于需要全球化的软件来说是必须要的,在开发Karmada dashboard的过程中,我们遇到了手动维护翻译内容(也称为locales文件)效率低、容易出错、多人协作时缺乏工程化的问题,因此我们我们开发了一套开箱即用的i18n自动化工具,解决这些问题,满足Karmada dashboard项目的i18n的需求。
-->

## Motivation

During the development of the Karmada dashboard, early on, we maintained the locales files manually. If new Chinese content was added to the code, it required to replace by the corresponding i18n keys and functions. After that, a mapping of code points to the corresponding Chinese content was added to the Chinese locales file. Then translating the Chinese content and inserting a mapping of code points to the translated content in the locales files of the respective languages. When the project was small and the amount of Chinese characters was limited, the cost of manual maintenance was relatively acceptable. However, as the project scale expanded and the number of Chinese characters increased, the cost of manually maintaining locales files rose exponentially. Therefore, an automated i18n tool was needed to meet the i18n requirements of the Karmada dashboard. In the open source community, it was hard to find a ready-to-use i18n tool that perfectly supported the i18n needs of the Karmada dashboard. Therefore, we aimed to develop an automated i18n tool which is based on the perspective of the Karmada dashboard's i18n requirements, to satisfy the specific i18n needs of the Karmada dashboard.
During the development of the Karmada dashboard, we maintained the locales files manually in the early stages. If new Chinese content was added to the code, we need to replace Chinese content with i18n keys and i18n function. After that, a mapping of code points to the corresponding Chinese content was added to the Chinese locales file. Then translating the Chinese content and inserting a mapping of code points to the translated content in the locales files of the respective languages. When the project was small and the amount of Chinese characters was limited, the cost of manual maintenance was relatively acceptable. However, as the project scale up expanded and the number of Chinese characters increased rapidly, the cost of maintaining locales files in manual way rose exponentially. Therefore, an automated i18n tool was needed to meet the i18n requirements of the Karmada dashboard. In the open source community, it was hard to find a out-of-the-box i18n tool that perfectly supported the i18n needs of the Karmada dashboard. Therefore, we aimed to develop an automated i18n tool which is based on the perspective of the Karmada dashboard's i18n requirements, to satisfy the specific i18n needs of the Karmada dashboard.
<!--
在开发Karmada dashboard的过程中,早期我们是通过人工的方式来维护locales文件,如果代码中新增了中文内容,则需要替换中文内容为对应的码点+i18n的调用函数,之后在中文的locales文件中插入码点和对应的中文内容的映射关系,再翻译中文内容,并在对应的语言的locales文件插入码点和对应翻译后内容的映射关系。在项目规模小,中文字符少的情况下手动维护的成本相对可以接受,但是一旦项目规模逐渐扩大、中文字符变多的情况下,手动维护locales文件的方式的成本会呈指数倍上升,因此需要一套i18n自动化工具来满足Karmada dashboard的i18n需求。在开源社区中我们发现很难找到一套开箱即用的i18n工具能够完美支持Karmada dashboard的i18n需求,因此我们希望从Karmada dashboard的i18n需求出发,实现一套满足Karmada dashboard的i18n需求的i18n自动化工具。
-->
Expand Down Expand Up @@ -52,15 +52,6 @@ During the development of the Karmada dashboard, early on, we maintained the loc

## Proposal

<!--
1. 自动节点识别:增强工具以自动识别和处理源代码中的各种节点类型,包括纯字符串节点、模板文字节点、JSX文本节点和JSX属性节点。此功能将确保对可能需要国际化的所有潜在文本元素进行全面扫描和修改。
2. 汉字替换:实现一个健壮的机制,用相应的i18n密钥替换原始文件中所有检测到的汉字。这一步对于为多语言支持准备代码库和确保所有文本内容都为国际化做好准备至关重要。
3. 与本地化文件的集成:自动将新的i18n键包含到locale /zh-CN中。json文件。此过程应有效地处理更新,确保所有密钥都准确地反映在本地化文件中,而无需人工干预。
4. 翻译执行:开发和整合使用更新后的zh-CN的翻译程序。json文件生成对应的其他语言的翻译,如英语(en-US)和法语。该功能将允许快速和准确地制作多语言内容。
-->
### User Stories (Optional)

<!--
Expand Down Expand Up @@ -108,10 +99,10 @@ The overall i18n automation tool comprises two main modules: the translation mod

### Modular Design:

1. processAST Function: Responsible for processing the AST, identifying and replacing Chinese strings.
2. generateKey Function: Generates unique keys for use in the i18n JSON file.
3. updateLocales Function: Update Locales files as material for subsequent translation functions.
4. translate Function: Choose the right way to translate from a variety of options.
1. Process AST Function: Responsible for processing the AST, identifying and replacing Chinese strings.
2. Generate i18n key Function: Generates unique keys for use in the i18n JSON file.
3. Update locales files Function: Update Locales files as material for subsequent translation functions.
4. Translate Function: Choose the right way to translate from a variety of options.
<!--
功能模块化:
Expand Down Expand Up @@ -141,7 +132,7 @@ The program, which is developed based on Node.js's commander module, primarily h
<!--
扫描流程:扫描模块负责接收外部传入的原始文件,返回处理好的AST(Abstract Syntax Tree)树,内部流程如图:
-->
Convert the input files into an AST, traverse the AST to find nodes which containing Chinese characters, calculate the code points corresponding to the Chinese characters and save them in the i18nMap, and save the transformed AST nodes in CNpath. After completing one scan, continue to traverse CNpath, converting the Chinese characters in the corresponding AST nodes into the form of i18n function calls, and generate a new AST tree to return.
Convert the input files into an AST, traverse the AST to find nodes which containing Chinese characters, calculate the code points corresponding to the Chinese characters and save them in the i18nMap, and save the transformed AST nodes in CNpath. After the first round of scanning finished, continue to traverse CNpath, converting the Chinese characters in the corresponding AST nodes into the form of i18n function calls, and generate a new AST tree to return.
<!--
将输入的文件转换成AST树,遍历AST树找到包含中文字符的AST节点,计算中文字符对应的码点保存在i18nMap中,并将AST节点作统一转换后保存在CNpath中。完成一趟扫描后,继续遍历CNpath,将对应的AST节点中的中文字符转成i18n的函数调用的形式,生成新的AST树返回出去。
-->
Expand All @@ -150,7 +141,7 @@ Convert the input files into an AST, traverse the AST to find nodes which contai
<!--
代码生成流程:接收扫描模块返回的修改后的AST树,将修改后的AST树转换成原始代码,内部流程如图:
-->
If the original code does not include an import statement for the i18n instance, an appropriate import statement needs to be inserted. This completes the main workflow of code generation. The process of code generation might inadvertently alter statements unrelated to i18n. To address this issue, a prettier process is introduced to style the generated code according to the original coding style, minimizing changes which brought by code-gen. Finally, the newly generated code is written back into the original file.
If the original code does not include an import statement for the i18n instance, an appropriate import statement needs to be inserted. This completes the main workflow of code generation. The process of code generation might inadvertently alter statements unrelated to i18n. To address this issue, a prettier process is introduced to style the generated code according to the original coding style, minimizing changes which were introduced by code-gen. Finally, the newly generated code is written back into the original file.
<!--
如果原始代码中没有对i18n实例的导入,则需要插入对应的import语句。到这里已经完成代码生成的主流程,代码生成的过程可能会导致i18n无关的语句在做code-gen的过程中也被修改了,为了解决这个问题,额外引入了prettier流程,将生成后代码按照原始代码风格做一次prettier,最小化code-gen带来的变更,最后将生成好的代码覆盖写入原始文件中。
-->
Expand Down

0 comments on commit 68c1bac

Please sign in to comment.