@intlayer/core 1.0.0 → 1.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 (88) hide show
  1. package/dist/cjs/getLocaleName.cjs +8 -13
  2. package/dist/cjs/getLocaleName.d.ts +1 -1
  3. package/dist/cjs/index.cjs +20 -27
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/index.d.ts +12 -25
  6. package/dist/cjs/localeList.cjs +9 -14
  7. package/dist/cjs/localeList.d.ts +1 -1
  8. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +12 -17
  9. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +6 -15
  10. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs +14 -34
  11. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +4 -7
  12. package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs +11 -23
  13. package/dist/cjs/transpiler/content_transformers/enumeration/index.d.ts +4 -4
  14. package/dist/cjs/transpiler/content_transformers/index.cjs +11 -27
  15. package/dist/cjs/transpiler/content_transformers/index.d.ts +9 -15
  16. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs +9 -15
  17. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs.map +1 -1
  18. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +7 -8
  19. package/dist/cjs/transpiler/content_transformers/translation/index.cjs +13 -23
  20. package/dist/cjs/transpiler/content_transformers/translation/index.cjs.map +1 -1
  21. package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +7 -5
  22. package/dist/cjs/transpiler/content_transformers/translation/{translations.cjs → translation.cjs} +17 -22
  23. package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -0
  24. package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +30 -0
  25. package/dist/cjs/transpiler/content_transformers/translation/types.cjs +17 -0
  26. package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -0
  27. package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +63 -0
  28. package/dist/cjs/transpiler/index.cjs +9 -22
  29. package/dist/cjs/transpiler/index.cjs.map +1 -1
  30. package/dist/cjs/transpiler/index.d.ts +9 -13
  31. package/dist/cjs/types/contentModule.cjs +4 -8
  32. package/dist/cjs/types/contentModule.d.ts +14 -28
  33. package/dist/cjs/types/index.cjs +9 -14
  34. package/dist/cjs/types/index.d.ts +7 -13
  35. package/dist/cjs/types/nodeType.cjs +8 -13
  36. package/dist/cjs/types/nodeType.d.ts +2 -2
  37. package/dist/cjs/utils/getStackTraceInfo.cjs +9 -14
  38. package/dist/cjs/utils/getStackTraceInfo.d.ts +3 -3
  39. package/dist/esm/getLocaleName.d.mts +1 -1
  40. package/dist/esm/getLocaleName.mjs +4 -2
  41. package/dist/esm/index.d.mts +12 -25
  42. package/dist/esm/index.mjs +7 -7
  43. package/dist/esm/index.mjs.map +1 -1
  44. package/dist/esm/localeList.d.mts +1 -1
  45. package/dist/esm/localeList.mjs +5 -3
  46. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +6 -15
  47. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +10 -6
  48. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +4 -7
  49. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs +10 -23
  50. package/dist/esm/transpiler/content_transformers/enumeration/index.d.mts +4 -4
  51. package/dist/esm/transpiler/content_transformers/enumeration/index.mjs +3 -3
  52. package/dist/esm/transpiler/content_transformers/index.d.mts +9 -15
  53. package/dist/esm/transpiler/content_transformers/index.mjs +3 -3
  54. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +7 -8
  55. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs +8 -5
  56. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs.map +1 -1
  57. package/dist/esm/transpiler/content_transformers/translation/index.d.mts +7 -5
  58. package/dist/esm/transpiler/content_transformers/translation/index.mjs +4 -3
  59. package/dist/esm/transpiler/content_transformers/translation/index.mjs.map +1 -1
  60. package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +30 -0
  61. package/dist/esm/transpiler/content_transformers/translation/{translations.mjs → translation.mjs} +10 -7
  62. package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -0
  63. package/dist/esm/transpiler/content_transformers/translation/types.d.mts +63 -0
  64. package/dist/esm/transpiler/content_transformers/translation/types.mjs +1 -0
  65. package/dist/esm/transpiler/content_transformers/translation/types.mjs.map +1 -0
  66. package/dist/esm/transpiler/index.d.mts +9 -13
  67. package/dist/esm/transpiler/index.mjs +2 -3
  68. package/dist/esm/transpiler/index.mjs.map +1 -1
  69. package/dist/esm/types/contentModule.d.mts +14 -28
  70. package/dist/esm/types/contentModule.mjs +1 -1
  71. package/dist/esm/types/index.d.mts +7 -13
  72. package/dist/esm/types/index.mjs +5 -3
  73. package/dist/esm/types/nodeType.d.mts +2 -2
  74. package/dist/esm/types/nodeType.mjs +4 -2
  75. package/dist/esm/utils/getStackTraceInfo.d.mts +3 -3
  76. package/dist/esm/utils/getStackTraceInfo.mjs +5 -3
  77. package/package.json +8 -5
  78. package/src/index.ts +2 -0
  79. package/src/transpiler/content_transformers/translation/getTranslationContent.ts +9 -5
  80. package/src/transpiler/content_transformers/translation/index.ts +2 -1
  81. package/src/transpiler/content_transformers/translation/translation.ts +53 -0
  82. package/src/transpiler/content_transformers/translation/types.ts +72 -0
  83. package/src/transpiler/index.ts +1 -7
  84. package/dist/cjs/transpiler/content_transformers/translation/translations.cjs.map +0 -1
  85. package/dist/cjs/transpiler/content_transformers/translation/translations.d.ts +0 -17
  86. package/dist/esm/transpiler/content_transformers/translation/translations.d.mts +0 -17
  87. package/dist/esm/transpiler/content_transformers/translation/translations.mjs.map +0 -1
  88. package/src/transpiler/content_transformers/translation/translations.ts +0 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "description": "IntLayer - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
