| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const SPANISH_COUNTRIES = new Set([
- "ES",
- "AR",
- "BO",
- "CL",
- "CO",
- "CR",
- "EC",
- "SV",
- "GT",
- "HN",
- "NI",
- "PA",
- "PY",
- "PE",
- "UY",
- "VE",
- "BZ",
- ]);
- const ARABIC_COUNTRIES = new Set([
- "DZ",
- "BH",
- "EG",
- "IQ",
- "JO",
- "KW",
- "LB",
- "MR",
- "MA",
- "OM",
- "PS",
- "QA",
- "SA",
- "SD",
- "SY",
- "TN",
- "AE",
- "YE",
- "DJ",
- "SO",
- ]);
- const CHINESE_COUNTRIES = new Set(["CN", "CNX", "CNA", "CNT"]);
- export function getBonusActivityLang(country) {
- if (!country) {
- return "en";
- }
- if (CHINESE_COUNTRIES.has(country)) {
- return "cn";
- }
- if (SPANISH_COUNTRIES.has(country)) {
- return "es";
- }
- if (ARABIC_COUNTRIES.has(country)) {
- return "ar";
- }
- return "en";
- }
- function getI18nMessageByPath(messages, path) {
- if (!messages || !path) {
- return null;
- }
- return path.split(".").reduce((obj, key) => {
- if (obj == null) {
- return undefined;
- }
- return obj[key];
- }, messages);
- }
- // i18n = {t,message} 合并传入 message要是useI18n的message.value
- export function getCountryLocalizedMessage(i18n, country, path) {
- const locale = getBonusActivityLang(country);
- const messages = i18n.messages;
- const localized = getI18nMessageByPath(messages[locale], path);
- console.log(localized, 'localized')
- const t = i18n.t;
- return localized || t(path);
- }
|