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,40 +1,65 @@
1
- import { getLocale, getDefaultLocale, getCurrentLocale, subscribeToLocaleChange, listLocaleDefs } from './locale-list';
2
- import { ILocaleDef, InternalLocStr, LocLiteral, LocStr } from './interfaces';
3
- import { setIsLoc } from './literal';
4
- import React, { useState } from 'react';
5
- import { asFragment } from './utils';
6
-
7
- let langCtx: ILocaleDef[] | null = null;
8
- let serialContext: SerializationContextOptions | null = null;
9
-
10
- export function useAsString(loc: LocStr | string | null): string | null;
11
- export function useAsString(loc: LocStr | string | undefined): string | undefined;
12
- export function useAsString(loc: LocStr | string | undefined): string | undefined;
13
- export function useAsString(loc: LocStr | string | null | undefined): string | null | undefined {
14
- const [, setCount] = useState(0);
15
- React.useEffect(() => {
16
- const unsub = subscribeToLocaleChange(() => setCount(c => c + 1));
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.multiLoc = exports.transformed = exports.smartLoc = void 0;
37
+ exports.useAsString = useAsString;
38
+ exports.withLocales = withLocales;
39
+ exports.withSerializationContext = withSerializationContext;
40
+ exports.singleLoc = singleLoc;
41
+ exports.joinArray = joinArray;
42
+ const jsx_runtime_1 = require("react/jsx-runtime");
43
+ const locale_list_1 = require("./locale-list");
44
+ const literal_1 = require("./literal");
45
+ const react_1 = __importStar(require("react"));
46
+ const utils_1 = require("./utils");
47
+ let langCtx = null;
48
+ let serialContext = null;
49
+ function useAsString(loc) {
50
+ const [, setCount] = (0, react_1.useState)(0);
51
+ react_1.default.useEffect(() => {
52
+ const unsub = (0, locale_list_1.subscribeToLocaleChange)(() => setCount(c => c + 1));
17
53
  return unsub;
18
54
  }, []);
19
55
  return loc?.toString();
20
56
  }
21
-
22
-
23
- export interface SerializationContextOptions {
24
- /** HOw non self-descriptive (MultiLoc, SingleLoc, ...) will be transformed. Defaults to 'id'.
25
- *
26
- * id => will serialize its ID ... the context of deserialization will be required to have the given translation
27
- * skip => will be left as it (=> serialization will translate it)
28
- * toMulti => translates to all registered languages, and serializes as a 'multi'
29
- */
30
- nonSelfDescriptive?: 'skip' | 'toMulti' | 'id';
31
- }
32
57
  /**
33
58
  * Execute something in the given locales context.
34
59
  * @param acceptLanguages The accepted languages, by order of preference
35
60
  * @param action Action to perform (usually a JSON.serialize() or a .toString() operation)
36
61
  **/
37
- export function withLocales<T = void>(acceptLanguages: string[], action: () => T) {
62
+ function withLocales(acceptLanguages, action) {
38
63
  if (!acceptLanguages || !acceptLanguages.length) {
39
64
  return action();
40
65
  }
@@ -42,62 +67,43 @@ export function withLocales<T = void>(acceptLanguages: string[], action: () => T
42
67
  try {
43
68
  // set accepted languages
44
69
  langCtx = acceptLanguages
45
- .map(getLocale)
70
+ .map(locale_list_1.getLocale)
46
71
  .filter(x => !!x);
47
-
48
72
  // perform action
49
73
  return action();
50
- } finally {
74
+ }
75
+ finally {
51
76
  langCtx = oldLangCtx;
52
77
  }
53
78
  }
54
-
55
79
  /**
56
80
  * Execute something in a context where .toJson() loc strings
57
81
  * will be serialized into a form that is parsable via jsonParseLocalized()
58
82
  */
59
- export function withSerializationContext<T = void>(action: () => T, options?: SerializationContextOptions) {
83
+ function withSerializationContext(action, options) {
60
84
  const os = serialContext;
61
85
  try {
62
86
  serialContext = options || {};
63
87
  return action();
64
- } finally {
88
+ }
89
+ finally {
65
90
  serialContext = os;
66
91
  }
67
92
  }
68
-
69
-
70
- interface SmartlocProps {
71
- id: string,
72
- literals: TemplateStringsArray | null;
73
- placeholders: LocLiteral[] | null;
74
- count: number | undefined;
75
- }
76
-
77
- function createKind<props extends object>(opts: {
78
- name: string;
79
- render: (props: props, locale: ILocaleDef) => React.ReactNode | null;
80
- toString: (props: props, locale: ILocaleDef) => string | null;
81
- toJson: (props: props) => any;
82
- }) {
83
-
93
+ function createKind(opts) {
84
94
  const Renderer = {
85
- [opts.name]: class extends React.Component<props, { locale: ILocaleDef | null }> {
86
- private rerender = () => this.setState({
87
- locale: getCurrentLocale(),
95
+ [opts.name]: class extends react_1.default.Component {
96
+ rerender = () => this.setState({
97
+ locale: (0, locale_list_1.getCurrentLocale)(),
88
98
  });
89
- private unsub?: () => void;
90
-
91
- override componentDidMount(): void {
92
- this.unsub = subscribeToLocaleChange(this.rerender);
93
-
99
+ unsub;
100
+ componentDidMount() {
101
+ this.unsub = (0, locale_list_1.subscribeToLocaleChange)(this.rerender);
94
102
  }
95
-
96
- override componentWillUnmount() {
103
+ componentWillUnmount() {
97
104
  this.unsub?.();
98
105
  }
99
-
100
- override render(): React.ReactNode {
106
+ render() {
101
107
  const locale = this.state?.locale;
102
108
  if (locale) {
103
109
  const rendered = opts.render(this.props, locale);
@@ -105,14 +111,14 @@ function createKind<props extends object>(opts: {
105
111
  return rendered;
106
112
  }
107
113
  }
108
- const currentLocale = getCurrentLocale(true);
114
+ const currentLocale = (0, locale_list_1.getCurrentLocale)(true);
109
115
  if (currentLocale) {
110
116
  const rendered = opts.render(this.props, currentLocale);
111
117
  if (rendered) {
112
118
  return rendered;
113
119
  }
114
120
  }
115
- const defaultLocale = getDefaultLocale();
121
+ const defaultLocale = (0, locale_list_1.getDefaultLocale)();
116
122
  if (defaultLocale) {
117
123
  const rendered = opts.render(this.props, defaultLocale);
118
124
  if (rendered) {
@@ -123,29 +129,25 @@ function createKind<props extends object>(opts: {
123
129
  }
124
130
  },
125
131
  }[opts.name];
126
-
127
132
  const Proto = {
128
- [opts.name]: class implements InternalLocStr {
133
+ [opts.name]: class {
129
134
  get locKind() {
130
135
  return opts.name;
131
136
  }
132
137
  // will be set the hackky way, see creator below
133
- props!: props;
134
-
138
+ props;
135
139
  toJSON() {
136
140
  if (!serialContext) {
137
141
  return this.toString();
138
142
  }
139
143
  return opts.toJson(this.props);
140
144
  }
141
-
142
- toString(locale?: string | ILocaleDef | null): string {
145
+ toString(locale) {
143
146
  if (typeof locale === 'string') {
144
- locale = getLocale(locale);
147
+ locale = (0, locale_list_1.getLocale)(locale);
145
148
  }
146
-
147
149
  if (locale) {
148
- const localized = opts.toString(this.props, locale)
150
+ const localized = opts.toString(this.props, locale);
149
151
  if (localized) {
150
152
  return localized;
151
153
  }
@@ -158,18 +160,16 @@ function createKind<props extends object>(opts: {
158
160
  }
159
161
  }
160
162
  }
161
-
162
163
  // try current locale
163
- const currentLocale = getCurrentLocale(true);
164
+ const currentLocale = (0, locale_list_1.getCurrentLocale)(true);
164
165
  if (currentLocale) {
165
166
  const localized = opts.toString(this.props, currentLocale);
166
167
  if (localized) {
167
168
  return localized;
168
169
  }
169
170
  }
170
-
171
171
  // fallback to default locale
172
- const defaultLocale = getDefaultLocale();
172
+ const defaultLocale = (0, locale_list_1.getDefaultLocale)();
173
173
  if (!defaultLocale) {
174
174
  throw new Error('You must specify default locale via setDefaultLocale() before using localization');
175
175
  }
@@ -180,45 +180,44 @@ function createKind<props extends object>(opts: {
180
180
  }
181
181
  return def;
182
182
  }
183
-
184
- transform(transformer: (x: string) => string): LocStr {
185
- return transformed({
183
+ transform(transformer) {
184
+ return (0, exports.transformed)({
186
185
  parent: this,
187
186
  transformer,
188
187
  });
189
188
  }
190
-
191
- useAsString(): string {
192
- const [, setCount] = useState(0);
193
- React.useEffect(() => {
194
- const unsub = subscribeToLocaleChange(() => setCount(c => c + 1));
189
+ useAsString() {
190
+ const [, setCount] = (0, react_1.useState)(0);
191
+ react_1.default.useEffect(() => {
192
+ const unsub = (0, locale_list_1.subscribeToLocaleChange)(() => setCount(c => c + 1));
195
193
  return unsub;
196
194
  }, []);
197
195
  return this.toString();
198
196
  }
199
197
  }
200
198
  }[opts.name];
201
-
202
-
203
-
204
199
  // trick to create a function that is named like the given name
205
200
  const creator = {
206
- [opts.name](props: props): LocStr {
207
- const e = React.createElement(Renderer, props);
208
- const eProps = Object.getOwnPropertyDescriptors(e);
201
+ [opts.name](props) {
202
+ // This is a dirty hack to create some item that will both be recognized by React as a valid element,
203
+ // but that also behaves as a LocStr with the appropriate methods.
204
+ // 1) create a react element
205
+ const e = react_1.default.createElement(Renderer, props);
206
+ // 2) create a new instance of our LocStr kind
209
207
  const ret = Object.create(Proto.prototype);
208
+ // 3) raw-copy what the react element has as properties
209
+ // ... this work because React.createElement() actually only creates a raw frozen object with some properties.
210
+ // see createElement() source code
211
+ const eProps = Object.getOwnPropertyDescriptors(e);
210
212
  Object.defineProperties(ret, eProps);
211
- setIsLoc(ret); // this will freeze the object
213
+ // 4) set the isLoc flag to true so isLocStr() will recognize this instance
214
+ (0, literal_1.setIsLoc)(ret); // this will freeze the object
212
215
  return ret;
213
216
  }
214
217
  }[opts.name];
215
-
216
218
  return creator;
217
219
  }
218
-
219
-
220
-
221
- export const smartLoc = createKind<SmartlocProps>({
220
+ exports.smartLoc = createKind({
222
221
  name: 'SmartLoc',
223
222
  render(props, locale) {
224
223
  return locale.localize(props.id, props.count ?? null, props.literals, props.placeholders, true);
@@ -227,19 +226,19 @@ export const smartLoc = createKind<SmartlocProps>({
227
226
  return locale.localize(props.id, props.count ?? null, props.literals, props.placeholders, false);
228
227
  },
229
228
  toJson(props) {
230
- switch (serialContext!.nonSelfDescriptive) {
229
+ switch (serialContext.nonSelfDescriptive) {
231
230
  case 'skip':
232
231
  return this;
233
232
  case 'toMulti':
234
- const multi: Record<string, string> = {};
235
- for (const l of listLocaleDefs()) {
233
+ const multi = {};
234
+ for (const l of (0, locale_list_1.listLocaleDefs)()) {
236
235
  const str = this.toString(props, l);
237
236
  if (str) {
238
237
  multi[l.id] = str;
239
238
  }
240
239
  }
241
240
  // tslint:disable-next-line: no-use-before-declare
242
- return multiLoc(multi).toJSON();
241
+ return (0, exports.multiLoc)(multi).toJSON();
243
242
  default:
244
243
  if (props.placeholders?.length || props.count !== undefined) {
245
244
  return {
@@ -252,14 +251,12 @@ export const smartLoc = createKind<SmartlocProps>({
252
251
  return `i18n/id:${props.id}`;
253
252
  }
254
253
  },
255
-
256
254
  });
257
-
258
- export const transformed = createKind<{ parent: InternalLocStr; transformer: (x: string) => string; }>({
255
+ exports.transformed = createKind({
259
256
  name: 'TransformedLoc',
260
257
  render(props, _) {
261
258
  console.warn('Transformed localized string cannot be rendered as React nodes => fallback to parent rendering');
262
- return <>{props.parent}</>;
259
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.parent });
263
260
  },
264
261
  toString(props, locale) {
265
262
  const ret = props.parent.toString(locale);
@@ -272,11 +269,10 @@ export const transformed = createKind<{ parent: InternalLocStr; transformer: (x:
272
269
  return props.parent.toJSON();
273
270
  },
274
271
  });
275
- export function singleLoc(text: string) {
272
+ function singleLoc(text) {
276
273
  return _singleLoc({ text });
277
274
  }
278
-
279
- const _singleLoc = createKind<{ text: string }>({
275
+ const _singleLoc = createKind({
280
276
  name: 'SingleLoc',
281
277
  render(props) {
282
278
  return props.text;
@@ -288,14 +284,12 @@ const _singleLoc = createKind<{ text: string }>({
288
284
  return 'i18n/single:' + props.text;
289
285
  },
290
286
  });
291
-
292
-
293
- export const multiLoc = createKind<Record<string, string>>({
287
+ exports.multiLoc = createKind({
294
288
  name: 'MultiLoc',
295
289
  render(props, locale) {
296
290
  const t = this.toString(props, locale);
297
291
  if (!t) {
298
- return <></>;
292
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
299
293
  }
300
294
  return t;
301
295
  },
@@ -303,22 +297,20 @@ export const multiLoc = createKind<Record<string, string>>({
303
297
  return props[locale.id] ?? props[locale.code ?? ''];
304
298
  },
305
299
  toJson(props) {
306
- const ret: Record<string, string> = {};
300
+ const ret = {};
307
301
  for (const [k, v] of Object.entries(props)) {
308
302
  ret[`i18n:${k}`] = v;
309
303
  }
310
304
  return ret;
311
305
  }
312
306
  });
313
-
314
- export function joinArray(separator: string | LocStr, items: (string | LocStr)[]): LocStr {
307
+ function joinArray(separator, items) {
315
308
  return _joinedArray({ items, separator });
316
309
  }
317
-
318
- const _joinedArray = createKind<{ separator: string | LocStr, items: (string | LocStr)[] }>({
310
+ const _joinedArray = createKind({
319
311
  name: 'LocStringArray',
320
312
  render(props) {
321
- const elts: any[] = [];
313
+ const elts = [];
322
314
  // locstrings are react-elements
323
315
  for (let i = 0; i < props.items.length; i++) {
324
316
  if (i) {
@@ -326,7 +318,7 @@ const _joinedArray = createKind<{ separator: string | LocStr, items: (string | L
326
318
  }
327
319
  elts.push(props.items[i]);
328
320
  }
329
- return asFragment(elts);
321
+ return (0, utils_1.asFragment)(elts);
330
322
  },
331
323
  toString(props, locale) {
332
324
  const sep = typeof props.separator === 'string' ? props.separator : props.separator.toString(locale);
@@ -335,4 +327,5 @@ const _joinedArray = createKind<{ separator: string | LocStr, items: (string | L
335
327
  toJson() {
336
328
  throw new Error('Cannot transform a joined array to json');
337
329
  }
338
- });
330
+ });
331
+ //# sourceMappingURL=smartloc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smartloc.js","sourceRoot":"","sources":["../../src/core/smartloc.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,kCAOC;AAiBD,kCAgBC;AAMD,4DAQC;AA2ND,8BAEC;AAqCD,8BAEC;;AAtUD,+CAAuH;AAEvH,uCAAqC;AACrC,+CAAwC;AACxC,mCAAqC;AAErC,IAAI,OAAO,GAAwB,IAAI,CAAC;AACxC,IAAI,aAAa,GAAuC,IAAI,CAAC;AAK7D,SAAgB,WAAW,CAAC,GAAuC;IAC/D,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAC;IACjC,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,MAAM,KAAK,GAAG,IAAA,qCAAuB,EAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAYD;;;;IAII;AACJ,SAAgB,WAAW,CAAW,eAAyB,EAAE,MAAe;IAC5E,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,MAAM,EAAE,CAAC;IACpB,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,CAAC;IAC3B,IAAI,C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,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrG,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;IACD,MAAM;QACF,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC/D,CAAC;CACJ,CAAC,CAAC"}
package/core/tag.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { LocLiteral, LocStr } from './interfaces';
2
+ type Templater = (literals: TemplateStringsArray, ...placeholders: LocLiteral[]) => LocStr;
3
+ declare function _tagSig(id: string): Templater;
4
+ declare function _tagSig(literals: TemplateStringsArray, ...placeholders: LocLiteral[]): LocStr;
5
+ type TagSignature = typeof _tagSig;
6
+ type LocTag = TagSignature & {
7
+ /** Creates a pluralizable string (will have two versions to be translated based on the given count: singlular & plural) */
8
+ plural(count: number): TagSignature;
9
+ /** Does nothing, except that the translation will not be collected (use for formatting purposes) */
10
+ nocollect: LocTag;
11
+ };
12
+ export declare const loc: LocTag;
13
+ export {};
package/core/tag.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loc = void 0;
4
+ const smartloc_1 = require("./smartloc");
5
+ const utils_1 = require("./utils");
6
+ function __loc(count, idOrLiterals, ...ph) {
7
+ if (typeof idOrLiterals === 'string') {
8
+ const id = idOrLiterals;
9
+ return (literals, ...placeholders) => {
10
+ return (0, smartloc_1.smartLoc)({ id, literals, placeholders, count });
11
+ };
12
+ }
13
+ return (0, smartloc_1.smartLoc)({ id: (0, utils_1.autoGenerateId)(idOrLiterals), literals: idOrLiterals, placeholders: ph, count });
14
+ }
15
+ function _loc(idOrLiteralsOrCount, ...ph) {
16
+ return __loc(undefined, idOrLiteralsOrCount, ...ph);
17
+ }
18
+ _loc.plural = (count) => {
19
+ function templater(idOrLiterals, ...ph) {
20
+ return __loc(count, idOrLiterals, ...ph);
21
+ }
22
+ return templater;
23
+ };
24
+ _loc.nocollect = () => {
25
+ return _loc;
26
+ };
27
+ exports.loc = _loc;
28
+ //# sourceMappingURL=tag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tag.js","sourceRoot":"","sources":["../../src/core/tag.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC,mCAAyC;AAkBzC,SAAS,KAAK,CAAC,KAAyB,EAAE,YAA2C,EAAE,GAAG,EAAgB;IACtG,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,EAAE,GAAG,YAAY,CAAC;QACxB,OAAO,CAAC,QAA8B,EAAE,GAAG,YAA0B,EAAE,EAAE;YACrE,OAAO,IAAA,mBAAQ,EAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACN,CAAC;IACD,OAAO,IAAA,mBAAQ,EAAC,EAAE,EAAE,EAAE,IAAA,sBAAc,EAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3G,CAAC;AAID,SAAS,IAAI,CAAC,mBAAkD,EAAE,GAAG,EAAgB;IACjF,OAAO,KAAK,CAAC,SAAS,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;AACxD,CAAC;AACD,IAAI,CAAC,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;IAG5B,SAAS,SAAS,CAAC,YAA2C,EAAE,GAAG,EAAgB;QAC/E,OAAO,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AACF,IAAI,CAAC,SAAS,GAAG,GAAG,EAAE;IAClB,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEW,QAAA,GAAG,GAAW,IAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare function autoGenerateId(str: TemplateStringsArray | string[]): string;
3
+ export declare function getLocaleCode(locale: string): string | undefined;
4
+ export declare function asFragment(children: React.ReactNode[]): React.ReactNode;
package/core/utils.js ADDED
@@ -0,0 +1,30 @@
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.autoGenerateId = autoGenerateId;
7
+ exports.getLocaleCode = getLocaleCode;
8
+ exports.asFragment = asFragment;
9
+ const jsx_runtime_1 = require("react/jsx-runtime");
10
+ const js_sha1_1 = require("js-sha1");
11
+ const react_1 = __importDefault(require("react"));
12
+ function autoGenerateId(str) {
13
+ const sha = (0, js_sha1_1.sha1)(str.join('|'));
14
+ return 'sha1.' + sha;
15
+ }
16
+ function getLocaleCode(locale) {
17
+ return locale && /^[a-z]+/.exec(locale.toLowerCase())?.[0] || undefined;
18
+ }
19
+ function asFragment(children) {
20
+ if (children.length === 1) {
21
+ return children[0];
22
+ }
23
+ return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: children.map((x, i) => {
24
+ if (react_1.default.isValidElement(x) && !x.key) {
25
+ return (0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: x }, i);
26
+ }
27
+ return x;
28
+ }) });
29
+ }
30
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.tsx"],"names":[],"mappings":";;;;;AAGA,wCAGC;AAED,sCAEC;AAGD,gCAUC;;AAvBD,qCAA+B;AAC/B,kDAA0B;AAE1B,SAAgB,cAAc,CAAC,GAAoC;IAC/D,MAAM,GAAG,GAAG,IAAA,cAAI,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,OAAO,OAAO,GAAG,GAAG,CAAC;AACzB,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IACxC,OAAO,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;AAC5E,CAAC;AAGD,SAAgB,UAAU,CAAC,QAA2B;IAClD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,uBAAC,eAAK,CAAC,QAAQ,cAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC1C,IAAI,eAAK,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;gBACpC,OAAO,uBAAC,eAAK,CAAC,QAAQ,cAAU,CAAC,IAAL,CAAC,CAAsB,CAAC;YACxD,CAAC;YACD,OAAO,CAAC,CAAC;QACb,CAAC,CAAC,GAAkB,CAAC;AACzB,CAAC"}
package/express.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export interface SmartlocExpressOptions {
2
+ /** (optional) Waits for this promise before performing a translation. This might be for instance the promise that waits all locales to be declared via addLocale() loaded */
3
+ waitFor?: Promise<any>;
4
+ /** Custom resolution (will fall back on accept-language if this function does not return anything) */
5
+ customLocaleResolver?: (req: any) => string | string[] | null | undefined | Promise<string | string[] | null | undefined>;
6
+ /** Error logger (gives a chance to log resolution errors) */
7
+ errorLogger?: (err: any) => void;
8
+ }
9
+ /**
10
+ * Express middleware that will translate calls to .send(), .json() (etc...) based on the Accept-Language request header.
11
+ */
12
+ export default function (options?: SmartlocExpressOptions): (req: any, res: any, next: any) => void;