locale_util.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.nestingToString = nestingToString;
  4. exports.combinePostfixIndex = combinePostfixIndex;
  5. exports.localFont = localFont;
  6. exports.localRole = localRole;
  7. exports.localEnclose = localEnclose;
  8. exports.localeFontCombiner = localeFontCombiner;
  9. const locale_js_1 = require("./locale.js");
  10. const transformers_js_1 = require("./transformers.js");
  11. function nestingToString(count) {
  12. switch (count) {
  13. case 1:
  14. return locale_js_1.LOCALE.MESSAGES.MS.ONCE || '';
  15. case 2:
  16. return locale_js_1.LOCALE.MESSAGES.MS.TWICE;
  17. default:
  18. return count.toString();
  19. }
  20. }
  21. function combinePostfixIndex(postfix, index) {
  22. return postfix === locale_js_1.LOCALE.MESSAGES.MS.ROOTINDEX ||
  23. postfix === locale_js_1.LOCALE.MESSAGES.MS.INDEX
  24. ? postfix
  25. : postfix + ' ' + index;
  26. }
  27. function localFont(font) {
  28. return extractString(locale_js_1.LOCALE.MESSAGES.font[font], font);
  29. }
  30. function localRole(role) {
  31. return extractString(locale_js_1.LOCALE.MESSAGES.role[role], role);
  32. }
  33. function localEnclose(enclose) {
  34. return extractString(locale_js_1.LOCALE.MESSAGES.enclose[enclose], enclose);
  35. }
  36. function extractString(combiner, fallback) {
  37. if (combiner === undefined) {
  38. return fallback;
  39. }
  40. return typeof combiner === 'string' ? combiner : combiner[0];
  41. }
  42. function localeFontCombiner(font) {
  43. return typeof font === 'string'
  44. ? { font: font, combiner: locale_js_1.LOCALE.ALPHABETS.combiner }
  45. : {
  46. font: font[0],
  47. combiner: locale_js_1.LOCALE.COMBINERS[font[1]] ||
  48. transformers_js_1.Combiners[font[1]] ||
  49. locale_js_1.LOCALE.ALPHABETS.combiner
  50. };
  51. }