@akanjs/dictionary 0.9.56 → 0.9.58-canary.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/cjs/src/base.dictionary.js +28 -45
- package/cjs/src/dictInfo.js +484 -0
- package/cjs/src/dictionary.js +5 -4
- package/cjs/src/index.js +4 -0
- package/cjs/src/locale.js +33 -0
- package/cjs/src/serverTranslator.js +1 -4
- package/cjs/src/trans.js +23 -103
- package/esm/src/base.dictionary.js +28 -45
- package/esm/src/dictInfo.js +465 -0
- package/esm/src/dictionary.js +5 -4
- package/esm/src/index.js +13 -1
- package/esm/src/locale.js +14 -0
- package/esm/src/serverTranslator.js +2 -5
- package/esm/src/trans.js +24 -104
- package/package.json +1 -1
- package/src/base.dictionary.d.ts +1 -93
- package/src/dictInfo.d.ts +204 -0
- package/src/dictionary.d.ts +12 -111
- package/src/index.d.ts +3 -1
- package/src/locale.d.ts +107 -0
- package/src/serverTranslator.d.ts +1 -1
- package/src/trans.d.ts +20 -82
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import { capitalize } from "@akanjs/common";
|
|
2
|
+
class FieldTranslation {
|
|
3
|
+
static translate = (trans) => new FieldTranslation(trans);
|
|
4
|
+
trans;
|
|
5
|
+
descTrans;
|
|
6
|
+
constructor(trans) {
|
|
7
|
+
this.trans = trans;
|
|
8
|
+
}
|
|
9
|
+
desc(descTrans) {
|
|
10
|
+
this.descTrans = descTrans;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class FunctionTranslation {
|
|
15
|
+
trans;
|
|
16
|
+
descTrans;
|
|
17
|
+
argTrans = {};
|
|
18
|
+
constructor(trans) {
|
|
19
|
+
this.trans = trans;
|
|
20
|
+
}
|
|
21
|
+
desc(descTrans) {
|
|
22
|
+
this.descTrans = descTrans;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
arg(translate) {
|
|
26
|
+
Object.assign(this.argTrans, translate(FieldTranslation.translate));
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const fn = (trans) => new FunctionTranslation(trans);
|
|
31
|
+
class ModelDictInfo {
|
|
32
|
+
static baseModelDictionary = {
|
|
33
|
+
id: FieldTranslation.translate(["ID", "\uC544\uC774\uB514"]).desc(["Unique ID value", "\uC720\uB2C8\uD06C\uD55C \uC544\uC774\uB514\uAC12"]),
|
|
34
|
+
createdAt: FieldTranslation.translate(["CreatedAt", "\uC0DD\uC131\uC77C"]).desc(["Data created time", "\uB370\uC774\uD130 \uC0DD\uC131 \uC2DC\uAC01"]),
|
|
35
|
+
updatedAt: FieldTranslation.translate(["UpdatedAt", "\uC218\uC815\uC77C"]).desc([
|
|
36
|
+
"Data updated time",
|
|
37
|
+
"\uB370\uC774\uD130 \uB9C8\uC9C0\uB9C9 \uC218\uC815 \uC2DC\uAC01"
|
|
38
|
+
]),
|
|
39
|
+
removedAt: FieldTranslation.translate(["RemovedAt", "\uC0AD\uC81C\uC77C"]).desc(["Data removed time", "\uB370\uC774\uD130 \uC0AD\uC81C \uC2DC\uAC01"])
|
|
40
|
+
};
|
|
41
|
+
static baseInsightDictionary = {
|
|
42
|
+
count: FieldTranslation.translate(["Count", "\uAC1C\uC218"]).desc(["Total number of items", "\uCD1D \uC544\uC774\uD15C \uAC1C\uC218"])
|
|
43
|
+
};
|
|
44
|
+
static baseQueryDictionary = {
|
|
45
|
+
any: fn(["Any", "\uC804\uCCB4"]).desc(["All", "\uC804\uCCB4"])
|
|
46
|
+
};
|
|
47
|
+
static baseSortDictionary = {
|
|
48
|
+
latest: FieldTranslation.translate(["Latest", "\uCD5C\uC2E0\uC21C"]).desc(["Latest", "\uCD5C\uC2E0\uC21C"]),
|
|
49
|
+
oldest: FieldTranslation.translate(["Oldest", "\uC624\uB798\uB41C\uC21C"]).desc(["Oldest", "\uC624\uB798\uB41C\uC21C"])
|
|
50
|
+
};
|
|
51
|
+
static getBaseSignalDictionary(refName) {
|
|
52
|
+
return {
|
|
53
|
+
[refName]: fn([`Get ${refName}`, `${refName} \uC870\uD68C`]).desc([`Get ${refName}`, `${refName} \uC870\uD68C`]).arg((t) => ({ [`${refName}Id`]: t(["Id", "\uC544\uC774\uB514"]).desc([`Id of ${refName}`, `${refName} \uC544\uC774\uB514`]) })),
|
|
54
|
+
[`light${refName}`]: fn([`Get light version of ${refName}`, `${refName} \uACBD\uB7C9\uD654 \uBC84\uC804 \uC870\uD68C`]).desc([`Get light version of ${refName}`, `${refName} \uACBD\uB7C9\uD654 \uBC84\uC804 \uC870\uD68C`]).arg((t) => ({ [`${refName}Id`]: t(["Id", "\uC544\uC774\uB514"]).desc([`Id of ${refName}`, `${refName} \uC544\uC774\uB514`]) })),
|
|
55
|
+
[`create${refName}`]: fn([`Create ${refName}`, `${refName} \uC0DD\uC131`]).desc([`Create ${refName}`, `${refName} \uC0DD\uC131`]).arg((t) => ({ data: t(["Data", "\uB370\uC774\uD130"]).desc([`Data of ${refName}`, `${refName} \uB370\uC774\uD130`]) })),
|
|
56
|
+
[`update${refName}`]: fn([`Update ${refName}`, `${refName} \uC218\uC815`]).desc([`Update ${refName}`, `${refName} \uC218\uC815`]).arg((t) => ({
|
|
57
|
+
[`${refName}Id`]: t(["Id", "\uC544\uC774\uB514"]).desc([`Id of ${refName}`, `${refName} \uC544\uC774\uB514`]),
|
|
58
|
+
data: t(["Data", "\uB370\uC774\uD130"]).desc([`Data of ${refName}`, `${refName} \uB370\uC774\uD130`])
|
|
59
|
+
})),
|
|
60
|
+
[`remove${refName}`]: fn([`Remove ${refName}`, `${refName} \uC0AD\uC81C`]).desc([`Remove ${refName}`, `${refName} \uC0AD\uC81C`]).arg((t) => ({ [`${refName}Id`]: t(["Id", "\uC544\uC774\uB514"]).desc([`Id of ${refName}`, `${refName} \uC544\uC774\uB514`]) }))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
static baseSliceDictionary = {
|
|
64
|
+
[""]: fn(["Universal", "\uC720\uB2C8\uBC84\uC124"]).desc(["Universal Slice", "\uC720\uB2C8\uBC84\uC124 \uC2AC\uB77C\uC774\uC2A4"]).arg((t) => ({ query: t(["Query", "\uCFFC\uB9AC"]).desc(["Query Description", "\uCFFC\uB9AC \uC124\uBA85"]) }))
|
|
65
|
+
};
|
|
66
|
+
languages;
|
|
67
|
+
modelTranslation;
|
|
68
|
+
modelDictionary = {};
|
|
69
|
+
insightDictionary = {};
|
|
70
|
+
queryDictionary = {};
|
|
71
|
+
sortDictionary = {};
|
|
72
|
+
enumDictionary = {};
|
|
73
|
+
baseSignalDictionary = {};
|
|
74
|
+
sliceDictionary = {};
|
|
75
|
+
endpointDictionary = {};
|
|
76
|
+
errorDictionary = {};
|
|
77
|
+
etcDictionary = {};
|
|
78
|
+
constructor(languages) {
|
|
79
|
+
this.languages = languages;
|
|
80
|
+
}
|
|
81
|
+
of(translate) {
|
|
82
|
+
this.modelTranslation = translate(FieldTranslation.translate);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
model(translate) {
|
|
86
|
+
Object.assign(
|
|
87
|
+
this.modelDictionary,
|
|
88
|
+
translate(FieldTranslation.translate),
|
|
89
|
+
ModelDictInfo.baseModelDictionary
|
|
90
|
+
);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
insight(translate) {
|
|
94
|
+
Object.assign(
|
|
95
|
+
this.insightDictionary,
|
|
96
|
+
translate(FieldTranslation.translate),
|
|
97
|
+
ModelDictInfo.baseInsightDictionary
|
|
98
|
+
);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
query(translate) {
|
|
102
|
+
Object.assign(this.queryDictionary, translate(fn), ModelDictInfo.baseQueryDictionary);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
sort(translate) {
|
|
106
|
+
Object.assign(
|
|
107
|
+
this.sortDictionary,
|
|
108
|
+
translate(FieldTranslation.translate),
|
|
109
|
+
ModelDictInfo.baseSortDictionary
|
|
110
|
+
);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
enum(enumName, translate) {
|
|
114
|
+
Object.assign(this.enumDictionary, { [enumName]: translate(FieldTranslation.translate) });
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
slice(translate) {
|
|
118
|
+
Object.assign(this.sliceDictionary, translate(fn), ModelDictInfo.baseSliceDictionary);
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
endpoint(translate) {
|
|
122
|
+
Object.assign(this.endpointDictionary, translate(fn));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
error(errorDictionary) {
|
|
126
|
+
Object.assign(this.errorDictionary, errorDictionary);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
translate(etcDictionary) {
|
|
130
|
+
Object.assign(this.etcDictionary, etcDictionary);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
_applyBaseSignal(refName) {
|
|
134
|
+
Object.assign(this.baseSignalDictionary, ModelDictInfo.getBaseSignalDictionary(refName));
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
_registerToRoot(refName, rootDict) {
|
|
138
|
+
this.languages.forEach((language) => {
|
|
139
|
+
rootDict[language] ??= {};
|
|
140
|
+
rootDict[language][refName] ??= {};
|
|
141
|
+
});
|
|
142
|
+
if (this.modelTranslation) {
|
|
143
|
+
this.modelTranslation.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].modelName = { t });
|
|
144
|
+
this.modelTranslation.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].modelDesc = { t });
|
|
145
|
+
}
|
|
146
|
+
this.#registerInsightToRoot(refName, rootDict);
|
|
147
|
+
this.#registerQueryToRoot(refName, rootDict);
|
|
148
|
+
this.#registerSortToRoot(refName, rootDict);
|
|
149
|
+
this.#registerEnumToRoot(rootDict);
|
|
150
|
+
this.#registerBaseSignalToRoot(refName, rootDict);
|
|
151
|
+
this.#registerSliceToRoot(refName, rootDict);
|
|
152
|
+
this.#registerEndpointToRoot(refName, rootDict);
|
|
153
|
+
this.#registerErrorToRoot(refName, rootDict);
|
|
154
|
+
this.#registerModelToRoot(refName, rootDict);
|
|
155
|
+
this.#registerEtcToRoot(refName, rootDict);
|
|
156
|
+
}
|
|
157
|
+
#registerModelToRoot(refName, rootDict) {
|
|
158
|
+
Object.entries(this.modelDictionary).forEach(([key, value]) => {
|
|
159
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName][key] = { t });
|
|
160
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName][key].desc = { t });
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
#registerInsightToRoot(refName, rootDict) {
|
|
164
|
+
this.languages.forEach((language) => rootDict[language][refName].insight ??= {});
|
|
165
|
+
Object.entries(this.insightDictionary).forEach(([key, value]) => {
|
|
166
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].insight[key] = { t });
|
|
167
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].insight[key].desc = { t });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
#registerQueryToRoot(refName, rootDict) {
|
|
171
|
+
this.languages.forEach((language) => rootDict[language][refName].query ??= {});
|
|
172
|
+
Object.entries(this.queryDictionary).forEach(
|
|
173
|
+
([key, value]) => {
|
|
174
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].query[key] = { t, arg: {} });
|
|
175
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].query[key].desc = { t });
|
|
176
|
+
Object.entries(value.argTrans).forEach(
|
|
177
|
+
([argKey, argTrans]) => {
|
|
178
|
+
argTrans.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].query[key].arg[argKey] = { t });
|
|
179
|
+
argTrans.descTrans?.forEach(
|
|
180
|
+
(t, idx) => rootDict[this.languages[idx]][refName].query[key].arg[argKey].desc = { t }
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
#registerSortToRoot(refName, rootDict) {
|
|
188
|
+
this.languages.forEach((language) => rootDict[language][refName].sort ??= {});
|
|
189
|
+
Object.entries(this.sortDictionary).forEach(([key, value]) => {
|
|
190
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].sort[key] = { t });
|
|
191
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].sort[key].desc = { t });
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
#registerEnumToRoot(rootDict) {
|
|
195
|
+
Object.entries(this.enumDictionary).forEach(
|
|
196
|
+
([refName, enumTrans]) => {
|
|
197
|
+
this.languages.forEach((language) => rootDict[language][refName] ??= {});
|
|
198
|
+
Object.entries(enumTrans).forEach(([enumKey, enumValue]) => {
|
|
199
|
+
enumValue.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName][enumKey] = { t });
|
|
200
|
+
enumValue.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName][enumKey].desc = { t });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
#registerBaseSignalToRoot(refName, rootDict) {
|
|
206
|
+
this.languages.forEach((language) => rootDict[language][refName].api ??= {});
|
|
207
|
+
Object.entries(this.baseSignalDictionary).forEach(
|
|
208
|
+
([key, value]) => {
|
|
209
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key] = { t, arg: {} });
|
|
210
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].desc = { t });
|
|
211
|
+
Object.entries(value.argTrans).forEach(
|
|
212
|
+
([argKey, argTrans]) => {
|
|
213
|
+
argTrans.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey] = { t });
|
|
214
|
+
argTrans.descTrans?.forEach(
|
|
215
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey].desc = { t }
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
#registerSliceToRoot(refName, rootDict) {
|
|
223
|
+
this.languages.forEach((language) => rootDict[language][refName].api ??= {});
|
|
224
|
+
Object.entries(this.sliceDictionary).forEach(
|
|
225
|
+
([sliceKey, sliceTrans]) => {
|
|
226
|
+
const listKey = `${refName}List${capitalize(sliceKey)}`;
|
|
227
|
+
const insightKey = `${refName}Insight${capitalize(sliceKey)}`;
|
|
228
|
+
sliceTrans.trans.forEach(
|
|
229
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey] = { t: `Slice List - ${t}`, arg: {} }
|
|
230
|
+
);
|
|
231
|
+
sliceTrans.descTrans?.forEach(
|
|
232
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey].desc = { t: `Slice List - ${t}` }
|
|
233
|
+
);
|
|
234
|
+
sliceTrans.trans.forEach(
|
|
235
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[insightKey] = { t: `Slice Insight - ${t}`, arg: {} }
|
|
236
|
+
);
|
|
237
|
+
sliceTrans.descTrans?.forEach(
|
|
238
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[insightKey].desc = { t: `Slice Insight - ${t}` }
|
|
239
|
+
);
|
|
240
|
+
Object.entries(sliceTrans.argTrans).forEach(
|
|
241
|
+
([argKey, argTrans]) => {
|
|
242
|
+
argTrans.trans.forEach(
|
|
243
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey].arg[argKey] = { t }
|
|
244
|
+
);
|
|
245
|
+
argTrans.descTrans?.forEach(
|
|
246
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey].arg[argKey].desc = { t }
|
|
247
|
+
);
|
|
248
|
+
["skip", "limit", "sort"].forEach((argKey2) => {
|
|
249
|
+
argTrans.trans.forEach(
|
|
250
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey].arg[argKey2] = { t: argKey2 }
|
|
251
|
+
);
|
|
252
|
+
argTrans.descTrans?.forEach(
|
|
253
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[listKey].arg[argKey2].desc = { t: argKey2 }
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
argTrans.trans.forEach(
|
|
257
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[insightKey].arg[argKey] = { t }
|
|
258
|
+
);
|
|
259
|
+
argTrans.descTrans?.forEach(
|
|
260
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[insightKey].arg[argKey].desc = { t }
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
#registerEndpointToRoot(refName, rootDict) {
|
|
268
|
+
this.languages.forEach((language) => rootDict[language][refName].api ??= {});
|
|
269
|
+
Object.entries(this.endpointDictionary).forEach(
|
|
270
|
+
([key, value]) => {
|
|
271
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key] = { t, arg: {} });
|
|
272
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].desc = { t });
|
|
273
|
+
Object.entries(value.argTrans).forEach(
|
|
274
|
+
([argKey, argTrans]) => {
|
|
275
|
+
argTrans.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey] = { t });
|
|
276
|
+
argTrans.descTrans?.forEach(
|
|
277
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey].desc = { t }
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
#registerErrorToRoot(refName, rootDict) {
|
|
285
|
+
this.languages.forEach((language) => rootDict[language][refName].error ??= {});
|
|
286
|
+
Object.entries(this.errorDictionary).forEach(([key, value]) => {
|
|
287
|
+
value.forEach((t, idx) => {
|
|
288
|
+
rootDict[this.languages[idx]][refName].error[key] ??= {};
|
|
289
|
+
rootDict[this.languages[idx]][refName].error[key].t = t;
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
#registerEtcToRoot(refName, rootDict) {
|
|
294
|
+
Object.entries(this.etcDictionary).forEach(([key, value]) => {
|
|
295
|
+
value.forEach((t, idx) => {
|
|
296
|
+
rootDict[this.languages[idx]][refName][key] ??= {};
|
|
297
|
+
rootDict[this.languages[idx]][refName][key].t = t;
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const modelDictionary = (languages = ["en"], ...extendModelDicts) => {
|
|
303
|
+
const modelDictionary2 = extendModelDicts.at(0) ?? new ModelDictInfo(languages);
|
|
304
|
+
return modelDictionary2;
|
|
305
|
+
};
|
|
306
|
+
class ScalarDictInfo {
|
|
307
|
+
languages;
|
|
308
|
+
modelTranslation;
|
|
309
|
+
modelDictionary = {};
|
|
310
|
+
enumDictionary = {};
|
|
311
|
+
errorDictionary = {};
|
|
312
|
+
etcDictionary = {};
|
|
313
|
+
constructor(languages) {
|
|
314
|
+
this.languages = languages;
|
|
315
|
+
}
|
|
316
|
+
of(translate) {
|
|
317
|
+
this.modelTranslation = translate(FieldTranslation.translate);
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
model(translate) {
|
|
321
|
+
Object.assign(
|
|
322
|
+
this.modelDictionary,
|
|
323
|
+
translate(FieldTranslation.translate),
|
|
324
|
+
ModelDictInfo.baseModelDictionary
|
|
325
|
+
);
|
|
326
|
+
return this;
|
|
327
|
+
}
|
|
328
|
+
enum(enumName, translate) {
|
|
329
|
+
Object.assign(this.enumDictionary, { [enumName]: translate(FieldTranslation.translate) });
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
error(errorDictionary) {
|
|
333
|
+
Object.assign(this.errorDictionary, errorDictionary);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
translate(etcDictionary) {
|
|
337
|
+
Object.assign(this.etcDictionary, etcDictionary);
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
_registerToRoot(refName, rootDict) {
|
|
341
|
+
this.languages.forEach((language) => {
|
|
342
|
+
rootDict[language] ??= {};
|
|
343
|
+
rootDict[language][refName] ??= {};
|
|
344
|
+
});
|
|
345
|
+
if (this.modelTranslation) {
|
|
346
|
+
this.modelTranslation.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].modelName = { t });
|
|
347
|
+
this.modelTranslation.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].modelDesc = { t });
|
|
348
|
+
}
|
|
349
|
+
this.#registerEnumToRoot(rootDict);
|
|
350
|
+
this.#registerErrorToRoot(refName, rootDict);
|
|
351
|
+
this.#registerModelToRoot(refName, rootDict);
|
|
352
|
+
this.#registerEtcToRoot(refName, rootDict);
|
|
353
|
+
}
|
|
354
|
+
#registerModelToRoot(refName, rootDict) {
|
|
355
|
+
Object.entries(this.modelDictionary).forEach(([key, value]) => {
|
|
356
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName][key] = { t });
|
|
357
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName][key].desc = { t });
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
#registerEnumToRoot(rootDict) {
|
|
361
|
+
Object.entries(this.enumDictionary).forEach(
|
|
362
|
+
([refName, enumTrans]) => {
|
|
363
|
+
this.languages.forEach((language) => rootDict[language][refName] ??= {});
|
|
364
|
+
Object.entries(enumTrans).forEach(([enumKey, enumValue]) => {
|
|
365
|
+
enumValue.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName][enumKey] = { t });
|
|
366
|
+
enumValue.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName][enumKey].desc = { t });
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
#registerErrorToRoot(refName, rootDict) {
|
|
372
|
+
this.languages.forEach((language) => rootDict[language][refName].error ??= {});
|
|
373
|
+
Object.entries(this.errorDictionary).forEach(([key, value]) => {
|
|
374
|
+
value.forEach((t, idx) => {
|
|
375
|
+
rootDict[this.languages[idx]][refName].error[key] ??= {};
|
|
376
|
+
rootDict[this.languages[idx]][refName].error[key].t = t;
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
#registerEtcToRoot(refName, rootDict) {
|
|
381
|
+
Object.entries(this.etcDictionary).forEach(([key, value]) => {
|
|
382
|
+
value.forEach((t, idx) => {
|
|
383
|
+
rootDict[this.languages[idx]][refName][key] ??= {};
|
|
384
|
+
rootDict[this.languages[idx]][refName][key].t = t;
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const scalarDictionary = (languages = ["en"]) => new ScalarDictInfo(languages);
|
|
390
|
+
class ServiceDictInfo {
|
|
391
|
+
languages;
|
|
392
|
+
endpointDictionary = {};
|
|
393
|
+
errorDictionary = {};
|
|
394
|
+
etcDictionary = {};
|
|
395
|
+
constructor(languages) {
|
|
396
|
+
this.languages = languages;
|
|
397
|
+
}
|
|
398
|
+
endpoint(translate) {
|
|
399
|
+
Object.assign(this.endpointDictionary, translate(fn));
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
error(errorDictionary) {
|
|
403
|
+
Object.assign(this.errorDictionary, errorDictionary);
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
translate(etcDictionary) {
|
|
407
|
+
Object.assign(this.etcDictionary, etcDictionary);
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
_toTranslation() {
|
|
411
|
+
return Object.assign({}, this.errorDictionary, this.etcDictionary);
|
|
412
|
+
}
|
|
413
|
+
_registerToRoot(refName, rootDict) {
|
|
414
|
+
this.languages.forEach((language) => {
|
|
415
|
+
rootDict[language] ??= {};
|
|
416
|
+
rootDict[language][refName] ??= {};
|
|
417
|
+
});
|
|
418
|
+
this.#registerEndpointToRoot(refName, rootDict);
|
|
419
|
+
this.#registerErrorToRoot(refName, rootDict);
|
|
420
|
+
this.#registerEtcToRoot(refName, rootDict);
|
|
421
|
+
}
|
|
422
|
+
#registerEndpointToRoot(refName, rootDict) {
|
|
423
|
+
this.languages.forEach((language) => rootDict[language][refName].api ??= {});
|
|
424
|
+
Object.entries(this.endpointDictionary).forEach(
|
|
425
|
+
([key, value]) => {
|
|
426
|
+
value.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key] = { t, arg: {} });
|
|
427
|
+
value.descTrans?.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].desc = { t });
|
|
428
|
+
Object.entries(value.argTrans).forEach(
|
|
429
|
+
([argKey, argTrans]) => {
|
|
430
|
+
argTrans.trans.forEach((t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey] = { t });
|
|
431
|
+
argTrans.descTrans?.forEach(
|
|
432
|
+
(t, idx) => rootDict[this.languages[idx]][refName].api[key].arg[argKey].desc = { t }
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
#registerErrorToRoot(refName, rootDict) {
|
|
440
|
+
this.languages.forEach((language) => rootDict[language][refName].error ??= {});
|
|
441
|
+
Object.entries(this.errorDictionary).forEach(([key, value]) => {
|
|
442
|
+
value.forEach((t, idx) => {
|
|
443
|
+
rootDict[this.languages[idx]][refName].error[key] ??= {};
|
|
444
|
+
rootDict[this.languages[idx]][refName].error[key].t = t;
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
#registerEtcToRoot(refName, rootDict) {
|
|
449
|
+
Object.entries(this.etcDictionary).forEach(([key, value]) => {
|
|
450
|
+
value.forEach((t, idx) => {
|
|
451
|
+
rootDict[this.languages[idx]][refName][key] ??= {};
|
|
452
|
+
rootDict[this.languages[idx]][refName][key].t = t;
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const serviceDictionary = (languages = ["en"]) => new ServiceDictInfo(languages);
|
|
458
|
+
export {
|
|
459
|
+
ModelDictInfo,
|
|
460
|
+
ScalarDictInfo,
|
|
461
|
+
ServiceDictInfo,
|
|
462
|
+
modelDictionary,
|
|
463
|
+
scalarDictionary,
|
|
464
|
+
serviceDictionary
|
|
465
|
+
};
|
package/esm/src/dictionary.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { baseDictionary } from "./base.dictionary";
|
|
2
|
+
import { registerServiceTrans } from "./locale";
|
|
2
3
|
import { makeTrans } from "./trans";
|
|
3
|
-
const dictionary = {
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
const { Revert, translate, msg, getDictionary, getAllDictionary } = makeTrans(dictionary);
|
|
4
|
+
const dictionary = { base: registerServiceTrans(baseDictionary) };
|
|
5
|
+
const { Revert, translate, msg, getDictionary, getAllDictionary, __Dict_Key__, __Error_Key__ } = makeTrans(dictionary);
|
|
7
6
|
export {
|
|
8
7
|
Revert,
|
|
8
|
+
__Dict_Key__,
|
|
9
|
+
__Error_Key__,
|
|
9
10
|
dictionary,
|
|
10
11
|
getAllDictionary,
|
|
11
12
|
getDictionary,
|
package/esm/src/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
export * from "./trans";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Revert,
|
|
4
|
+
translate,
|
|
5
|
+
dictionary,
|
|
6
|
+
getDictionary,
|
|
7
|
+
getAllDictionary,
|
|
8
|
+
__Dict_Key__,
|
|
9
|
+
__Error_Key__
|
|
10
|
+
} from "./dictionary";
|
|
3
11
|
export * from "./serverTranslator";
|
|
12
|
+
export * from "./dictInfo";
|
|
13
|
+
export * from "./locale";
|
|
4
14
|
export {
|
|
5
15
|
Revert,
|
|
16
|
+
__Dict_Key__,
|
|
17
|
+
__Error_Key__,
|
|
6
18
|
dictionary,
|
|
7
19
|
getAllDictionary,
|
|
8
20
|
getDictionary,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const registerModelTrans = (modelDict) => {
|
|
2
|
+
return { dict: modelDict };
|
|
3
|
+
};
|
|
4
|
+
const registerScalarTrans = (scalarDict) => {
|
|
5
|
+
return { dict: scalarDict };
|
|
6
|
+
};
|
|
7
|
+
const registerServiceTrans = (serviceDict) => {
|
|
8
|
+
return { dict: serviceDict };
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
registerModelTrans,
|
|
12
|
+
registerScalarTrans,
|
|
13
|
+
registerServiceTrans
|
|
14
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { baseClientEnv } from "@akanjs/base";
|
|
2
|
-
import { Logger } from "@akanjs/common";
|
|
2
|
+
import { Logger, pathGet } from "@akanjs/common";
|
|
3
3
|
class ServerTranslator {
|
|
4
4
|
static #langTransMap = /* @__PURE__ */ new Map();
|
|
5
5
|
async init(lang) {
|
|
@@ -28,10 +28,7 @@ class ServerTranslator {
|
|
|
28
28
|
const trans = {
|
|
29
29
|
dictionary,
|
|
30
30
|
translate: (dictKey) => {
|
|
31
|
-
|
|
32
|
-
const model = keyParts[0];
|
|
33
|
-
const key = keyParts.slice(1).join(".");
|
|
34
|
-
return dictionary[model]?.[key] ?? dictKey;
|
|
31
|
+
return pathGet(dictKey, dictionary, ".", { t: dictKey }).t;
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
ServerTranslator.#langTransMap.set(lang, trans);
|