locale_ca.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { createLocale } from '../locale.js';
  2. import { combinePostfixIndex } from '../locale_util.js';
  3. import { NUMBERS } from '../numbers/numbers_ca.js';
  4. import { Combiners } from '../transformers.js';
  5. const sansserifCombiner = function (letter, font, cap) {
  6. letter = 'sans serif ' + (cap ? cap + ' ' + letter : letter);
  7. return font ? letter + ' ' + font : letter;
  8. };
  9. let locale = null;
  10. export function ca() {
  11. if (!locale) {
  12. locale = create();
  13. }
  14. return locale;
  15. }
  16. function create() {
  17. const loc = createLocale();
  18. loc.NUMBERS = NUMBERS;
  19. loc.COMBINERS['sansserif'] = sansserifCombiner;
  20. loc.FUNCTIONS.fracNestDepth = (_node) => false;
  21. loc.FUNCTIONS.combineRootIndex = combinePostfixIndex;
  22. loc.FUNCTIONS.combineNestedRadical = (a, _b, c) => a + c;
  23. loc.FUNCTIONS.fontRegexp = (font) => RegExp('^' + font + ' ');
  24. loc.FUNCTIONS.plural = (unit) => {
  25. if (/.*os$/.test(unit)) {
  26. return unit + 'sos';
  27. }
  28. if (/.*s$/.test(unit)) {
  29. return unit + 'os';
  30. }
  31. if (/.*ga$/.test(unit)) {
  32. return unit.slice(0, -2) + 'gues';
  33. }
  34. if (/.*ça$/.test(unit)) {
  35. return unit.slice(0, -2) + 'ces';
  36. }
  37. if (/.*ca$/.test(unit)) {
  38. return unit.slice(0, -2) + 'ques';
  39. }
  40. if (/.*ja$/.test(unit)) {
  41. return unit.slice(0, -2) + 'ges';
  42. }
  43. if (/.*qua$/.test(unit)) {
  44. return unit.slice(0, -3) + 'qües';
  45. }
  46. if (/.*a$/.test(unit)) {
  47. return unit.slice(0, -1) + 'es';
  48. }
  49. if (/.*(e|i)$/.test(unit)) {
  50. return unit + 'ns';
  51. }
  52. if (/.*í$/.test(unit)) {
  53. return unit.slice(0, -1) + 'ins';
  54. }
  55. return unit + 's';
  56. };
  57. loc.FUNCTIONS.si = (prefix, unit) => {
  58. if (unit.match(/^metre/)) {
  59. prefix = prefix.replace(/a$/, 'à').replace(/o$/, 'ò').replace(/i$/, 'í');
  60. }
  61. return prefix + unit;
  62. };
  63. loc.ALPHABETS.combiner = Combiners.prefixCombiner;
  64. return loc;
  65. }