@intlayer/core 1.2.1 → 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 (101) hide show
  1. package/dist/cjs/index.cjs +5 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.ts +6 -2
  4. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +0 -4
  5. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
  6. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +2 -3
  7. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs +42 -0
  8. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs.map +1 -0
  9. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.d.ts +33 -0
  10. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs +3 -12
  11. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
  12. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +0 -1
  13. package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs +3 -1
  14. package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs.map +1 -1
  15. package/dist/cjs/transpiler/content_transformers/enumeration/index.d.ts +2 -2
  16. package/dist/cjs/transpiler/content_transformers/index.d.ts +3 -3
  17. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +0 -1
  18. package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +1 -2
  19. package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +0 -4
  20. package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
  21. package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +2 -3
  22. package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -1
  23. package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +3 -5
  24. package/dist/cjs/transpiler/index.d.ts +3 -3
  25. package/dist/cjs/types/declarationContent.cjs +17 -0
  26. package/dist/cjs/types/declarationContent.cjs.map +1 -0
  27. package/dist/cjs/types/declarationContent.d.ts +27 -0
  28. package/dist/cjs/types/{contentModule.cjs → dictionary.cjs} +3 -3
  29. package/dist/cjs/types/dictionary.cjs.map +1 -0
  30. package/dist/cjs/types/dictionary.d.ts +17 -0
  31. package/dist/cjs/types/index.cjs.map +1 -1
  32. package/dist/cjs/types/index.d.ts +4 -2
  33. package/dist/cjs/types/keyPath.cjs +17 -0
  34. package/dist/cjs/types/keyPath.cjs.map +1 -0
  35. package/dist/cjs/types/keyPath.d.ts +17 -0
  36. package/dist/cjs/utils/{getStackTraceInfo.cjs → isSameKeyPath.cjs} +9 -23
  37. package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -0
  38. package/dist/cjs/utils/isSameKeyPath.d.ts +6 -0
  39. package/dist/esm/index.d.mts +6 -2
  40. package/dist/esm/index.mjs +4 -0
  41. package/dist/esm/index.mjs.map +1 -1
  42. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +2 -3
  43. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +0 -6
  44. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
  45. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.d.mts +33 -0
  46. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs +18 -0
  47. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs.map +1 -0
  48. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +0 -1
  49. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs +3 -12
  50. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
  51. package/dist/esm/transpiler/content_transformers/enumeration/index.d.mts +2 -2
  52. package/dist/esm/transpiler/content_transformers/enumeration/index.mjs +1 -0
  53. package/dist/esm/transpiler/content_transformers/enumeration/index.mjs.map +1 -1
  54. package/dist/esm/transpiler/content_transformers/index.d.mts +3 -3
  55. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +0 -1
  56. package/dist/esm/transpiler/content_transformers/translation/index.d.mts +1 -2
  57. package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +2 -3
  58. package/dist/esm/transpiler/content_transformers/translation/translation.mjs +0 -4
  59. package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
  60. package/dist/esm/transpiler/content_transformers/translation/types.d.mts +3 -5
  61. package/dist/esm/transpiler/index.d.mts +3 -3
  62. package/dist/esm/types/declarationContent.d.mts +27 -0
  63. package/dist/esm/types/declarationContent.mjs +1 -0
  64. package/dist/esm/types/dictionary.d.mts +17 -0
  65. package/dist/esm/types/dictionary.mjs +1 -0
  66. package/dist/esm/types/dictionary.mjs.map +1 -0
  67. package/dist/esm/types/index.d.mts +4 -2
  68. package/dist/esm/types/index.mjs.map +1 -1
  69. package/dist/esm/types/keyPath.d.mts +17 -0
  70. package/dist/esm/types/keyPath.mjs +1 -0
  71. package/dist/esm/types/keyPath.mjs.map +1 -0
  72. package/dist/esm/utils/isSameKeyPath.d.mts +6 -0
  73. package/dist/esm/utils/isSameKeyPath.mjs +7 -0
  74. package/dist/esm/utils/isSameKeyPath.mjs.map +1 -0
  75. package/package.json +2 -4
  76. package/src/index.ts +10 -1
  77. package/dist/cjs/types/contentModule.cjs.map +0 -1
  78. package/dist/cjs/types/contentModule.d.ts +0 -21
  79. package/dist/cjs/utils/getStackTraceInfo.cjs.map +0 -1
  80. package/dist/cjs/utils/getStackTraceInfo.d.ts +0 -12
  81. package/dist/esm/types/contentModule.d.mts +0 -21
  82. package/dist/esm/types/contentModule.mjs +0 -1
  83. package/dist/esm/utils/getStackTraceInfo.d.mts +0 -12
  84. package/dist/esm/utils/getStackTraceInfo.mjs +0 -21
  85. package/dist/esm/utils/getStackTraceInfo.mjs.map +0 -1
  86. package/src/getLocaleName.ts +0 -463
  87. package/src/localeList.ts +0 -229
  88. package/src/transpiler/content_transformers/enumeration/enumeration.ts +0 -75
  89. package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +0 -66
  90. package/src/transpiler/content_transformers/enumeration/index.ts +0 -2
  91. package/src/transpiler/content_transformers/index.ts +0 -2
  92. package/src/transpiler/content_transformers/translation/getTranslationContent.ts +0 -33
  93. package/src/transpiler/content_transformers/translation/index.ts +0 -3
  94. package/src/transpiler/content_transformers/translation/translation.ts +0 -54
  95. package/src/transpiler/content_transformers/translation/types.ts +0 -72
  96. package/src/transpiler/index.ts +0 -1
  97. package/src/types/contentModule.ts +0 -32
  98. package/src/types/index.ts +0 -9
  99. package/src/types/nodeType.ts +0 -4
  100. package/src/utils/getStackTraceInfo.ts +0 -39
  101. /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,75 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { NodeType } from '../../../types/index';
