@intlayer/core 1.0.0 → 1.2.0
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.
- package/dist/cjs/getLocaleName.cjs +8 -13
- package/dist/cjs/getLocaleName.d.ts +1 -1
- package/dist/cjs/index.cjs +20 -27
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +12 -25
- package/dist/cjs/localeList.cjs +9 -14
- package/dist/cjs/localeList.d.ts +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +12 -17
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +21 -16
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs +14 -34
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +27 -7
- package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs +11 -23
- package/dist/cjs/transpiler/content_transformers/enumeration/index.d.ts +4 -4
- package/dist/cjs/transpiler/content_transformers/index.cjs +11 -27
- package/dist/cjs/transpiler/content_transformers/index.d.ts +9 -15
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs +9 -15
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +25 -8
- package/dist/cjs/transpiler/content_transformers/translation/index.cjs +13 -23
- package/dist/cjs/transpiler/content_transformers/translation/index.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +7 -5
- package/dist/cjs/transpiler/content_transformers/translation/{translations.cjs → translation.cjs} +17 -22
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -0
- package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +27 -0
- package/dist/cjs/transpiler/content_transformers/translation/types.cjs +17 -0
- package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -0
- package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +63 -0
- package/dist/cjs/transpiler/index.cjs +9 -22
- package/dist/cjs/transpiler/index.cjs.map +1 -1
- package/dist/cjs/transpiler/index.d.ts +9 -13
- package/dist/cjs/types/contentModule.cjs +4 -8
- package/dist/cjs/types/contentModule.d.ts +14 -28
- package/dist/cjs/types/index.cjs +9 -14
- package/dist/cjs/types/index.d.ts +7 -13
- package/dist/cjs/types/nodeType.cjs +8 -13
- package/dist/cjs/types/nodeType.d.ts +2 -2
- package/dist/cjs/utils/getStackTraceInfo.cjs +9 -14
- package/dist/cjs/utils/getStackTraceInfo.cjs.map +1 -1
- package/dist/cjs/utils/getStackTraceInfo.d.ts +4 -4
- package/dist/esm/getLocaleName.d.mts +1 -1
- package/dist/esm/getLocaleName.mjs +4 -2
- package/dist/esm/index.d.mts +12 -25
- package/dist/esm/index.mjs +7 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/localeList.d.mts +1 -1
- package/dist/esm/localeList.mjs +5 -3
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +21 -16
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +10 -6
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +27 -7
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs +10 -23
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/index.d.mts +4 -4
- package/dist/esm/transpiler/content_transformers/enumeration/index.mjs +3 -3
- package/dist/esm/transpiler/content_transformers/index.d.mts +9 -15
- package/dist/esm/transpiler/content_transformers/index.mjs +3 -3
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +25 -8
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs +8 -5
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/index.d.mts +7 -5
- package/dist/esm/transpiler/content_transformers/translation/index.mjs +4 -3
- package/dist/esm/transpiler/content_transformers/translation/index.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +27 -0
- package/dist/esm/transpiler/content_transformers/translation/{translations.mjs → translation.mjs} +10 -7
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -0
- package/dist/esm/transpiler/content_transformers/translation/types.d.mts +63 -0
- package/dist/esm/transpiler/content_transformers/translation/types.mjs +1 -0
- package/dist/esm/transpiler/content_transformers/translation/types.mjs.map +1 -0
- package/dist/esm/transpiler/index.d.mts +9 -13
- package/dist/esm/transpiler/index.mjs +2 -3
- package/dist/esm/transpiler/index.mjs.map +1 -1
- package/dist/esm/types/contentModule.d.mts +14 -28
- package/dist/esm/types/contentModule.mjs +1 -1
- package/dist/esm/types/index.d.mts +7 -13
- package/dist/esm/types/index.mjs +5 -3
- package/dist/esm/types/nodeType.d.mts +2 -2
- package/dist/esm/types/nodeType.mjs +4 -2
- package/dist/esm/utils/getStackTraceInfo.d.mts +4 -4
- package/dist/esm/utils/getStackTraceInfo.mjs +5 -3
- package/dist/esm/utils/getStackTraceInfo.mjs.map +1 -1
- package/package.json +12 -8
- package/src/index.ts +2 -0
- package/src/transpiler/content_transformers/enumeration/enumeration.ts +15 -1
- package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +23 -0
- package/src/transpiler/content_transformers/translation/getTranslationContent.ts +27 -5
- package/src/transpiler/content_transformers/translation/index.ts +2 -1
- package/src/transpiler/content_transformers/translation/translation.ts +50 -0
- package/src/transpiler/content_transformers/translation/types.ts +72 -0
- package/src/transpiler/index.ts +1 -7
- package/src/utils/getStackTraceInfo.ts +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/translations.cjs.map +0 -1
- package/dist/cjs/transpiler/content_transformers/translation/translations.d.ts +0 -17
- package/dist/esm/transpiler/content_transformers/translation/translations.d.mts +0 -17
- package/dist/esm/transpiler/content_transformers/translation/translations.mjs.map +0 -1
- package/src/transpiler/content_transformers/translation/translations.ts +0 -42
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./content_transformers/enumeration/enumeration.mjs";
|
|
11
|
-
import "@intlayer/config/client";
|
|
12
|
-
import "../utils/getStackTraceInfo.mjs";
|
|
13
|
-
import "../types/nodeType.mjs";
|
|
1
|
+
export { t } from './content_transformers/translation/translation.mjs';
|
|
2
|
+
export { getTranslationContent } from './content_transformers/translation/getTranslationContent.mjs';
|
|
3
|
+
export { ConfigLanguageContent, ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './content_transformers/translation/types.mjs';
|
|
4
|
+
export { EnumerationContent, QuantityContent, enu } from './content_transformers/enumeration/enumeration.mjs';
|
|
5
|
+
export { getEnumerationContent } from './content_transformers/enumeration/getEnumerationContent.mjs';
|
|
6
|
+
import '@intlayer/config/client';
|
|
7
|
+
import 'intlayer';
|
|
8
|
+
import '../utils/getStackTraceInfo.mjs';
|
|
9
|
+
import '../types/nodeType.mjs';
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './content_transformers/index.mjs';
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './content_transformers/index';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
import { TranslationContent } from
|
|
2
|
-
import { EnumerationContent } from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { TranslationContent } from '../transpiler/content_transformers/translation/types.mjs';
|
|
2
|
+
import { EnumerationContent } from '../transpiler/content_transformers/enumeration/enumeration.mjs';
|
|
3
|
+
import './nodeType.mjs';
|
|
4
|
+
import '@intlayer/config/client';
|
|
5
|
+
import 'intlayer';
|
|
6
|
+
import '../utils/getStackTraceInfo.mjs';
|
|
6
7
|
|
|
7
8
|
type TypedNode = TranslationContent<unknown> | EnumerationContent<unknown>;
|
|
8
|
-
type ContentValue =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[key: string]: ContentValue;
|
|
12
|
-
}
|
|
13
|
-
| (() => ContentValue)
|
|
14
|
-
| Promise<ContentValue>
|
|
15
|
-
| TypedNode;
|
|
9
|
+
type ContentValue = string | {
|
|
10
|
+
[key: string]: ContentValue;
|
|
11
|
+
} | (() => ContentValue) | Promise<ContentValue> | TypedNode;
|
|
16
12
|
type Content = Record<string, ContentValue | undefined>;
|
|
17
|
-
type FlatContentValue =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[key: string]: FlatContentValue;
|
|
21
|
-
}
|
|
22
|
-
| TypedNode;
|
|
13
|
+
type FlatContentValue = string | {
|
|
14
|
+
[key: string]: FlatContentValue;
|
|
15
|
+
} | TypedNode;
|
|
23
16
|
type FlatContent = Record<string, FlatContentValue | undefined>;
|
|
24
17
|
type ContentModule = Content & {
|
|
25
|
-
|
|
18
|
+
id: string;
|
|
26
19
|
};
|
|
27
20
|
|
|
28
|
-
export type {
|
|
29
|
-
Content,
|
|
30
|
-
ContentModule,
|
|
31
|
-
ContentValue,
|
|
32
|
-
FlatContent,
|
|
33
|
-
FlatContentValue,
|
|
34
|
-
TypedNode,
|
|
35
|
-
};
|
|
21
|
+
export type { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
//# sourceMappingURL=contentModule.mjs.map
|
|
1
|
+
//# sourceMappingURL=contentModule.mjs.map
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./contentModule.mjs";
|
|
9
|
-
export { NodeType } from "./nodeType.mjs";
|
|
10
|
-
import "../transpiler/content_transformers/translation/translations.mjs";
|
|
11
|
-
import "@intlayer/config/client";
|
|
12
|
-
import "../utils/getStackTraceInfo.mjs";
|
|
13
|
-
import "../transpiler/content_transformers/enumeration/enumeration.mjs";
|
|
1
|
+
export { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode } from './contentModule.mjs';
|
|
2
|
+
export { NodeType } from './nodeType.mjs';
|
|
3
|
+
import '../transpiler/content_transformers/translation/types.mjs';
|
|
4
|
+
import '@intlayer/config/client';
|
|
5
|
+
import 'intlayer';
|
|
6
|
+
import '../utils/getStackTraceInfo.mjs';
|
|
7
|
+
import '../transpiler/content_transformers/enumeration/enumeration.mjs';
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
type NoteStackTraceInfo = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
file?: string;
|
|
3
|
+
line?: string;
|
|
4
|
+
column?: string;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Get the file path, line number, and column number of the caller of this function
|
|
8
|
-
*
|
|
8
|
+
* Return an object containing file, line, and column numbers
|
|
9
9
|
*/
|
|
10
10
|
declare const getStackTraceInfo: () => NoteStackTraceInfo;
|
|
11
11
|
|
|
@@ -10,10 +10,12 @@ const getStackTraceInfo = () => {
|
|
|
10
10
|
return {
|
|
11
11
|
// file,
|
|
12
12
|
line,
|
|
13
|
-
column
|
|
13
|
+
column
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
return {};
|
|
17
17
|
};
|
|
18
|
-
export {
|
|
19
|
-
|
|
18
|
+
export {
|
|
19
|
+
getStackTraceInfo
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=getStackTraceInfo.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n *
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n * Return an object containing file, line, and column numbers\n */\nexport const getStackTraceInfo = (): NoteStackTraceInfo => {\n // Create a new Error object to capture the stack trace\n const err = new Error();\n const stack = err.stack ?? '';\n\n // Split the stack trace into lines and find the line where this function was called\n // Adjust the line index as necessary based on how your environment's stack trace format\n const stackLines = stack.split('\\n');\n const callerLine = stackLines[2] ?? ''; // Adjust the index 2 if needed\n\n // Extract file path, line number, and column number using a regular expression\n // This regex pattern might need adjustments based on your environment\n const match = callerLine.match(/at\\s[^(:]+\\([^:]+:(\\d+):(\\d+)\\)?/);\n\n // const file = match?.[1];\n const line = match?.[1];\n const column = match?.[2];\n\n if (match) {\n return {\n // file,\n line,\n column,\n };\n }\n\n // Return empty object if parsing fails\n return {};\n};\n"],"mappings":"AAUO,MAAM,oBAAoB,MAA0B;AAEzD,QAAM,MAAM,IAAI,MAAM;AACtB,QAAM,QAAQ,IAAI,SAAS;AAI3B,QAAM,aAAa,MAAM,MAAM,IAAI;AACnC,QAAM,aAAa,WAAW,CAAC,KAAK;AAIpC,QAAM,QAAQ,WAAW,MAAM,kCAAkC;AAGjE,QAAM,OAAO,QAAQ,CAAC;AACtB,QAAM,SAAS,QAAQ,CAAC;AAExB,MAAI,OAAO;AACT,WAAO;AAAA;AAAA,MAEL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,SAAO,CAAC;AACV;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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":
|
|
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,17 +50,18 @@
|
|
|
47
50
|
"./package.json"
|
|
48
51
|
],
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"
|
|
53
|
+
"chokidar": "^3.6.0",
|
|
54
|
+
"@intlayer/config": "^1.2.0"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^20.
|
|
54
|
-
"@types/react": "^18.2.
|
|
57
|
+
"@types/node": "^20.12.7",
|
|
58
|
+
"@types/react": "^18.2.79",
|
|
55
59
|
"react": "^18.2.0",
|
|
56
60
|
"rimraf": "5.0.5",
|
|
57
61
|
"tsup": "^8.0.2",
|
|
58
|
-
"typescript": "^5.4.
|
|
59
|
-
"@utils/
|
|
60
|
-
"@utils/
|
|
62
|
+
"typescript": "^5.4.5",
|
|
63
|
+
"@utils/eslint-config": "^1.0.1",
|
|
64
|
+
"@utils/ts-config": "^1.0.1"
|
|
61
65
|
},
|
|
62
66
|
"peerDependencies": {
|
|
63
67
|
"@types/react": "^18.2.78",
|
package/src/index.ts
CHANGED
|
@@ -32,7 +32,21 @@ export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
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
|
+
* const content = enu({
|
|
42
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
43
|
+
* '<1': 'You have less than one',
|
|
44
|
+
* '2': 'You have two',
|
|
45
|
+
* '>=3': 'You have three or more',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* The order of the keys will define the priority of the content.
|
|
49
|
+
*
|
|
36
50
|
*/
|
|
37
51
|
const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
38
52
|
const stackTraceInfo = getStackTraceInfo();
|
|
@@ -2,6 +2,29 @@ import type { QuantityContent } from './enumeration';
|
|
|
2
2
|
|
|
3
3
|
type Key = keyof QuantityContent<string>;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Allow to pick a content based on a quantity.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
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
|
+
* },
|
|
16
|
+
* 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* const content = getEnumerationContent({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* });
|
|
25
|
+
* // 'You have less than four'
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
5
28
|
export const getEnumerationContent = <Content>(
|
|
6
29
|
enumerationContent: QuantityContent<Content>,
|
|
7
30
|
quantity: number
|
|
@@ -2,12 +2,34 @@ import {
|
|
|
2
2
|
type Locales,
|
|
3
3
|
intlayerIntlConfiguration,
|
|
4
4
|
} from '@intlayer/config/client';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CustomizableLanguageContent } from './types';
|
|
6
6
|
|
|
7
7
|
const defaultLocale = intlayerIntlConfiguration.defaultLocale;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
languageContent:
|
|
9
|
+
type GetTranslationContent = <Content = string>(
|
|
10
|
+
languageContent: CustomizableLanguageContent<Content>,
|
|
11
11
|
locale: Locales
|
|
12
|
-
)
|
|
13
|
-
|
|
12
|
+
) => Content;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* Allow to pick a content based on a locale.
|
|
17
|
+
* If not locale found, it will return the content related to the default locale.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
*
|
|
21
|
+
* const content = getTranslationContent({
|
|
22
|
+
* en: 'Hello',
|
|
23
|
+
* fr: 'Bonjour',
|
|
24
|
+
* },
|
|
25
|
+
* 'fr');
|
|
26
|
+
* // 'Bonjour'
|
|
27
|
+
*
|
|
28
|
+
* Using TypeScript:
|
|
29
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
30
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
31
|
+
*/
|
|
32
|
+
export const getTranslationContent: GetTranslationContent = <Content = string>(
|
|
33
|
+
languageContent: CustomizableLanguageContent<Content>,
|
|
34
|
+
locale: Locales
|
|
35
|
+
) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
*
|
|
10
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
11
|
+
*
|
|
12
|
+
* Get the content of a translation based on the locale.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
*
|
|
16
|
+
* translation<string>({
|
|
17
|
+
* "en": "Hello",
|
|
18
|
+
* "fr": "Bonjour",
|
|
19
|
+
* // ... any other available locale
|
|
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 stackTraceInfo = getStackTraceInfo();
|
|
30
|
+
|
|
31
|
+
if (typeof content === 'string') {
|
|
32
|
+
const result: TranslationContent<Content> = {
|
|
33
|
+
nodeType: NodeType.Translation,
|
|
34
|
+
...stackTraceInfo,
|
|
35
|
+
[defaultLocale]: content,
|
|
36
|
+
} as TranslationContent<Content>;
|
|
37
|
+
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const result: TranslationContent<Content> = {
|
|
42
|
+
nodeType: NodeType.Translation,
|
|
43
|
+
...stackTraceInfo,
|
|
44
|
+
...(content as unknown as object),
|
|
45
|
+
} as TranslationContent<Content>;
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
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
|
+
};
|
package/src/transpiler/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type NoteStackTraceInfo = {
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the file path, line number, and column number of the caller of this function
|
|
9
|
-
*
|
|
9
|
+
* Return an object containing file, line, and column numbers
|
|
10
10
|
*/
|
|
11
11
|
export const getStackTraceInfo = (): NoteStackTraceInfo => {
|
|
12
12
|
// Create a new Error object to capture the stack trace
|
|
@@ -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 };
|