6
6
  "keywords": [
@@ -24,7 +24,10 @@
24
24
  "url": "git+https://github.com/aypineau/intlayer.git"
25
25
  },
26
26
  "license": "MIT",
27
- "author": "Aymeric PINEAU (https://github.com/aypineau)",
27
+ "author": {
28
+ "name": "Aymeric PINEAU",
29
+ "url": "https://github.com/aypineau"
30
+ },
28
31
  "exports": {
29
32
  ".": {
30
33
  "types": "./dist/esm/index.d.mts",
@@ -47,7 +50,7 @@
47
50
  "./package.json"
48
51
  ],
49
52
  "dependencies": {
50
- "@intlayer/config": "^1.0.0"
53
+ "@intlayer/config": "^1.0.1"
51
54
  },
52
55
  "devDependencies": {
53
56
  "@types/node": "^20.11.30",
@@ -56,8 +59,8 @@
56
59
  "rimraf": "5.0.5",
57
60
  "tsup": "^8.0.2",
58
61
  "typescript": "^5.4.3",
59
- "@utils/ts-config": "^1.0.0",
60
- "@utils/eslint-config": "^1.0.0"
62
+ "@utils/eslint-config": "^1.0.1",
63
+ "@utils/ts-config": "^1.0.1"
61
64
  },
62
65
  "peerDependencies": {
63
66
  "@types/react": "^18.2.78",
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export type {
2
+ CustomizableLanguageContent,
2
3
  LanguageContent,
3
4
  TranslationContent,
4
5
  EnumerationContent,
5
6
  QuantityContent,
7
+ CustomLocales as Locales,
6
8
  } from './transpiler/content_transformers/index';
7
9
  export {
8
10
  t,
@@ -2,12 +2,16 @@ import {
2
2
  type Locales,
3
3
  intlayerIntlConfiguration,
4
4
  } from '@intlayer/config/client';
5
- import type { LanguageContent } from './translations';
5
+ import type { CustomizableLanguageContent } from './types';
6
6
 
7
7
  const defaultLocale = intlayerIntlConfiguration.defaultLocale;
8
8
 
9
- export const getTranslationContent = <Content>(
10
- languageContent: LanguageContent<Content>,
9
+ type GetTranslationContent = <Content = string>(
10
+ languageContent: CustomizableLanguageContent<Content>,
11
11
  locale: Locales
12
- ): Content =>
13
- languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
12
+ ) => Content;
13
+
14
+ export const getTranslationContent: GetTranslationContent = <Content = string>(
15
+ languageContent: CustomizableLanguageContent<Content>,
16
+ locale: Locales
17
+ ) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
@@ -1,2 +1,3 @@
1
- export * from './translations';
1
+ export * from './translation';
2
2
  export * from './getTranslationContent';
3
+ export * from './types';
@@ -0,0 +1,53 @@
1
+ import { intlayerConfiguration } 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
+ const { defaultLocale } = intlayerConfiguration.internationalization;
7
+
8
+ /**
9
+ * Transpile multilingual dictionary content
10
+ *
11
+ * Usage
12
+ *
13
+ * translation<string>({
14
+ * "en": "test",
15
+ * "fr": "test",
16
+ * // ... any other available locale
17
+ * })
18
+ *
19
+ * translation<number, Locales.ENGLISH>({
20
+ * "en": 1
21
+ * })
22
+ *
23
+ * translation<string, Locales.ENGLISH | Locales.FRENCH>({
24
+ * "fr": "test",
25
+ * "en": "test"
26
+ * })
27
+ *
28
+ */
29
+ const translation = <Content = string>(
30
+ content?: CustomizableLanguageContent<Content>
31
+ ) => {
32
+ const stackTraceInfo = getStackTraceInfo();
33
+
34
+ if (typeof content === 'string') {
35
+ const result: TranslationContent<Content> = {
36
+ nodeType: NodeType.Translation,
37
+ ...stackTraceInfo,
38
+ [defaultLocale]: content,
39
+ } as TranslationContent<Content>;
40
+
41
+ return result;
42
+ }
43
+
44
+ const result: TranslationContent<Content> = {
45
+ nodeType: NodeType.Translation,
46
+ ...stackTraceInfo,
47
+ ...(content as unknown as object),
48
+ } as TranslationContent<Content>;
49
+
50
+ return result;
51
+ };
52
+
53
+ export { translation as t };
@@ -0,0 +1,72 @@
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,7 +1 @@
1
- export type {
2
- LanguageContent,
3
- TranslationContent,
4
- EnumerationContent,
5
- QuantityContent,
6
- } from './content_transformers/index';
7
- export { t, enu } from './content_transformers/index';
1
+ export * from './content_transformers/index';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translations.ts"],"sourcesContent":["import { type Locales, intlayerConfiguration } from '@intlayer/config/client';\nimport type { ReactNode } from 'react';\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\nexport type LanguageContent<Content> = Record<Locales, Content>;\n\nexport type TranslationContent<Content> = Partial<LanguageContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Translation;\n };\n\n/**\n * Create a JSON with the content and the stack trace information\n */\nconst translations = <Content>(\n content?: Partial<LanguageContent<Content>> | string\n) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n [intlayerConfiguration.internationalization.defaultLocale]: content,\n };\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { translations as t };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoD;AAEpD,mBAAyB;AACzB,+BAGO;AAYP,MAAM,eAAe,CACnB,YACG;AACH,QAAM,qBAAiB,4CAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,GAAG;AAAA,MACH,CAAC,oCAAsB,qBAAqB,aAAa,GAAG;AAAA,IAC9D;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
@@ -1,17 +0,0 @@
1
- import { Locales } from "@intlayer/config/client";
2
- import { NoteStackTraceInfo } from "../../../utils/getStackTraceInfo.js";
3
- import { NodeType } from "../../../types/nodeType.js";
4
-
5
- type LanguageContent<Content> = Record<Locales, Content>;
6
- type TranslationContent<Content> = Partial<LanguageContent<Content>> &
7
- NoteStackTraceInfo & {
8
- nodeType: NodeType.Translation;
9
- };
10
- /**
11
- * Create a JSON with the content and the stack trace information
12
- */
13
- declare const translations: <Content>(
14
- content?: Partial<LanguageContent<Content>> | string
15
- ) => TranslationContent<Content>;
16
-
17
- export { type LanguageContent, type TranslationContent, translations as t };
@@ -1,17 +0,0 @@
1
- import { Locales } from "@intlayer/config/client";
2
- import { NoteStackTraceInfo } from "../../../utils/getStackTraceInfo.mjs";
3
- import { NodeType } from "../../../types/nodeType.mjs";
4
-
5
- type LanguageContent<Content> = Record<Locales, Content>;
6
- type TranslationContent<Content> = Partial<LanguageContent<Content>> &
7
- NoteStackTraceInfo & {
8
- nodeType: NodeType.Translation;
9
- };
10
- /**
11
- * Create a JSON with the content and the stack trace information
12
- */
13
- declare const translations: <Content>(
14
- content?: Partial<LanguageContent<Content>> | string
15
- ) => TranslationContent<Content>;
16
-
17
- export { type LanguageContent, type TranslationContent, translations as t };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translations.ts"],"sourcesContent":["import { type Locales, intlayerConfiguration } from '@intlayer/config/client';\nimport type { ReactNode } from 'react';\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\nexport type LanguageContent<Content> = Record<Locales, Content>;\n\nexport type TranslationContent<Content> = Partial<LanguageContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Translation;\n };\n\n/**\n * Create a JSON with the content and the stack trace information\n */\nconst translations = <Content>(\n content?: Partial<LanguageContent<Content>> | string\n) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n [intlayerConfiguration.internationalization.defaultLocale]: content,\n };\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { translations as t };\n"],"mappings":"AAAA,SAAuB,6BAA6B;AAEpD,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;AAYP,MAAM,eAAe,CACnB,YACG;AACH,QAAM,iBAAiB,kBAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,GAAG;AAAA,MACH,CAAC,sBAAsB,qBAAqB,aAAa,GAAG;AAAA,IAC9D;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
@@ -1,42 +0,0 @@
1
- import { type Locales, intlayerConfiguration } from '@intlayer/config/client';
2
- import { NodeType } from '../../../types/index';
3
- import {
4
- getStackTraceInfo,
5
- type NoteStackTraceInfo,
6
- } from '../../../utils/getStackTraceInfo';
7
-
8
- export type LanguageContent<Content> = Record<Locales, Content>;
9
-
10
- export type TranslationContent<Content> = Partial<LanguageContent<Content>> &
11
- NoteStackTraceInfo & {
12
- nodeType: NodeType.Translation;
13
- };
14
-
15
- /**
16
- * Create a JSON with the content and the stack trace information
17
- */
18
- const translations = <Content>(
19
- content?: Partial<LanguageContent<Content>> | string
20
- ) => {
21
- const stackTraceInfo = getStackTraceInfo();
22
-
23
- if (typeof content === 'string') {
24
- const result: TranslationContent<Content> = {
25
- nodeType: NodeType.Translation,
26
- ...stackTraceInfo,
27
- [intlayerConfiguration.internationalization.defaultLocale]: content,
28
- };
29
-
30
- return result;
31
- }
32
-
33
- const result: TranslationContent<Content> = {
34
- nodeType: NodeType.Translation,
35
- ...stackTraceInfo,
36
- ...content,
37
- };
38
-
39
- return result;
40
- };
41
-
42
- export { translations as t };