smartloc 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/adapters/adapter-base.d.ts +12 -0
  2. package/adapters/adapter-base.js +56 -0
  3. package/adapters/adapter-base.js.map +1 -0
  4. package/adapters/index.d.ts +4 -0
  5. package/adapters/index.js +32 -0
  6. package/adapters/index.js.map +1 -0
  7. package/adapters/json.d.ts +6 -0
  8. package/adapters/json.js +23 -0
  9. package/adapters/json.js.map +1 -0
  10. package/adapters/xliff.d.ts +6 -0
  11. package/adapters/xliff.js +35 -0
  12. package/adapters/xliff.js.map +1 -0
  13. package/cli/cli.d.ts +2 -0
  14. package/cli/cli.js +129 -0
  15. package/cli/cli.js.map +1 -0
  16. package/cli/collect.d.ts +14 -0
  17. package/{src/cli/collect.ts → cli/collect.js} +59 -75
  18. package/cli/collect.js.map +1 -0
  19. package/cli/interfaces.js +3 -0
  20. package/cli/interfaces.js.map +1 -0
  21. package/cli/reconciliate.d.ts +6 -0
  22. package/{src/cli/reconciliate.ts → cli/reconciliate.js} +35 -40
  23. package/cli/reconciliate.js.map +1 -0
  24. package/cli/utils.d.ts +6 -0
  25. package/{src/cli/utils.ts → cli/utils.js} +16 -12
  26. package/cli/utils.js.map +1 -0
  27. package/core/default-locale.d.ts +10 -0
  28. package/{src/core/default-locale.tsx → core/default-locale.js} +23 -28
  29. package/core/default-locale.js.map +1 -0
  30. package/{src/core/interfaces.ts → core/interfaces.d.ts} +15 -20
  31. package/core/interfaces.js +3 -0
  32. package/core/interfaces.js.map +1 -0
  33. package/core/json-utils.d.ts +19 -0
  34. package/{src/core/json-utils.ts → core/json-utils.js} +27 -33
  35. package/core/json-utils.js.map +1 -0
  36. package/core/literal.d.ts +13 -0
  37. package/{src/core/literal.ts → core/literal.js} +20 -19
  38. package/core/literal.js.map +1 -0
  39. package/core/load.d.ts +32 -0
  40. package/core/load.js +50 -0
  41. package/core/load.js.map +1 -0
  42. package/core/locale-list.d.ts +27 -0
  43. package/{src/core/locale-list.ts → core/locale-list.js} +36 -37
  44. package/core/locale-list.js.map +1 -0
  45. package/core/locale.d.ts +15 -0
  46. package/{src/core/locale.tsx → core/locale.js} +29 -28
  47. package/core/locale.js.map +1 -0
  48. package/core/smartloc.d.ts +39 -0
  49. package/{src/core/smartloc.tsx → core/smartloc.js} +113 -120
  50. package/core/smartloc.js.map +1 -0
  51. package/core/tag.d.ts +13 -0
  52. package/core/tag.js +28 -0
  53. package/core/tag.js.map +1 -0
  54. package/core/utils.d.ts +4 -0
  55. package/core/utils.js +30 -0
  56. package/core/utils.js.map +1 -0
  57. package/express.d.ts +12 -0
  58. package/{src/express.ts → express.js} +33 -41
  59. package/express.js.map +1 -0
  60. package/graphql.d.ts +13 -0
  61. package/{src/graphql.ts → graphql.js} +62 -74
  62. package/graphql.js.map +1 -0
  63. package/index.js +30 -1
  64. package/index.js.map +1 -0
  65. package/node/index.d.ts +1 -0
  66. package/node/index.js +18 -0
  67. package/node/index.js.map +1 -0
  68. package/node/load.d.ts +12 -0
  69. package/node/load.js +37 -0
  70. package/node/load.js.map +1 -0
  71. package/package.json +3 -22
  72. package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
  73. package/.vscode/launch.json +0 -65
  74. package/.vscode/settings.json +0 -14
  75. package/.vscode/tasks.json +0 -27
  76. package/build/README.md +0 -225
  77. package/build/package.json +0 -60
  78. package/bun.lock +0 -310
  79. package/samples/express/main.ts +0 -37
  80. package/samples/express/package.json +0 -10
  81. package/samples/graphql/main.ts +0 -73
  82. package/samples/graphql/package.json +0 -15
  83. package/src/adapters/adapter-base.ts +0 -58
  84. package/src/adapters/index.ts +0 -31
  85. package/src/adapters/json.ts +0 -18
  86. package/src/adapters/xliff.ts +0 -30
  87. package/src/cli/cli.ts +0 -137
  88. package/src/core/load.ts +0 -82
  89. package/src/core/tag.ts +0 -40
  90. package/src/core/utils.tsx +0 -24
  91. package/src/node/index.ts +0 -1
  92. package/src/node/load.ts +0 -32
  93. package/test/collect.spec.ts +0 -45
  94. package/test/reconciliation.spec.ts +0 -132
  95. package/test/serialization.spec.ts +0 -162
  96. package/test/translation.spec.ts +0 -61
  97. package/tsconfig.json +0 -37
  98. package/tslint.json +0 -103
  99. /package/{src/cli/interfaces.ts → cli/interfaces.d.ts} +0 -0
  100. /package/{src/index.ts → index.d.ts} +0 -0
