hypertrons / hypertrons-crx

A browser extension for insights into GitHub projects and developers.
https://crx.hypertrons.io
Apache License 2.0
329 stars 91 forks source link

[OSS101] Task 1: Refactor the existing multiple languages feature by adopting a third i18n library #805

Closed tyn1998 closed 3 hours ago

tyn1998 commented 1 month ago

Description

This task originates from #669.

What is i18n?

Internationalization, abbreviated as i18n, is a process of designing software so that it can be adapted to various languages and regions without significant changes to its structure. It allows software to manage and integrate different languages easily from a localization perspective, enhancing the user experience.

Current Scheme and Its Limitations

HyperCRX currently uses a rudimentary self-contained module get-message-by-locale.ts to handle internationalization. Although this module meets basic i18n needs, it exhibits several significant limitations:

Recommended Improvement Plan

To address these limitations and enhance the project's internationalization quality, it is recommended to introduce a mature third-party i18n library. We suggest using react-i18next, a powerful internationalization framework based on i18next widely used in React projects. Adopting react-i18next can bring the following benefits:

Task Objectives

The goal of this task is to refactor the current multi-language feature of HyperCRX by replacing the existing self-contained module with react-i18next. Through this refactoring, we aim to improve the application's internationalization quality and user experience, while laying the foundation for potential future expansions.

任务描述

此任务来自 #669。

i18n是什么?

国际化(Internationalization,缩写为 i18n)是一个软件设计的过程,使得软件可以适配多种语言和地区,无需进行重大的结构改动。它允许软件从本地化的角度来轻松管理和集成不同语言,提供更佳的用户体验。

当前的方案及其局限性

HyperCRX 目前使用了一个简陋的自封装模块 get-message-by-locale.ts 来处理国际化需求。尽管该模块能基本满足简单的国际化需求,但存在以下局限性:

推荐的改进方案

为了解决现有的局限性并提升项目的国际化质量,建议引入成熟的第三方国际化库。我们推荐使用 react-i18next,这是一个基于i18next的强大国际化框架,广泛应用于React项目中。引入 react-i18next 可带来以下好处:

任务目标

本任务的目标是重构 HyperCRX 当前的多语言特性,采用 react-i18next 来替换现有的自封装模块。通过这次重构,我们期望能够提升应用的国际化质量和用户体验,同时为未来可能的扩展奠定基础。

taketaketakeru commented 4 weeks ago

我先用react-i18next实现了一个界面hypertrons-crx\src\pages\Options\Options.tsx的本地化,我是这样做的:① 配置i18n的相关信息 ② 将原来调用getMessageByLocale函数的部分替换成i18n的实现方法,比如替换为t('options_locale_title.message')。但我不确定这样实现是否正确?并且这样一来原来每处调用getMessageByLocale函数的部分都要进行修改,改用i18n实现本地化依旧很麻烦,也没有感受到上述提出的i18n的三个优点?

wxharry commented 4 weeks ago

我先用react-i18next实现了一个界面hypertrons-crx\src\pages\Options\Options.tsx的本地化,我是这样做的:① 配置i18n的相关信息 ② 将原来调用getMessageByLocale函数的部分替换成i18n的实现方法,比如替换为t('options_locale_title.message')。但我不确定这样实现是否正确?并且这样一来原来每处调用getMessageByLocale函数的部分都要进行修改,改用i18n实现本地化依旧很麻烦,也没有感受到上述提出的i18n的三个优点?

替换每处现有的getMessageByLocale是不可避免的,这应该不是问题。i18n的库更灵活,性能上也更高效。可能我们项目当前没有很多能体现它优势的地方,但改用i18n能有效帮助提高代码性能,也为我们以后的功能提供支持和灵活性。你可以先提一个PR,这样我们可以具体对着代码讨论,如果代码还处于未完成,可以把pr设置成draft。

taketaketakeru commented 3 weeks ago

我先用react-i18next实现了一个界面hypertrons-crx\src\pages\Options\Options.tsx的本地化,我是这样做的:① 配置i18n的相关信息 ② 将原来调用getMessageByLocale函数的部分替换成i18n的实现方法,比如替换为t('options_locale_title.message')。但我不确定这样实现是否正确?并且这样一来原来每处调用getMessageByLocale函数的部分都要进行修改,改用i18n实现本地化依旧很麻烦,也没有感受到上述提出的i18n的三个优点?

替换每处现有的getMessageByLocale是不可避免的,这应该不是问题。i18n的库更灵活,性能上也更高效。可能我们项目当前没有很多能体现它优势的地方,但改用i18n能有效帮助提高代码性能,也为我们以后的功能提供支持和灵活性。你可以先提一个PR,这样我们可以具体对着代码讨论,如果代码还处于未完成,可以把pr设置成draft。

好的,感谢回复