@intlayer/core 2.0.0 → 2.0.1

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 (70) hide show
  1. package/dist/cjs/index.cjs +3 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.ts +5 -3
  4. package/dist/cjs/transpiler/content_transformers/index.d.ts +0 -1
  5. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +0 -1
  6. package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +0 -1
  7. package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +0 -1
  8. package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -1
  9. package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +1 -2
  10. package/dist/cjs/transpiler/index.d.ts +0 -1
  11. package/dist/cjs/types/declarationContent.cjs +17 -0
  12. package/dist/cjs/types/declarationContent.cjs.map +1 -0
  13. package/dist/cjs/types/{contentModule.d.ts → declarationContent.d.ts} +9 -4
  14. package/dist/cjs/types/{contentModule.cjs → dictionary.cjs} +3 -3
  15. package/dist/cjs/types/dictionary.cjs.map +1 -0
  16. package/dist/cjs/types/dictionary.d.ts +17 -0
  17. package/dist/cjs/types/index.cjs.map +1 -1
  18. package/dist/cjs/types/index.d.ts +4 -3
  19. package/dist/cjs/types/keyPath.cjs.map +1 -1
  20. package/dist/cjs/types/keyPath.d.ts +6 -2
  21. package/dist/cjs/utils/{getStackTraceInfo.cjs → isSameKeyPath.cjs} +9 -23
  22. package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -0
  23. package/dist/cjs/utils/isSameKeyPath.d.ts +6 -0
  24. package/dist/esm/index.d.mts +5 -3
  25. package/dist/esm/index.mjs +2 -0
  26. package/dist/esm/index.mjs.map +1 -1
  27. package/dist/esm/transpiler/content_transformers/index.d.mts +0 -1
  28. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +0 -1
  29. package/dist/esm/transpiler/content_transformers/translation/index.d.mts +0 -1
  30. package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +0 -1
  31. package/dist/esm/transpiler/content_transformers/translation/types.d.mts +1 -2
  32. package/dist/esm/transpiler/index.d.mts +0 -1
  33. package/dist/esm/types/{contentModule.d.mts → declarationContent.d.mts} +9 -4
  34. package/dist/esm/types/declarationContent.mjs +1 -0
  35. package/dist/esm/types/dictionary.d.mts +17 -0
  36. package/dist/esm/types/dictionary.mjs +1 -0
  37. package/dist/esm/types/dictionary.mjs.map +1 -0
  38. package/dist/esm/types/index.d.mts +4 -3
  39. package/dist/esm/types/index.mjs.map +1 -1
  40. package/dist/esm/types/keyPath.d.mts +6 -2
  41. package/dist/esm/utils/isSameKeyPath.d.mts +6 -0
  42. package/dist/esm/utils/isSameKeyPath.mjs +7 -0
  43. package/dist/esm/utils/isSameKeyPath.mjs.map +1 -0
  44. package/package.json +2 -3
  45. package/src/index.ts +6 -1
  46. package/dist/cjs/types/contentModule.cjs.map +0 -1
  47. package/dist/cjs/utils/getStackTraceInfo.cjs.map +0 -1
  48. package/dist/cjs/utils/getStackTraceInfo.d.ts +0 -12
  49. package/dist/esm/types/contentModule.mjs +0 -1
  50. package/dist/esm/utils/getStackTraceInfo.d.mts +0 -12
  51. package/dist/esm/utils/getStackTraceInfo.mjs +0 -21
  52. package/dist/esm/utils/getStackTraceInfo.mjs.map +0 -1
  53. package/src/getLocaleName.ts +0 -463
  54. package/src/localeList.ts +0 -229
  55. package/src/transpiler/content_transformers/enumeration/enumeration.ts +0 -66
  56. package/src/transpiler/content_transformers/enumeration/findMatchingCondition.ts +0 -64
  57. package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +0 -38
  58. package/src/transpiler/content_transformers/enumeration/index.ts +0 -3
  59. package/src/transpiler/content_transformers/index.ts +0 -2
  60. package/src/transpiler/content_transformers/translation/getTranslationContent.ts +0 -33
  61. package/src/transpiler/content_transformers/translation/index.ts +0 -3
  62. package/src/transpiler/content_transformers/translation/translation.ts +0 -49
  63. package/src/transpiler/content_transformers/translation/types.ts +0 -71
  64. package/src/transpiler/index.ts +0 -1
  65. package/src/types/contentModule.ts +0 -33
  66. package/src/types/index.ts +0 -14
  67. package/src/types/keyPath.ts +0 -13
  68. package/src/types/nodeType.ts +0 -4
  69. package/src/utils/getStackTraceInfo.ts +0 -39
  70. /package/dist/esm/types/{contentModule.mjs.map → declarationContent.mjs.map} +0 -0