@@ -1,27 +1,27 @@
1
- import type { Translation, CollectItem } from '../core/load';
2
- import levenshtein from 'js-levenshtein';
3
- import diacritics from 'diacritics';
4
- import { deepEqual } from './utils';
5
- import type { TranslationTarget } from '../core/interfaces';
6
-
7
- const cache: Record<string, string> = {};
8
- function asKey(t: TranslationTarget) {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.reconciliate = reconciliate;
7
+ const js_levenshtein_1 = __importDefault(require("js-levenshtein"));
8
+ const diacritics_1 = __importDefault(require("diacritics"));
9
+ const utils_1 = require("./utils");
10
+ const cache = {};
11
+ function asKey(t) {
9
12
  const str = typeof t === 'string' ? t : t.plural;
10
13
  if (cache[str]) {
11
14
  return cache[str];
12
15
  }
13
- return cache[str] = diacritics.remove(str.toLowerCase().trim());
16
+ return cache[str] = diacritics_1.default.remove(str.toLowerCase().trim());
14
17
  }
15
-
16
- export function reconciliate(translations: Translation, source: Translation) {
18
+ function reconciliate(translations, source) {
17
19
  // source is the new one
18
20
  translations.sourceLanguage = source.targetLanguage;
19
-
20
21
  // stores which translations do not exist in code anymore
21
- const translatedLost: { [original: string]: CollectItem; } = {};
22
-
23
- function updateWithOrig(trans: CollectItem, origId: string, src: CollectItem) {
24
- if (trans.source && !deepEqual(trans.source, src.target)) {
22
+ const translatedLost = {};
23
+ function updateWithOrig(trans, origId, src) {
24
+ if (trans.source && !(0, utils_1.deepEqual)(trans.source, src.target)) {
25
25
  trans.dirty = true;
26
26
  }
27
27
  trans.source = src.target ?? undefined;
@@ -29,14 +29,14 @@ export function reconciliate(translations: Translation, source: Translation) {
29
29
  // remove it from 'def'
30
30
  delete source.resources[origId];
31
31
  }
32
-
33
32
  // update source lines
34
33
  for (const [id, trans] of Object.entries(translations.resources)) {
35
34
  const d = source.resources[id];
36
35
  if (d) {
37
36
  // already exists => update
38
37
  updateWithOrig(trans, id, d);
39
- } else {
38
+ }
39
+ else {
40
40
  // does not exist anymore => remove, but keep in mind.
41
41
  delete translations.resources[id];
42
42
  if (trans.source) {
@@ -44,7 +44,6 @@ export function reconciliate(translations: Translation, source: Translation) {
44
44
  }
45
45
  }
46
46
  }
47
-
48
47
  // for each NEW translations missing
49
48
  // try to reconciliate with those which have changed id, but still same translation.
50
49
  for (const [id, value] of Object.entries(source.resources)) {
@@ -56,30 +55,27 @@ export function reconciliate(translations: Translation, source: Translation) {
56
55
  updateWithOrig(translatedLost[cleanTarget], id, value);
57
56
  }
58
57
  }
59
-
60
58
  // try to reconciliate with strings that look alike
61
59
  // nb: avoid doing that when too much deleted translations: Levenshtein distance computation is expensive
62
60
  const lostKeys = Object.keys(translatedLost);
63
61
  if (Object.keys(source.resources).length * lostKeys.length < 5000 && lostKeys.length > 0) {
64
- const reconc: { origId: string; orig: CollectItem; translatedLostSource: string; distance: number }[] = [];
62
+ const reconc = [];
65
63
  for (const lk of lostKeys) {
66
64
  reconc.push(...Object.entries(source.resources)
67
65
  .map(([id, orig]) => {
68
- // distance between the lost source & the new source
69
- const target = orig.target ? asKey(orig.target) : null;
70
- const distance = target ? levenshtein(lk, target) : Infinity;
71
- return {
72
- origId: id,
73
- orig,
74
- translatedLostSource: lk,
75
- distance: distance,
76
- }
77
- })
66
+ // distance between the lost source & the new source
67
+ const target = orig.target ? asKey(orig.target) : null;
68
+ const distance = target ? (0, js_levenshtein_1.default)(lk, target) : Infinity;
69
+ return {
70
+ origId: id,
71
+ orig,
72
+ translatedLostSource: lk,
73
+ distance: distance,
74
+ };
75
+ })
78
76
  // forbids to much change
79
- .filter(x => x.distance < lk.length / 1.5)
80
- );
77
+ .filter(x => x.distance < lk.length / 1.5));
81
78
  }
82
-
83
79
  reconc.sort((a, b) => a.distance - b.distance);
84
80
  const done = new Set();
85
81
  for (const d of reconc) {
@@ -90,25 +86,23 @@ export function reconciliate(translations: Translation, source: Translation) {
90
86
  updateWithOrig(translatedLost[d.translatedLostSource], d.origId, d.orig);
91
87
  }
92
88
  }
93
-
94
89
  // finally, add new translations...
95
90
  for (const [id, value] of Object.entries(source.resources)) {
96
91
  translations.resources[id] = {
97
92
  source: value.target ?? undefined,
98
93
  };
99
94
  }
100
-
101
95
  // try to reconciliate
102
-
103
96
  // count things
104
97
  let missing = 0;
105
- const same: string[] = [];
98
+ const same = [];
106
99
  let dirty = 0;
107
100
  for (const [k, c] of Object.entries(translations.resources)) {
108
101
  if (!c.target) {
109
102
  missing++;
110
103
  c.target = null; // so it is serialized as json
111
- } else if (c.target === c.source) {
104
+ }
105
+ else if (c.target === c.source) {
112
106
  same.push(k);
113
107
  }
114
108
  if (c.dirty) {
@@ -116,4 +110,5 @@ export function reconciliate(translations: Translation, source: Translation) {
116
110
  }
117
111
  }
118
112
  return { missing, same, dirty };
119
- }
113
+ }
114
+ //# sourceMappingURL=reconciliate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciliate.js","sourceRoot":"","sources":["../../src/cli/reconciliate.ts"],"names":[],"mappings":";;;;;AAeA,oCAuGC;AArHD,oEAAyC;AACzC,4DAAoC;AACpC,mCAAoC;AAGpC,MAAM,KAAK,GAA2B,EAAE,CAAC;AACzC,SAAS,KAAK,CAAC,CAAoB;IAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,OAAO,KAAK,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;IACd,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1D,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;YACV,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,8BAA8B;QACnD,CAAC;aAAM,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;QACD,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YACV,KAAK,EAAE,CAAC;QACZ,CAAC;IACL,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC"}
package/cli/utils.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { CollectResult, GroupedTranslation, Translation } from '../core/load';
2
+ export declare function groupByNamespace(trans: CollectResult): {
3
+ [namespace: string]: CollectResult;
4
+ };
5
+ export declare function toGroupedTranslation(translation: Translation): GroupedTranslation;
6
+ export declare function deepEqual<T>(obj1: T, obj2: T): boolean;
@@ -1,8 +1,14 @@
1
- import fastDeepEqual from 'fast-deep-equal';
2
- import type { CollectResult, GroupedTranslation, Translation } from '../core/load';
3
-
4
- export function groupByNamespace(trans: CollectResult): {[namespace: string]: CollectResult} {
5
- const result: {[namespace: string]: CollectResult} = {};
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.groupByNamespace = groupByNamespace;
7
+ exports.toGroupedTranslation = toGroupedTranslation;
8
+ exports.deepEqual = deepEqual;
9
+ const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
10
+ function groupByNamespace(trans) {
11
+ const result = {};
6
12
  for (let [id, v] of Object.entries(trans)) {
7
13
  let namespace = '$default';
8
14
  const i = id.indexOf('.');
@@ -17,20 +23,18 @@ export function groupByNamespace(trans: CollectResult): {[namespace: string]: Co
17
23
  }
18
24
  return result;
19
25
  }
20
-
21
- export function toGroupedTranslation(translation: Translation): GroupedTranslation {
26
+ function toGroupedTranslation(translation) {
22
27
  return {
23
28
  resources: groupByNamespace(translation.resources),
24
29
  sourceLanguage: translation.sourceLanguage,
25
30
  targetLanguage: translation.targetLanguage,
26
31
  };
27
32
  }
28
-
29
-
30
- export function deepEqual<T>(obj1: T, obj2: T): boolean {
33
+ function deepEqual(obj1, obj2) {
31
34
  // if (typeof Bun !== 'undefined') {
32
35
  // const inst = Bun;
33
36
  // return inst.deepEquals(obj1, obj2);
34
37
  // }
35
- return fastDeepEqual(obj1, obj2);
36
- }
38
+ return (0, fast_deep_equal_1.default)(obj1, obj2);
39
+ }
40
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":";;;;;AAGA,4CAeC;AAED,oDAMC;AAGD,8BAMC;AAnCD,sEAA4C;AAG5C,SAAgB,gBAAgB,CAAC,KAAoB;IACjD,MAAM,MAAM,GAAyC,EAAE,CAAC;IACxD,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,IAAI,SAAS,GAAG,UAAU,CAAC;QAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5B,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAC3B,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAgB,oBAAoB,CAAC,WAAwB;IACzD,OAAO;QACH,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC;QAClD,cAAc,EAAE,WAAW,CAAC,cAAc;QAC1C,cAAc,EAAE,WAAW,CAAC,cAAc;KAC7C,CAAC;AACN,CAAC;AAGD,SAAgB,SAAS,CAAI,IAAO,EAAE,IAAO;IACzC,oCAAoC;IACpC,wBAAwB;IACxB,0CAA0C;IAC1C,IAAI;IACJ,OAAO,IAAA,yBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ILocaleDef, LocLiteral, ILiteralLocalizer } from './interfaces';
2
+ import React from 'react';
3
+ export declare class DefaultLocale implements ILocaleDef {
4
+ readonly id: string;
5
+ readonly literals: ILiteralLocalizer;
6
+ readonly code: string | undefined;
7
+ constructor(id: string);
8
+ localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: false): string;
9
+ localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: true): React.ReactNode;
10
+ }
@@ -1,54 +1,49 @@
1
- import { ILocaleDef, LocLiteral, ILiteralLocalizer } from './interfaces';
2
- import { LiteralLocalizer } from './literal';
3
- import { getLocale } from './locale-list';
4
- import { asFragment, autoGenerateId, getLocaleCode } from './utils';
5
- import React from 'react';
6
-
7
- const emptyStringAutoId = autoGenerateId([]);
8
- export class DefaultLocale implements ILocaleDef {
9
-
10
- readonly literals: ILiteralLocalizer;
11
- readonly code: string | undefined;
12
-
13
- constructor(readonly id: string) {
14
- this.literals = new LiteralLocalizer(this);
15
- this.code = getLocaleCode(id);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultLocale = void 0;
4
+ const literal_1 = require("./literal");
5
+ const locale_list_1 = require("./locale-list");
6
+ const utils_1 = require("./utils");
7
+ const emptyStringAutoId = (0, utils_1.autoGenerateId)([]);
8
+ class DefaultLocale {
9
+ id;
10
+ literals;
11
+ code;
12
+ constructor(id) {
13
+ this.id = id;
14
+ this.literals = new literal_1.LiteralLocalizer(this);
15
+ this.code = (0, utils_1.getLocaleCode)(id);
16
16
  }
17
-
18
- localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: false): string;
19
- localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: true): React.ReactNode;
20
- localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: boolean): string | React.ReactNode {
21
- const existing = getLocale(this.id);
17
+ localize(id, count, parts, placeholders, react) {
18
+ const existing = (0, locale_list_1.getLocale)(this.id);
22
19
  if (existing) {
23
20
  const exist = existing.localize(id, count, parts, placeholders, react);
24
21
  if (exist) {
25
22
  return exist;
26
23
  }
27
24
  }
28
-
29
25
  if (!parts || !placeholders) {
30
26
  // special case for empty string, which could not be translated.
31
27
  if (id === emptyStringAutoId) {
32
28
  return '';
33
29
  }
34
- throw new Error(`The smartloc string "${id}" cannot be translated to your default locale. It is likely that is has been deserialized. In order to support deserialized strings, you MUST load your default locale as a classic locale. nb: To generate your default locale translation file through smartloc CLI, use --generateDefault option`)
30
+ throw new Error(`The smartloc string "${id}" cannot be translated to your default locale. It is likely that is has been deserialized. In order to support deserialized strings, you MUST load your default locale as a classic locale. nb: To generate your default locale translation file through smartloc CLI, use --generateDefault option`);
35
31
  }
36
-
37
32
  // fallback to the in-code translation
38
- const result: React.ReactNode[] = [];
39
-
33
+ const result = [];
40
34
  // interleave the literals with the placeholders
41
35
  for (let i = 0; i < placeholders.length; i++) {
42
36
  result.push(parts[i]);
43
37
  result.push(this.literals.localize(placeholders[i], react));
44
38
  }
45
-
46
39
  // add the last literal
47
40
  result.push(parts[parts.length - 1]);
48
41
  if (react) {
49
42
  // return a fragment having result as children
50
- return asFragment(result);
43
+ return (0, utils_1.asFragment)(result);
51
44
  }
52
45
  return result.join('');
53
46
  }
54
- }
47
+ }
48
+ exports.DefaultLocale = DefaultLocale;
49
+ //# sourceMappingURL=default-locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-locale.js","sourceRoot":"","sources":["../../src/core/default-locale.tsx"],"names":[],"mappings":";;;AACA,uCAA6C;AAC7C,+CAA0C;AAC1C,mCAAoE;AAGpE,MAAM,iBAAiB,GAAG,IAAA,sBAAc,EAAC,EAAE,CAAC,CAAC;AAC7C,MAAa,aAAa;IAKD;IAHZ,QAAQ,CAAoB;IAC5B,IAAI,CAAqB;IAElC,YAAqB,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAgB,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,IAAA,qBAAa,EAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAID,QAAQ,CAAC,EAAU,EAAE,KAAoB,EAAE,KAAkC,EAAE,YAAiC,EAAE,KAAc;QAC5H,MAAM,QAAQ,GAAG,IAAA,uBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,QAAQ,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YACvE,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1B,gEAAgE;YAChE,IAAI,EAAE,KAAK,iBAAiB,EAAE,CAAC;gBAC3B,OAAO,EAAE,CAAC;YACd,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,EAAE,qSAAqS,CAAC,CAAA;QACpV,CAAC;QAED,sCAAsC;QACtC,MAAM,MAAM,GAAsB,EAAE,CAAC;QAErC,gDAAgD;QAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QAChE,CAAC;QAED,uBAAuB;QACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACR,8CAA8C;YAC9C,OAAO,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;CACJ;AA9CD,sCA8CC"}
@@ -1,26 +1,21 @@
1
1
  export type LocStr = InternalLocStr & React.ReactElement;
2
-
3
2
  export interface InternalLocStr {
4
3
  /**
5
4
  * Localizes this string. To be used within a @see withLocales scope to have an actual translation.
6
5
  */
7
6
  toString(locale?: string | ILocaleDef): string;
8
7
  toJSON(): any;
9
-
10
8
  /** Apply a transformation to the final translated text */
11
9
  transform(transformer: (x: string) => string): LocStr;
12
-
13
10
  /** React hook equivalent of .toString(), but which will updated when local changes */
14
11
  useAsString(): string;
15
12
  }
16
-
17
13
  export type LocLiteral = string | number | Date | LocStr | React.ReactNode;
18
14
  export interface ILiteralLocalizer {
19
15
  localize(data: LocLiteral, react: false): string;
20
16
  localize(data: LocLiteral, react: true): React.ReactNode;
21
17
  localize(data: LocLiteral, react: boolean): string | React.ReactNode;
22
18
  }
23
-
24
19
  export interface ILocaleDef {
25
20
  readonly id: string;
26
21
  readonly code: string | undefined;
@@ -29,21 +24,21 @@ export interface ILocaleDef {
29
24
  localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: true): React.ReactNode | null;
30
25
  localize(id: string, count: number | null, parts: TemplateStringsArray | null, placeholders: LocLiteral[] | null, react: boolean): string | React.ReactNode | null;
31
26
  }
32
-
33
27
  export type TranslationTarget = string | {
34
28
  singular: string | null;
35
29
  plural: string;
36
- }
37
-
38
- export type TranslationOf<T> = T extends LocStr ? string
39
- : T extends Object ? { [K in keyof T]: TranslationOf<T[K]> }
40
- : T extends (infer E)[] ? TranslationOf<E>[]
41
- : T;
42
-
43
-
44
- export type StorableOf<T> = T extends LocStr ? Stored
45
- : T extends Object ? { [K in keyof T]: StorableOf<T[K]> }
46
- : T extends (infer E)[] ? StorableOf<E>[]
47
- : T;
48
-
49
- type Stored = string | { [key: string]: string } | { i18n: string; data: any[]; count?: number } | LocStr; // LocStr is there in case nonDescriptive is 'skip'
30
+ };
31
+ export type TranslationOf<T> = T extends LocStr ? string : T extends Object ? {
32
+ [K in keyof T]: TranslationOf<T[K]>;
33
+ } : T extends (infer E)[] ? TranslationOf<E>[] : T;
34
+ export type StorableOf<T> = T extends LocStr ? Stored : T extends Object ? {
35
+ [K in keyof T]: StorableOf<T[K]>;
36
+ } : T extends (infer E)[] ? StorableOf<E>[] : T;
37
+ type Stored = string | {
38
+ [key: string]: string;
39
+ } | {
40
+ i18n: string;
41
+ data: any[];
42
+ count?: number;
43
+ } | LocStr;
44
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/core/interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { SerializationContextOptions } from './smartloc';
2
+ import type { TranslationOf, StorableOf } from './interfaces';
3
+ /**
4
+ * Parse a JSON string where localized strings have been serialized in their non translated form
5
+ */
6
+ export declare function jsonParseLocalized(value: string): any;
7
+ /**
8
+ * Transforms an object that has been deserialized from a non translated from to an object that is translatable
9
+ */
10
+ export declare function toLocalizable(value: any): any;
11
+ /**
12
+ * Transforms an object so it can be stored with localized strings in their non translated form
13
+ * @returns Either a new copy of your object, or your object (if had no smarloc strings in it)
14
+ */
15
+ export declare function toJsonStorable<T>(value: T, options?: SerializationContextOptions): StorableOf<T>;
16
+ /** Translates an object to the given language */
17
+ export declare function translateObject<T>(locales: string | string[], object: T): TranslationOf<T>;
18
+ /** Translates an object according to the current context (call this when wrapped in withSerializationContext() or withLocales()) */
19
+ export declare function translateInContext(object: any): any;
@@ -1,35 +1,38 @@
1
- import { singleLoc, multiLoc, withSerializationContext, withLocales, SerializationContextOptions, smartLoc } from './smartloc';
2
- import { isLocStr } from './literal';
3
- import type { TranslationOf, StorableOf } from './interfaces';
4
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsonParseLocalized = jsonParseLocalized;
4
+ exports.toLocalizable = toLocalizable;
5
+ exports.toJsonStorable = toJsonStorable;
6
+ exports.translateObject = translateObject;
7
+ exports.translateInContext = translateInContext;
8
+ const smartloc_1 = require("./smartloc");
9
+ const literal_1 = require("./literal");
5
10
  /**
6
11
  * Parse a JSON string where localized strings have been serialized in their non translated form
7
12
  */
8
- export function jsonParseLocalized(value: string) {
13
+ function jsonParseLocalized(value) {
9
14
  const parsed = JSON.parse(value);
10
15
  return _toLocalizable(parsed, 50);
11
16
  }
12
-
13
17
  /**
14
18
  * Transforms an object that has been deserialized from a non translated from to an object that is translatable
15
19
  */
16
- export function toLocalizable(value: any) {
20
+ function toLocalizable(value) {
17
21
  return _toLocalizable(value, 50);
18
22
  }
19
- function _toLocalizable(value: any, depth: number): any {
23
+ function _toLocalizable(value, depth) {
20
24
  if (depth < 0) {
21
25
  throw new Error('This object is either too nested, or has cycles');
22
26
  }
23
27
  if (!value) {
24
28
  return value;
25
29
  }
26
-
27
30
  if (typeof value === 'string') {
28
31
  if (value.startsWith('i18n/single:')) {
29
- return singleLoc(value.substr('i18n/single:'.length));
32
+ return (0, smartloc_1.singleLoc)(value.substr('i18n/single:'.length));
30
33
  }
31
34
  if (value.startsWith('i18n/id:')) {
32
- return smartLoc({
35
+ return (0, smartloc_1.smartLoc)({
33
36
  id: value.substr('i18n/id:'.length),
34
37
  count: undefined,
35
38
  literals: null,
@@ -38,11 +41,9 @@ function _toLocalizable(value: any, depth: number): any {
38
41
  }
39
42
  return value;
40
43
  }
41
-
42
44
  if (typeof value !== 'object' || value instanceof Date) {
43
45
  return value;
44
46
  }
45
-
46
47
  // === handle arrays
47
48
  if (value instanceof Array) {
48
49
  const retArray = [];
@@ -60,26 +61,23 @@ function _toLocalizable(value: any, depth: number): any {
60
61
  if (!keys.length) {
61
62
  return value;
62
63
  }
63
-
64
64
  // === handle smartloc with args
65
65
  if (keys.length === 2 && keys.includes('i18n') && keys.includes('data') && typeof value.i18n === 'string' && value.data instanceof Array) {
66
- return smartLoc({
66
+ return (0, smartloc_1.smartLoc)({
67
67
  id: value.i18n,
68
68
  literals: null,
69
69
  placeholders: value.data,
70
70
  count: value.count
71
71
  });
72
72
  }
73
-
74
73
  // === handle multi
75
- const ret: Record<string, string> = {};
74
+ const ret = {};
76
75
  if (!keys.some(x => !x.startsWith('i18n:'))) {
77
76
  for (const k of keys) {
78
77
  ret[k.substr('i18n:'.length)] = value[k];
79
78
  }
80
- return multiLoc(ret);
79
+ return (0, smartloc_1.multiLoc)(ret);
81
80
  }
82
-
83
81
  // === handle plain object
84
82
  let changed = false;
85
83
  for (const k of keys) {
@@ -90,29 +88,25 @@ function _toLocalizable(value: any, depth: number): any {
90
88
  ? ret
91
89
  : value;
92
90
  }
93
-
94
91
  /**
95
92
  * Transforms an object so it can be stored with localized strings in their non translated form
96
93
  * @returns Either a new copy of your object, or your object (if had no smarloc strings in it)
97
94
  */
98
- export function toJsonStorable<T>(value: T, options?: SerializationContextOptions): StorableOf<T> {
99
- return withSerializationContext(() => _toJsonStorable(value, 50), options);
95
+ function toJsonStorable(value, options) {
96
+ return (0, smartloc_1.withSerializationContext)(() => _toJsonStorable(value, 50), options);
100
97
  }
101
-
102
98
  /** Translates an object to the given language */
103
- export function translateObject<T>(locales: string | string[], object: T): TranslationOf<T> {
99
+ function translateObject(locales, object) {
104
100
  if (typeof locales === 'string') {
105
101
  locales = [locales];
106
102
  }
107
- return withLocales(locales, () => _toJsonStorable(object, 50));
103
+ return (0, smartloc_1.withLocales)(locales, () => _toJsonStorable(object, 50));
108
104
  }
109
-
110
105
  /** Translates an object according to the current context (call this when wrapped in withSerializationContext() or withLocales()) */
111
- export function translateInContext(object: any) {
106
+ function translateInContext(object) {
112
107
  return _toJsonStorable(object, 50);
113
108
  }
114
-
115
- function _toJsonStorable(v: any, depth: number) {
109
+ function _toJsonStorable(v, depth) {
116
110
  if (depth < 0) {
117
111
  throw new Error('This object is either too nested, or has cycles');
118
112
  }
@@ -126,7 +120,7 @@ function _toJsonStorable(v: any, depth: number) {
126
120
  return v;
127
121
  }
128
122
  if (v instanceof Array) {
129
- let ret: any[] | undefined = undefined;
123
+ let ret = undefined;
130
124
  for (let i = 0; i < v.length; i++) {
131
125
  const p = _toJsonStorable(v[i], depth - 1);
132
126
  if (p !== v[i] && !ret) {
@@ -141,11 +135,10 @@ function _toJsonStorable(v: any, depth: number) {
141
135
  }
142
136
  return ret || v;
143
137
  }
144
- if (isLocStr(v)) {
138
+ if ((0, literal_1.isLocStr)(v)) {
145
139
  return v.toJSON();
146
140
  }
147
-
148
- const obj: Record<string, any> = {};
141
+ const obj = {};
149
142
  let diff = false;
150
143
  for (const [k, p] of Object.entries(v)) {
151
144
  const val = _toJsonStorable(p, depth - 1);
@@ -160,3 +153,4 @@ function _toJsonStorable(v: any, depth: number) {
160
153
  Object.setPrototypeOf(obj, Object.getPrototypeOf(v));
161
154
  return obj;
162
155
  }
156
+ //# sourceMappingURL=json-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-utils.js","sourceRoot":"","sources":["../../src/core/json-utils.ts"],"names":[],"mappings":";;AAOA,gDAGC;AAKD,sCAEC;AAgFD,wCAEC;AAGD,0CAKC;AAGD,gDAEC;AAhHD,yCAA+H;AAC/H,uCAAqC;AAGrC;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAAa;IAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAU;IACpC,OAAO,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC;AACD,SAAS,cAAc,CAAC,KAAU,EAAE,KAAa;IAC7C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;YACnC,OAAO,IAAA,oBAAS,EAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAA,mBAAQ,EAAC;gBACZ,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU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AAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClB,CAAC;YACL,CAAC;YACD,IAAI,GAAG,EAAE,CAAC;gBACN,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACf,CAAC;QACL,CAAC;QACD,OAAO,GAAG,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,IAAA,kBAAQ,EAAC,CAAC,CAAC,EAAE,CAAC;QACd,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACtB,CAAC;IAED,MAAM,GAAG,GAAwB,EAAE,CAAC;IACpC,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACZ,IAAI,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,CAAC,CAAC;IACb,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { LocLiteral, LocStr, ILocaleDef, ILiteralLocalizer } from './interfaces';
3
+ export declare function isLocStr(data: any): data is LocStr;
4
+ export declare function setIsLoc(data: any): void;
5
+ export declare class LiteralLocalizer implements ILiteralLocalizer {
6
+ private locale;
7
+ private numbers;
8
+ private dateTimeFormat;
9
+ private dateFormat;
10
+ constructor(locale: ILocaleDef);
11
+ localize(data: LocLiteral, react: false): string;
12
+ localize(data: LocLiteral, react: true): React.ReactNode;
13
+ }