refactor: optimize i18n#2158
Conversation
First visit now follows navigator.languages instead of always defaulting to zh_CN; explicit choice in localStorage still wins. Configure fallbackLng zh_CN (the only complete language) in both init paths so missing keys never render as raw key text.
moment was pinned to zh-cn at TimeRangePicker module load, so English UI still rendered Chinese weekdays/months in date components. Move the custom zh-cn config to utils/momentLocale (config.ts keeps a re-export) and sync the active moment locale on i18n init and languageChanged.
Login page captcha/SSO warnings now go through the login namespace (sso_no_url is parameterized instead of six copies). The identical "verification failed" JSX duplicated across five loginCallback pages is extracted into a shared CallbackFailed component; Custom.tsx keeps its verifying state and reuses the same keys. Also drop a stray @codemirror/language import in login/locale/zh_CN.ts.
scripts/check_locale_keys.ts diffs every locale dir against zh_CN and flags en_US values still containing Chinese. Fill the 81 missing en_US keys it found (aiConfig agents/mcpServers/skills, dashboard, datasource, eventPipeline, explorer, pageLayout, NotificationSettings, siteSettings, shield) and translate the two Chinese values left in alertRules. Also fixed along the way: mcpServers en title said 'Agent'; the zh cannot_delete_when_enabled on the MCP page said 'LLM 配置'; explorer en had a stale field_values_topn.label (component reads .title); notFound locale files carried dead keys unrelated to what OutOfService.tsx actually renders — realigned all languages to the real keys.
The repo has no default 'translation' namespace, so t('中文') under a
bare useTranslation() always rendered the Chinese key. Full scan found
and fixed every such case:
- account/secretKey and user/delPopover now use the account/user
namespaces plus existing common:btn keys, with new keys in all
five languages
- InputEnlarge/LinkBuilder, TipsBox and Code pointed at the wrong
(default) namespace; wired to inputEnlarge/common
- pgsql & mysql Datasource/Detail 精确/正则, explorer ES 下钻设置 and
shareChart empty-data text got proper namespace keys
- log/IndexPatterns 请输入/请选择 filled in en/zh_HK/ja
buildContentText hardcoded 业务组/数据源/团队 in the confirmation text echoed back to the chat. Reuse the existing form_select.* keys via i18next.t (module-level helper, evaluated at click time) and pick the colon/list separator by language.
datasource items/Auth.tsx was the only sibling without i18n; wire it to the datasourceManage namespace with new AccessKey placeholders. NOTIFICATION_CHANNEL_TYPES is now a lazy getNotificationChannelTypes() factory: the ali/tx sms & voice default payload templates carried Chinese operator instructions that were POSTed verbatim to the backend. Values now resolve through the notification-channels default_values keys at form-init time (module-scope evaluation would run before i18next.init because the eager locale glob pulls in constants.ts). JSON body skeletons stay in code; only human phrases live in locales. Bulk of the constants.ts diff is re-indentation — review with -w.
The DocLink header button always pointed at the Chinese docs site. Extract the language-suffix convention already used by DocumentDrawer into utils/docUrl (DOC_URL_LANG_SUFFIX + localizeDocUrl, preserving query/hash and leaving non-flashcat.cloud URLs untouched) and apply it in getProductDocumentHref. The two duplicated filenameMap copies in DocumentDrawer now import the shared map. Plugin documentPath links already flow through DocumentDrawer with a language prop, so they were covered. Tests added for both helpers.
Covers the remaining one-off Chinese literals on high-traffic paths:
alertRules form warnings, dashboard ES histogram editor (reuses
datasource:es.* keys like its siblings, plus a new es.histogram.interval),
invalid panel config/type messages, the dashboard migrate modal (new
dashboard:migrate.* group), Loki log-context controls, the
organize-fields tooltip in both LogsViewer variants, the event action
busi-group warning, clipboard/password messages in utils (also fixes
three i18next.t('中文') calls missed by the earlier scan because of the
`.t(` pattern), PromQueryBuilder "no parameters" and the DeviceSelect
"且" connector. New keys added to all five languages.
traceCpt Detail header and scatter chart now use trace-namespace keys (new detail/chart groups in all five languages); tooltip handling keys off the original field name instead of comparing Chinese strings. TraceSortItem/RelationType and the manageInterface/eventInterface enums carried Chinese values that only served as discriminators (display goes through t() mappings like createModal's actionLabel), so their values become stable English identifiers with no consumer changes. Side fix: the sortTraces fallback comparators[TraceSortItem.LONGEST_FIRST] indexed by the Chinese value and was always undefined — it now resolves.
MigrationModal had no i18n despite the module owning the migrationDashboard namespace; wire it up with a new modal.* group in all five languages, reuse common:btn.cancel and the existing migrate key, and pass the translated title to BlankBusinessPlaceholder.
App.tsx and ModalHOC only mapped en_US/ru_RU, so antd chrome rendered in Simplified Chinese for zh_HK/ja_JP users. Extract a shared getAntdLocale(language) helper covering all five languages.
|
Important Review skippedToo many files! This PR contains 272 files, which is 122 over the limit of 150. To get a review, narrow the scope: Upgrade to a paid plan to raise the limit. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (272)
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# Conflicts: # src/pages/alertRules/locale/en_US.ts # src/pages/alertRules/locale/ja_JP.ts # src/pages/alertRules/locale/ru_RU.ts # src/pages/alertRules/locale/zh_CN.ts # src/pages/alertRules/locale/zh_HK.ts
- fallbackLng: zh_HK -> zh_CN; other languages -> en_US -> zh_CN - add 18 new ja_JP/ru_RU locale files and register them - fill missing keys across dashboard/eventPipeline/aiConfig/logExplorer/plugins - fix explorer field_values_topn key (label -> title) to match en_US/zh_CN - fix Cyrillic 'A' typo in ru_RU 'Agent' and stale const name in IndexPatterns ja_JP
…e gaps With the new fallback chain (default: en_US -> zh_CN), Chinese-as-key entries that existed only in en_US/zh_HK/ja/ru caused zh_CN UI to show English. Backfill them into zh_CN (value same as key) for InputEnlarge, menu, log/IndexPatterns and plugins/mysql, and complete the same keys missing in ja/ru/hk files. Also fix two Russian strings with leftover Chinese (alertRules threshold_judgment, dashboard var.help_tip).
A cross-language union check found keys existing only in some language files with no reference anywhere (main repo and plus repo verified): menu.personnel_orgs, ident_placeholder, query.prometheus.expression, link.url_tip, script.script_content, nested link-tip-time-format, and 19 query.* keys copied into clickHouse/doris ja_JP from other plugin templates. Remove them so all five languages share an identical key set.
Replace hardcoded Chinese text and i18n.language conditionals with t()/i18next.t() calls across dashboard, trace, task, explorer and datasource plugin (TDengine/iotdb/victorialogs) pages. Add the corresponding keys to en_US/ja_JP/ru_RU/zh_CN/zh_HK locales. i18n is read at call-time (trace duration units, switch field yes/no, config length limits) so language switching takes effect at render.
# Conflicts: # src/App.tsx
- FormNG: gate the advanced sidebar section with IS_PLUS; its content
(NotifyExtraNG) is a plus-only parcel that renders null in OSS, so the
entry pointed to nothing and showed raw alertRules_extra keys
- Triggers/Builder x2: db_aliyunSLS:trigger.value_msg (plus-only ns) ->
alertRules:trigger.value_msg, new leaf added to all 5 locales
- ES EnrichQueries: db_aliyunSLS:enrich_queries.title ->
alertRules:enrich_queries.title, new leaf added to all 5 locales
- builtInComponents AlertRules Detail: alertRulesBuiltin:detail_no_result
(nonexistent ns) -> common:nodata
- Relabel EventsModal x2: t('rule_name') missing in AlertHisEvents ns ->
AlertCurEvents:rule_name (column renders rule name + event tags)
- logExplorer RenderValue x3: drop stray 'log.' prefix so
field_actions.{exists,and,not} resolve
No description provided.