bonusActivityLang.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const SPANISH_COUNTRIES = new Set([
  2. "ES",
  3. "AR",
  4. "BO",
  5. "CL",
  6. "CO",
  7. "CR",
  8. "EC",
  9. "SV",
  10. "GT",
  11. "HN",
  12. "NI",
  13. "PA",
  14. "PY",
  15. "PE",
  16. "UY",
  17. "VE",
  18. "BZ",
  19. ]);
  20. const ARABIC_COUNTRIES = new Set([
  21. "DZ",
  22. "BH",
  23. "EG",
  24. "IQ",
  25. "JO",
  26. "KW",
  27. "LB",
  28. "MR",
  29. "MA",
  30. "OM",
  31. "PS",
  32. "QA",
  33. "SA",
  34. "SD",
  35. "SY",
  36. "TN",
  37. "AE",
  38. "YE",
  39. "DJ",
  40. "SO",
  41. ]);
  42. const CHINESE_COUNTRIES = new Set(["CN", "CNX", "CNA", "CNT"]);
  43. export function getBonusActivityLang(country) {
  44. if (!country) {
  45. return "en";
  46. }
  47. if (CHINESE_COUNTRIES.has(country)) {
  48. return "cn";
  49. }
  50. if (SPANISH_COUNTRIES.has(country)) {
  51. return "es";
  52. }
  53. if (ARABIC_COUNTRIES.has(country)) {
  54. return "ar";
  55. }
  56. return "en";
  57. }
  58. function getI18nMessageByPath(messages, path) {
  59. if (!messages || !path) {
  60. return null;
  61. }
  62. return path.split(".").reduce((obj, key) => {
  63. if (obj == null) {
  64. return undefined;
  65. }
  66. return obj[key];
  67. }, messages);
  68. }
  69. // i18n = {t,message} 合并传入 message要是useI18n的message.value
  70. export function getCountryLocalizedMessage(i18n, country, path) {
  71. const locale = getBonusActivityLang(country);
  72. const messages = i18n.messages;
  73. const localized = getI18nMessageByPath(messages[locale], path);
  74. console.log(localized, 'localized')
  75. const t = i18n.t;
  76. return localized || t(path);
  77. }