package/src/localeList.ts DELETED
@@ -1,229 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
-
3
- export const localeList: Locales[] = [
4
- Locales.AFRIKAANS,
5
- Locales.AFRIKAANS_SOUTH_AFRICA,
6
- Locales.ARABIC,
7
- Locales.ARABIC_UNITED_ARAB_EMIRATES,
8
- Locales.ARABIC_BAHRAIN,
9
- Locales.ARABIC_ALGERIA,
10
- Locales.ARABIC_EGYPT,
11
- Locales.ARABIC_IRAQ,
12
- Locales.ARABIC_JORDAN,
13
- Locales.ARABIC_KUWAIT,
14
- Locales.ARABIC_LEBANON,
15
- Locales.ARABIC_LIBYA,
16
- Locales.ARABIC_MOROCCO,
17
- Locales.ARABIC_OMAN,
18
- Locales.ARABIC_QATAR,
19
- Locales.ARABIC_SAUDI_ARABIA,
20
- Locales.ARABIC_SYRIA,
21
- Locales.ARABIC_TUNISIA,
22
- Locales.ARABIC_YEMEN,
23
- Locales.AZERI_LATIN,
24
- Locales.AZERI_LATIN_AZERBAIJAN,
25
- Locales.BELARUSIAN,
26
- Locales.BELARUSIAN_BELARUS,
27
- Locales.BULGARIAN,
28
- Locales.BULGARIAN_BULGARIA,
29
- Locales.BOSNIAN_BOSNIA_AND_HERZEGOVINA,
30
- Locales.CATALAN,
31
- Locales.CATALAN_SPAIN,
32
- Locales.CZECH,
33
- Locales.CZECH_CZECH_REPUBLIC,
34
- Locales.WELSH,
35
- Locales.WELSH_UNITED_KINGDOM,
36
- Locales.DANISH,
37
- Locales.DANISH_DENMARK,
38
- Locales.GERMAN,
39
- Locales.GERMAN_AUSTRIA,
40
- Locales.GERMAN_SWITZERLAND,
41
- Locales.GERMAN_GERMANY,
42
- Locales.GERMAN_LIECHTENSTEIN,
43
- Locales.GERMAN_LUXEMBOURG,
44
- Locales.DIVEHI,
45
- Locales.DIVEHI_MALDIVES,
46
- Locales.GREEK,
47
- Locales.GREEK_GREECE,
48
- Locales.ENGLISH,
49
- Locales.ENGLISH_AUSTRALIA,
50
- Locales.ENGLISH_BELIZE,
51
- Locales.ENGLISH_CANADA,
52
- Locales.ENGLISH_CARIBBEAN,
53
- Locales.ENGLISH_UNITED_KINGDOM,
54
- Locales.ENGLISH_IRELAND,
55
- Locales.ENGLISH_JAMAICA,
56
- Locales.ENGLISH_NEW_ZEALAND,
57
- Locales.ENGLISH_PHILIPPINES,
58
- Locales.ENGLISH_TRINIDAD_AND_TOBAGO,
59
- Locales.ENGLISH_UNITED_STATES,
60
- Locales.ENGLISH_SOUTH_AFRICA,
61
- Locales.ENGLISH_ZIMBABWE,
62
- Locales.ESPERANTO,
63
- Locales.SPANISH,
64
- Locales.SPANISH_ARGENTINA,
65
- Locales.SPANISH_BOLIVIA,
66
- Locales.SPANISH_CHILE,
67
- Locales.SPANISH_COLOMBIA,
68
- Locales.SPANISH_COSTA_RICA,
69
- Locales.SPANISH_DOMINICAN_REPUBLIC,
70
- Locales.SPANISH_ECUADOR,
71
- Locales.SPANISH_SPAIN,
72
- Locales.SPANISH_GUATEMALA,
73
- Locales.SPANISH_HONDURAS,
74
- Locales.SPANISH_MEXICO,
75
- Locales.SPANISH_NICARAGUA,
76
- Locales.SPANISH_PANAMA,
77
- Locales.SPANISH_PERU,
78
- Locales.SPANISH_PUERTO_RICO,
79
- Locales.SPANISH_PARAGUAY,
80
- Locales.SPANISH_EL_SALVADOR,
81
- Locales.SPANISH_URUGUAY,
82
- Locales.SPANISH_VENEZUELA,
83
- Locales.ESTONIAN,
84
- Locales.ESTONIAN_ESTONIA,
85
- Locales.BASQUE,
86
- Locales.BASQUE_SPAIN,
87
- Locales.FARSI,
88
- Locales.FARSI_IRAN,
89
- Locales.FINNISH,
90
- Locales.FINNISH_FINLAND,
91
- Locales.FAROESE,
92
- Locales.FAROESE_FAROE_ISLANDS,
93
- Locales.FRENCH,
94
- Locales.FRENCH_BELGIUM,
95
- Locales.FRENCH_CANADA,
96
- Locales.FRENCH_SWITZERLAND,
97
- Locales.FRENCH_FRANCE,
98
- Locales.FRENCH_LUXEMBOURG,
99
- Locales.FRENCH_PRINCIPALITY_OF_MONACO,
100
- Locales.GALICIAN,
101
- Locales.GALICIAN_SPAIN,
102
- Locales.GUJARATI,
103
- Locales.GUJARATI_INDIA,
104
- Locales.HEBREW,
105
- Locales.HEBREW_ISRAEL,
106
- Locales.HINDI,
107
- Locales.HINDI_INDIA,
108
- Locales.CROATIAN,
109
- Locales.CROATIAN_BOSNIA_AND_HERZEGOVINA,
110
- Locales.CROATIAN_CROATIA,
111
- Locales.HUNGARIAN,
112
- Locales.HUNGARIAN_HUNGARY,
113
- Locales.ARMENIAN,
114
- Locales.ARMENIAN_ARMENIA,
115
- Locales.INDONESIAN,
116
- Locales.INDONESIAN_INDONESIA,
117
- Locales.ICELANDIC,
118
- Locales.ICELANDIC_ICELAND,
119
- Locales.ITALIAN,
120
- Locales.ITALIAN_SWITZERLAND,
121
- Locales.ITALIAN_ITALY,
122
- Locales.JAPANESE,
123
- Locales.JAPANESE_JAPAN,
124
- Locales.GEORGIAN,
125
- Locales.GEORGIAN_GEORGIA,
126
- Locales.KAZAKH,
127
- Locales.KAZAKH_KAZAKHSTAN,
128
- Locales.KANNADA,
129
- Locales.KANNADA_INDIA,
130
- Locales.KOREAN,
131
- Locales.KOREAN_KOREA,
132
- Locales.KONKANI,
133
- Locales.KONKANI_INDIA,
134
- Locales.KYRGYZ,
135
- Locales.KYRGYZ_KYRGYZSTAN,
136
- Locales.LITHUANIAN,
137
- Locales.LITHUANIAN_LITHUANIA,
138
- Locales.LATVIAN,
139
- Locales.LATVIAN_LATVIA,
140
- Locales.MAORI,
141
- Locales.MAORI_NEW_ZEALAND,
142
- Locales.FYRO_MACEDONIAN,
143
- Locales.FYRO_MACEDONIAN_MACEDONIA,
144
- Locales.MONGOLIAN,
145
- Locales.MONGOLIAN_MONGOLIA,
146
- Locales.MARATHI,
147
- Locales.MARATHI_INDIA,
148
- Locales.MALAY,
149
- Locales.MALAY_BRUNEI_DARUSSALAM,
150
- Locales.MALAY_MALAYSIA,
151
- Locales.MALTESE,
152
- Locales.MALTESE_MALTA,
153
- Locales.NORWEGIAN_BOKMAL,
154
- Locales.NORWEGIAN_BOKMAL_NORWAY,
155
- Locales.DUTCH,
156
- Locales.DUTCH_BELGIUM,
157
- Locales.DUTCH_NETHERLANDS,
158
- Locales.NORWEGIAN_NYNORSK_NORWAY,
159
- Locales.NORTHERN_SOTHO,
160
- Locales.NORTHERN_SOTHO_SOUTH_AFRICA,
161
- Locales.PUNJABI,
162
- Locales.PUNJABI_INDIA,
163
- Locales.POLISH,
164
- Locales.POLISH_POLAND,
165
- Locales.PASHTO,
166
- Locales.PASHTO_AFGHANISTAN,
167
- Locales.PORTUGUESE,
168
- Locales.PORTUGUESE_BRAZIL,
169
- Locales.PORTUGUESE_PORTUGAL,
170
- Locales.QUECHUA,
171
- Locales.QUECHUA_BOLIVIA,
172
- Locales.QUECHUA_ECUADOR,
173
- Locales.QUECHUA_PERU,
174
- Locales.ROMANIAN,
175
- Locales.ROMANIAN_ROMANIA,
176
- Locales.RUSSIAN,
177
- Locales.RUSSIAN_RUSSIA,
178
- Locales.SANSKRIT,
179
- Locales.SANSKRIT_INDIA,
180
- Locales.SAMI_NORTHERN,
181
- Locales.SAMI_NORTHERN_FINLAND,
182
- Locales.SAMI_NORTHERN_NORWAY,
183
- Locales.SAMI_NORTHERN_SWEDEN,
184
- Locales.SLOVAK,
185
- Locales.SLOVAK_SLOVAKIA,
186
- Locales.SLOVENIAN,
187
- Locales.SLOVENIAN_SLOVENIA,
188
- Locales.ALBANIAN,
189
- Locales.ALBANIAN_ALBANIA,
190
- Locales.SERBIAN_LATIN_BOSNIA_AND_HERZEGOVINA,
191
- Locales.SERBIAN_LATIN_SERBIA_AND_MONTENEGRO,
192
- Locales.SWEDISH,
193
- Locales.SWEDISH_FINLAND,
194
- Locales.SWEDISH_SWEDEN,
195
- Locales.SWAHILI_KENYA,
196
- Locales.SYRIAC_SYRIA,
197
- Locales.TAMIL,
198
- Locales.TAMIL_INDIA,
199
- Locales.TELUGU,
200
- Locales.TELUGU_INDIA,
201
- Locales.THAI,
202
- Locales.THAI_THAILAND,
203
- Locales.TAGALOG,
204
- Locales.TAGALOG_PHILIPPINES,
205
- Locales.TSWANA,
206
- Locales.TSWANA_SOUTH_AFRICA,
207
- Locales.TURKISH,
208
- Locales.TURKISH_TURKEY,
209
- Locales.TATAR,
210
- Locales.TATAR_RUSSIA,
211
- Locales.TSOGA,
212
- Locales.UKRAINIAN,
213
- Locales.UKRAINIAN_UKRAINE,
214
- Locales.URDU,
215
- Locales.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN,
216
- Locales.UZBEK_LATIN,
217
- Locales.UZBEK_LATIN_UZBEKISTAN,
218
- Locales.VIETNAMESE,
219
- Locales.VIETNAMESE_VIET_NAM,
220
- Locales.XHOSA,
221
- Locales.XHOSA_SOUTH_AFRICA,
222
- Locales.CHINESE,
223
- Locales.CHINESE_SIMPLIFIED,
224
- Locales.CHINESE_HONG_KONG,
225
- Locales.CHINESE_MACAU,
226
- Locales.CHINESE_SINGAPORE,
227
- Locales.CHINESE_TRADITIONAL,
228
- Locales.ZULU_SOUTH_AFRICA,
229
- ];
@@ -1,66 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { NodeType } from '../../../types/index';
3
-
4
- type Positif = number | `${number}`;
5
- type Negatif = `-${number}`;
6
- type Numbers = Positif | Negatif;
7
-
8
- type Equal = Numbers;
9
- type EqualString = `=${Numbers}`;
10
- type Superior = `>${Numbers}`;
11
- type SuperiorOrEqual = `>=${Numbers}`;
12
- type Inferior = `<${Numbers}`;
13
- type InferiorOrEqual = `<=${Numbers}`;
14
-
15
- export type EnterFormat =
16
- | Equal
17
- | EqualString
18
- | Superior
19
- | SuperiorOrEqual
20
- | Inferior
21
- | InferiorOrEqual;
22
-
23
- export type QuantityContent<Content> = Record<EnterFormat, Content>;
24
-
25
- export type EnumerationContent<Content> = Partial<QuantityContent<Content>> & {
26
- nodeType: NodeType.Enumeration;
27
- };
28
-
29
- /**
30
- * Function intended to be used to build intlayer dictionaries.
31
- *
32
- * Allow to pick a content based on a quantity.
33
- *
34
- * Usage:
35
- *
36
- * ```ts
37
- * const content = enu({
38
- * '<=-2.3': 'You have less than -2.3',
39
- * '<1': 'You have less than one',
40
- * '2': 'You have two',
41
- * '>=3': 'You have three or more',
42
- * });
43
- * ```
44
- *
45
- * The order of the keys will define the priority of the content.
46
- *
47
- */
48
- const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
49
- if (typeof content === 'string') {
50
- const result: EnumerationContent<Content> = {
51
- nodeType: NodeType.Enumeration,
52
- 1: content,
53
- };
54
-
55
- return result;
56
- }
57
-
58
- const result: EnumerationContent<Content> = {
59
- nodeType: NodeType.Enumeration,
60
- ...content,
61
- };
62
-
63
- return result;
64
- };
65
-
66
- export { enumeration as enu };
@@ -1,64 +0,0 @@
1
- import type { EnterFormat, QuantityContent } from './enumeration';
2
-
3
- /**
4
- * Find the matching condition for a quantity.
5
- *
6
- * Usage:
7
- *
8
- * ```ts
9
- * const key = findMatchingCondition({
10
- * '<=-2.3': 'You have less than -2.3',
11
- * '<1': 'You have less than one',
12
- * '2': 'You have two',
13
- * '>=3': 'You have three or more',
14
- * }, 2);
15
- * // '2'
16
- * ```
17
- *
18
- * The order of the keys will define the priority of the content.
19
- *
20
- * ```ts
21
- * const key = findMatchingCondition({
22
- * '<4': 'You have less than four',
23
- * '2': 'You have two',
24
- * }, 2);
25
- * // '<4'
26
- * ```
27
- *
28
- * If no keys match, the default key is '1'.
29
- */
30
- export const findMatchingCondition = <Content>(
31
- enumerationContent: QuantityContent<Content>,
32
- quantity: number
33
- ): EnterFormat => {
34
- const numericKeys = Object.keys(enumerationContent);
35
-
36
- for (const key of numericKeys) {
37
- const isEqual =
38
- (!key.startsWith('>') &&
39
- !key.startsWith('<') &&
40
- !key.startsWith('=') &&
41
- parseFloat(key) === quantity) ||
42
- (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);
43
- const isSuperior =
44
- key.startsWith('>') && quantity > parseFloat(key.slice(1));
45
- const isSuperiorOrEqual =
46
- key.startsWith('>=') && quantity >= parseFloat(key.slice(2));
47
- const isInferior =
48
- key.startsWith('<') && quantity < parseFloat(key.slice(1));
49
- const isInferiorOrEqual =
50
- key.startsWith('<=') && quantity <= parseFloat(key.slice(2));
51
-
52
- if (
53
- isEqual ||
54
- isSuperior ||
55
- isSuperiorOrEqual ||
56
- isInferior ||
57
- isInferiorOrEqual
58
- ) {
59
- return key as EnterFormat;
60
- }
61
- }
62
-
63
- return '1';
64
- };
@@ -1,38 +0,0 @@
1
- import { findMatchingCondition } from '../..';
2
- import type { QuantityContent } from './enumeration';
3
-
4
- /**
5
- * Allow to pick a content based on a quantity.
6
- *
7
- * Usage:
8
- *
9
- * ```ts
10
- * const content = getEnumerationContent({
11
- * '<=-2.3': 'You have less than -2.3',
12
- * '<1': 'You have less than one',
13
- * '2': 'You have two',
14
- * '>=3': 'You have three or more',
15
- * }, 2);
16
- * // 'You have two'
17
- * ```
18
- *
19
- * The order of the keys will define the priority of the content.
20
- *
21
- * ```ts
22
- * const content = getEnumerationContent({
23
- * '<4': 'You have less than four',
24
- * '2': 'You have two',
25
- * }, 2);
26
- * // 'You have less than four'
27
- * ```
28
- *
29
- */
30
- export const getEnumerationContent = <Content>(
31
- enumerationContent: QuantityContent<Content>,
32
- quantity: number
33
- ): Content => {
34
- const key = findMatchingCondition<Content>(enumerationContent, quantity);
35
-
36
- // Default or error handling if no keys match
37
- return enumerationContent[key];
38
- };
@@ -1,3 +0,0 @@
1
- export * from './enumeration';
2
- export * from './getEnumerationContent';
3
- export * from './findMatchingCondition';
@@ -1,2 +0,0 @@
1
- export * from './translation/index';
2
- export * from './enumeration/index';
@@ -1,33 +0,0 @@
1
- import { type Locales, getConfiguration } from '@intlayer/config/client';
2
- import type { CustomizableLanguageContent } from './types';
3
-
4
- const defaultLocale = getConfiguration().internationalization.defaultLocale;
5
-
6
- type GetTranslationContent = <Content = string>(
7
- languageContent: CustomizableLanguageContent<Content>,
8
- locale: Locales
9
- ) => Content;
10
-
11
- /**
12
- *
13
- * Allow to pick a content based on a locale.
14
- * If not locale found, it will return the content related to the default locale.
15
- *
16
- * Usage:
17
- *
18
- * ```ts
19
- * const content = getTranslationContent({
20
- * en: 'Hello',
21
- * fr: 'Bonjour',
22
- * }, 'fr');
23
- * // 'Bonjour'
24
- * ```
25
- *
26
- * Using TypeScript:
27
- * - this function will require each locale to be defined if defined in the project configuration.
28
- * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
29
- */
30
- export const getTranslationContent: GetTranslationContent = <Content = string>(
31
- languageContent: CustomizableLanguageContent<Content>,
32
- locale: Locales
33
- ) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
@@ -1,3 +0,0 @@
1
- export * from './translation';
2
- export * from './getTranslationContent';
3
- export * from './types';
@@ -1,49 +0,0 @@
1
- import { getConfiguration } from '@intlayer/config/client';
2
- import { NodeType } from '../../../types/index';
3
- import type { CustomizableLanguageContent, TranslationContent } from './types';
4
-
5
- /**
6
- *
7
- * Function intended to be used to build intlayer dictionaries.
8
- *
9
- * Get the content of a translation based on the locale.
10
- *
11
- * Usage:
12
- *
13
- * ```ts
14
- * translation<string>({
15
- * "en": "Hello",
16
- * "fr": "Bonjour",
17
- * // ... any other available locale
18
- * })
19
- * ```
20
- *
21
- * Using TypeScript:
22
- * - this function require each locale to be defined if defined in the project configuration.
23
- * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
24
- */
25
- const translation = <Content = string>(
26
- content?: CustomizableLanguageContent<Content>
27
- ) => {
28
- const {
29
- internationalization: { defaultLocale },
30
- } = getConfiguration();
31
-
32
- if (typeof content === 'string') {
33
- const result: TranslationContent<Content> = {
34
- nodeType: NodeType.Translation,
35
- [defaultLocale]: content,
36
- } as TranslationContent<Content>;
37
-
38
- return result;
39
- }
40
-
41
- const result: TranslationContent<Content> = {
42
- nodeType: NodeType.Translation,
43
- ...(content as unknown as object),
44
- } as TranslationContent<Content>;
45
-
46
- return result;
47
- };
48
-
49
- export { translation as t };
@@ -1,71 +0,0 @@
1
- import type { LocalesValues } from '@intlayer/config/client';
2
- // @ts-expect-error intlayer declared for module augmentation
3
- import type { IConfigLocales } from 'intlayer';
4
- import type { NodeType } from '../../../types';
5
- import type { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo';
6
-
7
- /**
8
- * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...
9
- * If not, it will return never
10
- */
11
- export type ConfigLocales = keyof IConfigLocales<unknown>;
12
-
13
- /**
14
- * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...
15
- * If not, it will return all available locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...
16
- */
17
- export type CustomLocales = ConfigLocales extends never
18
- ? LocalesValues
19
- : ConfigLocales;
20
-
21
- /**
22
- * Record of locales and content
23
- *
24
- * const myVar1: LanguageContent<string> = {
25
- * "en": "",
26
- * "fr": ""
27
- * }
28
- *
29
- * const myVar2: LanguageContent<{age: number, name: string}> = {
30
- * "en": {age: 1, name: "test"},
31
- * "fr": {age: 1, name: "test"}
32
- * }
33
- */
34
- export type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;
35
-
36
- /**
37
- * Valid
38
- * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {
39
- * "en": "test",
40
- * "fr": "test"
41
- * }
42
- *
43
- * const test: CustomizableLanguageContent<number> = {
44
- * "fr": 1,
45
- * "en": 1,
46
- * ... any other available locale
47
- * }
48
- *
49
- * Invalid
50
- *
51
- * const test: CustomizableLanguageContent<string> = {
52
- * "en": "test",
53
- * "fr": "test",
54
- * "sss": "test" // Does not exist in Locales
55
- * }
56
- *
57
- * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {
58
- * "fr": "test"
59
- * // Locales.ENGLISH is missing
60
- * }
61
- *
62
- */
63
- export type CustomizableLanguageContent<Content = string> =
64
- ConfigLocales extends never
65
- ? LanguageContent<Content>
66
- : IConfigLocales<Content>;
67
-
68
- export type TranslationContent<Content> = LanguageContent<Content> &
69
- NoteStackTraceInfo & {
70
- nodeType: NodeType.Translation;
71
- };
@@ -1 +0,0 @@
1
- export * from './content_transformers/index';
@@ -1,33 +0,0 @@
1
- import type {
2
- EnumerationContent,
3
- TranslationContent,
4
- } from '../transpiler/index';
5
-
6
- export type TypedNode =
7
- | TranslationContent<unknown>
8
- | EnumerationContent<unknown>;
9
-
10
- export type ContentValue =
11
- | string
12
- | {
13
- [key: string]: ContentValue;
14
- }
15
- | (() => ContentValue)
16
- | Promise<ContentValue>
17
- | TypedNode;
18
-
19
- export type Content = Record<string, ContentValue | undefined>;
20
-
21
- export type FlatContentValue =
22
- | string
23
- | {
24
- [key: string]: FlatContentValue;
25
- }
26
- | TypedNode;
27
-
28
- export type FlatContent = Record<string, FlatContentValue | undefined>;
29
-
30
- export type ContentModule = Content & {
31
- id: string;
32
- filePath?: string;
33
- };
@@ -1,14 +0,0 @@
1
- export type {
2
- ContentValue,
3
- Content,
4
- FlatContentValue,
5
- FlatContent,
6
- TypedNode,
7
- ContentModule,
8
- } from './contentModule';
9
- export { NodeType } from './nodeType';
10
- export type {
11
- KeyPath,
12
- ObjectExpressionNode,
13
- TranslationOrEnumerationNode,
14
- } from './keyPath';
@@ -1,13 +0,0 @@
1
- import type { NodeType } from './nodeType';
2
-
3
- export type ObjectExpressionNode = {
4
- type: 'ObjectExpression';
5
- key: string;
6
- };
7
-
8
- export type TranslationOrEnumerationNode = {
9
- type: NodeType;
10
- key: string;
11
- };
12
-
13
- export type KeyPath = ObjectExpressionNode | TranslationOrEnumerationNode;
@@ -1,4 +0,0 @@
1
- export enum NodeType {
2
- Translation = 'translation',
3
- Enumeration = 'enumeration',
4
- }
@@ -1,39 +0,0 @@
1
- export type NoteStackTraceInfo = {
2
- file?: string;
3
- line?: string;
4
- column?: string;
5
- };
6
-
7
- /**
8
- * Get the file path, line number, and column number of the caller of this function
9
- * Return an object containing file, line, and column numbers
10
- */
11
- export const getStackTraceInfo = (): NoteStackTraceInfo => {
12
- // Create a new Error object to capture the stack trace
13
- const err = new Error();
14
- const stack = err.stack ?? '';
15
-
16
- // Split the stack trace into lines and find the line where this function was called
17
- // Adjust the line index as necessary based on how your environment's stack trace format
18
- const stackLines = stack.split('\n');
19
- const callerLine = stackLines[2] ?? ''; // Adjust the index 2 if needed
20
-
21
- // Extract file path, line number, and column number using a regular expression
22
- // This regex pattern might need adjustments based on your environment
23
- const match = callerLine.match(/at\s[^(:]+\([^:]+:(\d+):(\d+)\)?/);
24
-
25
- // const file = match?.[1];
26
- const line = match?.[1];
27
- const column = match?.[2];
28
-
29
- if (match) {
30
- return {
31
- // file,
32
- line,
33
- column,
34
- };
35
- }
36
-
37
- // Return empty object if parsing fails
38
- return {};
39
- };