本地化
每一条内置界面文案(关闭按钮、分页标签、排序播报、上传提示…)都通过 locale 注册表解析。包中仅内嵌了 en — 其他所有语言都从外部(可导入的模块或 JSON 文件)加载,并通过 addLocale 注册。同一个注册表同时驱动 @zephora/react 和 @zephora/native。 en, tr.
加载一种 locale
// 1) As a module (tree-shaken, typed):
import { addLocale } from "@zephora/react";
import { trLocale } from "@zephora/theme/locales/tr";
addLocale("tr", trLocale);
// 2) As JSON over the network (e.g. from your CDN):
const messages = await fetch("/locales/tr.json").then((r) => r.json());
addLocale("tr", messages);
// JSON dosyası pakette hazır: @zephora/theme/locales/tr.json在线演示
切换 locale — 分页标签和 dialog 按钮会即时更新。
选择一种 locale
// Web
<ZephoraConfigProvider locale="tr">...</ZephoraConfigProvider>
// React Native
<ZephoraProvider theme={lightTheme} locale="tr">...</ZephoraProvider>注册自定义 locale
addLocale 会将你的消息合并到英文之上,因此部分定义也是安全的。updateLocale 则修补一个已有的 locale。
import { addLocale, updateLocale } from "@zephora/react";
addLocale("de", {
intlLocale: "de",
firstDayOfWeek: 1,
close: "Schließen",
cancel: "Abbrechen",
confirm: "Bestätigen",
loading: "Wird geladen…",
pageOf: "Seite {page} von {count}",
});
updateLocale("de", { clear: "Leeren" });在你自己的组件中读取文案
import { useLocale, localeOption } from "@zephora/react";
function SaveBar() {
const { t } = useLocale();
return <Button>{t("apply")}</Button>;
}
// Outside React:
localeOption("cancel", "tr"); // "İptal"可用的 locale
内置 48 种现成翻译。每种都是独立模块 — 只导入你需要的(或 fetch 对应的 .json)。
| 代码 | 语言 | 导入路径 |
|---|---|---|
ar | العربية (Arabic) | @zephora/theme/locales/ar |
az | Azərbaycanca (Azerbaijani) | @zephora/theme/locales/az |
bg | Български (Bulgarian) | @zephora/theme/locales/bg |
bn | বাংলা (Bengali) | @zephora/theme/locales/bn |
ca | Català (Catalan) | @zephora/theme/locales/ca |
cs | Čeština (Czech) | @zephora/theme/locales/cs |
da | Dansk (Danish) | @zephora/theme/locales/da |
de | Deutsch (German) | @zephora/theme/locales/de |
el | Ελληνικά (Greek) | @zephora/theme/locales/el |
es | Español (Spanish) | @zephora/theme/locales/es |
et | Eesti (Estonian) | @zephora/theme/locales/et |
fa | فارسی (Persian) | @zephora/theme/locales/fa |
fi | Suomi (Finnish) | @zephora/theme/locales/fi |
fr | Français (French) | @zephora/theme/locales/fr |
he | עברית (Hebrew) | @zephora/theme/locales/he |
hi | हिन्दी (Hindi) | @zephora/theme/locales/hi |
hr | Hrvatski (Croatian) | @zephora/theme/locales/hr |
hu | Magyar (Hungarian) | @zephora/theme/locales/hu |
hy | Հայերեն (Armenian) | @zephora/theme/locales/hy |
id | Bahasa Indonesia (Indonesian) | @zephora/theme/locales/id |
is | Íslenska (Icelandic) | @zephora/theme/locales/is |
it | Italiano (Italian) | @zephora/theme/locales/it |
ja | 日本語 (Japanese) | @zephora/theme/locales/ja |
ka | ქართული (Georgian) | @zephora/theme/locales/ka |
kk | Қазақша (Kazakh) | @zephora/theme/locales/kk |
ko | 한국어 (Korean) | @zephora/theme/locales/ko |
lt | Lietuvių (Lithuanian) | @zephora/theme/locales/lt |
lv | Latviešu (Latvian) | @zephora/theme/locales/lv |
ms | Bahasa Melayu (Malay) | @zephora/theme/locales/ms |
nl | Nederlands (Dutch) | @zephora/theme/locales/nl |
no | Norsk bokmål (Norwegian) | @zephora/theme/locales/no |
pl | Polski (Polish) | @zephora/theme/locales/pl |
pt | Português (Portuguese) | @zephora/theme/locales/pt |
pt-br | Português do Brasil (Brazilian Portuguese) | @zephora/theme/locales/pt-br |
ro | Română (Romanian) | @zephora/theme/locales/ro |
ru | Русский (Russian) | @zephora/theme/locales/ru |
sk | Slovenčina (Slovak) | @zephora/theme/locales/sk |
sl | Slovenščina (Slovenian) | @zephora/theme/locales/sl |
sr | Srpski (Serbian) | @zephora/theme/locales/sr |
sv | Svenska (Swedish) | @zephora/theme/locales/sv |
sw | Kiswahili (Swahili) | @zephora/theme/locales/sw |
ta | தமிழ் (Tamil) | @zephora/theme/locales/ta |
th | ไทย (Thai) | @zephora/theme/locales/th |
tr | Türkçe (Turkish) | @zephora/theme/locales/tr |
uk | Українська (Ukrainian) | @zephora/theme/locales/uk |
vi | Tiếng Việt (Vietnamese) | @zephora/theme/locales/vi |
zh-cn | 简体中文 (Simplified Chinese) | @zephora/theme/locales/zh-cn |
zh-tw | 繁體中文 (Traditional Chinese) | @zephora/theme/locales/zh-tw |
消息参考
完整的键集存在于 ZephoraLocale 类型中 — 动作(close、cancel、confirm、clear…)、数据状态(loading、noData、emptyMessage)、表单文案(showPassword、browseFiles、removeFile)、导航(pageOf、nextPage、breadcrumb)、数据展示(sortAscending、selectAllRows、goToSlide)以及日期(prevMonth、chooseDate、firstDayOfWeek、intlLocale)。占位符使用 {param} 语法,由 t(key, params) 进行插值。