3
- import {
4
- getStackTraceInfo,
5
- type NoteStackTraceInfo,
6
- } from '../../../utils/getStackTraceInfo';
7
-
8
- type Positif = number | `${number}`;
9
- type Negatif = `-${number}`;
10
- type Numbers = Positif | Negatif;
11
-
12
- type Equal = Numbers;
13
- type EqualString = `=${Numbers}`;
14
- type Superior = `>${Numbers}`;
15
- type SuperiorOrEqual = `>=${Numbers}`;
16
- type Inferior = `<${Numbers}`;
17
- type InferiorOrEqual = `<=${Numbers}`;
18
-
19
- type EnterFormat =
20
- | Equal
21
- | EqualString
22
- | Superior
23
- | SuperiorOrEqual
24
- | Inferior
25
- | InferiorOrEqual;
26
-
27
- export type QuantityContent<Content> = Record<EnterFormat, Content>;
28
-
29
- export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
30
- NoteStackTraceInfo & {
31
- nodeType: NodeType.Enumeration;
32
- };
33
-
34
- /**
35
- * Function intended to be used to build intlayer dictionaries.
36
- *
37
- * Allow to pick a content based on a quantity.
38
- *
39
- * Usage:
40
- *
41
- * ```ts
42
- * const content = enu({
43
- * '<=-2.3': 'You have less than -2.3',
44
- * '<1': 'You have less than one',
45
- * '2': 'You have two',
46
- * '>=3': 'You have three or more',
47
- * });
48
- * ```
49
- *
50
- * The order of the keys will define the priority of the content.
51
- *
52
- */
53
- const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
54
- const stackTraceInfo = getStackTraceInfo();
55
-
56
- if (typeof content === 'string') {
57
- const result: EnumerationContent<Content> = {
58
- nodeType: NodeType.Enumeration,
59
- ...stackTraceInfo,
60
- 1: content,
61
- };
62
-
63
- return result;
64
- }
65
-
66
- const result: EnumerationContent<Content> = {
67
- nodeType: NodeType.Enumeration,
68
- ...stackTraceInfo,
69
- ...content,
70
- };
71
-
72
- return result;
73
- };
74
-
75
- export { enumeration as enu };
@@ -1,66 +0,0 @@
1
- import type { QuantityContent } from './enumeration';
2
-
3
- type Key = keyof QuantityContent<string>;
4
-
5
- /**
6
- * Allow to pick a content based on a quantity.
7
- *
8
- * Usage:
9
- *
10
- * ```ts
11
- * const content = getEnumerationContent({
12
- * '<=-2.3': 'You have less than -2.3',
13
- * '<1': 'You have less than one',
14
- * '2': 'You have two',
15
- * '>=3': 'You have three or more',
16
- * }, 2);
17
- * // 'You have two'
18
- * ```
19
- *
20
- * The order of the keys will define the priority of the content.
21
- *
22
- * ```ts
23
- * const content = getEnumerationContent({
24
- * '<4': 'You have less than four',
25
- * '2': 'You have two',
26
- * }, 2);
27
- * // 'You have less than four'
28
- * ```
29
- *
30
- */
31
- export const getEnumerationContent = <Content>(
32
- enumerationContent: QuantityContent<Content>,
33
- quantity: number
34
- ): Content => {
35
- const numericKeys = Object.keys(enumerationContent);
36
-
37
- for (const key of numericKeys) {
38
- const isEqual =
39
- (!key.startsWith('>') &&
40
- !key.startsWith('<') &&
41
- !key.startsWith('=') &&
42
- parseFloat(key) === quantity) ||
43
- (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);
44
- const isSuperior =
45
- key.startsWith('>') && quantity > parseFloat(key.slice(1));
46
- const isSuperiorOrEqual =
47
- key.startsWith('>=') && quantity >= parseFloat(key.slice(2));
48
- const isInferior =
49
- key.startsWith('<') && quantity < parseFloat(key.slice(1));
50
- const isInferiorOrEqual =
51
- key.startsWith('<=') && quantity <= parseFloat(key.slice(2));
52
-
53
- if (
54
- isEqual ||
55
- isSuperior ||
56
- isSuperiorOrEqual ||
57
- isInferior ||
58
- isInferiorOrEqual
59
- ) {
60
- return enumerationContent[key as Key];
61
- }
62
- }
63
-
64
- // Default or error handling if no keys match
65
- return enumerationContent['1'];
66
- };
@@ -1,2 +0,0 @@
1
- export * from './enumeration';
2
- export * from './getEnumerationContent';
@@ -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,54 +0,0 @@
1
- import { getConfiguration } from '@intlayer/config/client';
2
- import { NodeType } from '../../../types/index';
3
- import { getStackTraceInfo } from '../../../utils/getStackTraceInfo';
4
- import type { CustomizableLanguageContent, TranslationContent } from './types';
5
-
6
- /**
7
- *
8
- * Function intended to be used to build intlayer dictionaries.
9
- *
10
- * Get the content of a translation based on the locale.
11
- *
12
- * Usage:
13
- *
14
- * ```ts
15
- * translation<string>({
16
- * "en": "Hello",
17
- * "fr": "Bonjour",
18
- * // ... any other available locale
19
- * })
20
- * ```
21
- *
22
- * Using TypeScript:
23
- * - this function require each locale to be defined if defined in the project configuration.
24
- * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
25
- */
26
- const translation = <Content = string>(
27
- content?: CustomizableLanguageContent<Content>
28
- ) => {
29
- const {
30
- internationalization: { defaultLocale },
31
- } = getConfiguration();
32
-
33
- const stackTraceInfo = getStackTraceInfo();
34
-
35
- if (typeof content === 'string') {
36
- const result: TranslationContent<Content> = {
37
- nodeType: NodeType.Translation,
38
- ...stackTraceInfo,
39
- [defaultLocale]: content,
40
- } as TranslationContent<Content>;
41
-
42
- return result;
43
- }
44
-
45
- const result: TranslationContent<Content> = {
46
- nodeType: NodeType.Translation,
47
- ...stackTraceInfo,
48
- ...(content as unknown as object),
49
- } as TranslationContent<Content>;
50
-
51
- return result;
52
- };
53
-
54
- export { translation as t };
@@ -1,72 +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
- export type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;
36
-
37
- /**
38
- * Valid
39
- * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {
40
- * "en": "test",
41
- * "fr": "test"
42
- * }
43
- *
44
- * const test: CustomizableLanguageContent<number> = {
45
- * "fr": 1,
46
- * "en": 1,
47
- * ... any other available locale
48
- * }
49
- *
50
- * Invalid
51
- *
52
- * const test: CustomizableLanguageContent<string> = {
53
- * "en": "test",
54
- * "fr": "test",
55
- * "sss": "test" // Does not exist in Locales
56
- * }
57
- *
58
- * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {
59
- * "fr": "test"
60
- * // Locales.ENGLISH is missing
61
- * }
62
- *
63
- */
64
- export type CustomizableLanguageContent<Content = string> =
65
- ConfigLocales extends never
66
- ? LanguageContent<Content>
67
- : ConfigLanguageContent<Content>;
68
-
69
- export type TranslationContent<Content> = LanguageContent<Content> &
70
- NoteStackTraceInfo & {
71
- nodeType: NodeType.Translation;
72
- };
@@ -1 +0,0 @@
1
- export * from './content_transformers/index';
@@ -1,32 +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
- };
@@ -1,9 +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';
@@ -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
- };