@akanjs/dictionary 0.9.43 → 0.9.44

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.
@@ -22,6 +22,8 @@ __export(base_dictionary_exports, {
22
22
  module.exports = __toCommonJS(base_dictionary_exports);
23
23
  const baseDictionary = {
24
24
  // * ==================== Endpoint ==================== * //
25
+ "api-publishPing": ["Publish Ping", "Publish Ping"],
26
+ "apidesc-publishPing": ["Publish Ping", "Publish Ping"],
25
27
  "api-ping": ["Ping", "Ping"],
26
28
  "apidesc-ping": ["Ping", "Ping"],
27
29
  "api-pingBody": ["Ping Body", "Ping Body"],
@@ -50,6 +52,10 @@ const baseDictionary = {
50
52
  "argdesc-wsPing-data": ["Data", "\uB370\uC774\uD130"],
51
53
  "api-pubsubPing": ["Pubsub Ping", "Pubsub Ping"],
52
54
  "apidesc-pubsubPing": ["Pubsub Ping", "Pubsub Ping"],
55
+ "api-getDictionary": ["Get Dictionary", "Get Dictionary"],
56
+ "apidesc-getDictionary": ["Get Dictionary", "Get Dictionary"],
57
+ "arg-getDictionary-lang": ["Language", "\uC5B8\uC5B4"],
58
+ "argdesc-getDictionary-lang": ["Language", "\uC5B8\uC5B4"],
53
59
  // * ==================== Endpoint ==================== * //
54
60
  // * ==================== Etc ==================== * //
55
61
  new: ["New", "\uC2E0\uADDC"],
@@ -60,6 +66,8 @@ const baseDictionary = {
60
66
  refreshing: ["Refreshing the page in some seconds.", "\uBA87 \uCD08 \uD6C4 \uC0C8\uB85C\uACE0\uCE68\uB429\uB2C8\uB2E4."],
61
67
  tryReconnecting: ["Try reconnecting to the server", "\uC11C\uBC84\uC5D0 \uB2E4\uC2DC \uC5F0\uACB0\uC911\uC785\uB2C8\uB2E4."],
62
68
  serverHasProblem: ["Maybe your server is having a problem.", "\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uC788\uC744 \uC218 \uC788\uC2B5\uB2C8\uB2E4."],
63
- checkServerStatus: ["Please check your server status.", "\uC11C\uBC84 \uC0C1\uD0DC\uB97C \uD655\uC778\uD574\uC8FC\uC138\uC694."]
69
+ checkServerStatus: ["Please check your server status.", "\uC11C\uBC84 \uC0C1\uD0DC\uB97C \uD655\uC778\uD574\uC8FC\uC138\uC694."],
70
+ success: ["Success", "\uC131\uACF5"],
71
+ failed: ["Failed", "\uC2E4\uD328"]
64
72
  // * ==================== Etc ==================== * //
65
73
  };
@@ -19,6 +19,7 @@ var dictionary_exports = {};
19
19
  __export(dictionary_exports, {
20
20
  Revert: () => Revert,
21
21
  dictionary: () => dictionary,
22
+ getDictionary: () => getDictionary,
22
23
  msg: () => msg,
23
24
  translate: () => translate
24
25
  });
@@ -28,4 +29,4 @@ var import_trans = require("./trans");
28
29
  const dictionary = {
29
30
  base: import_base.baseDictionary
30
31
  };
31
- const { Revert, translate, msg } = (0, import_trans.makeTrans)(dictionary);
32
+ const { Revert, translate, msg, getDictionary } = (0, import_trans.makeTrans)(dictionary);
package/cjs/src/index.js CHANGED
@@ -18,8 +18,13 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var src_exports = {};
20
20
  __export(src_exports, {
21
- dictionary: () => import_dictionary.dictionary
21
+ Revert: () => import_dictionary.Revert,
22
+ dictionary: () => import_dictionary.dictionary,
23
+ getDictionary: () => import_dictionary.getDictionary,
24
+ serverTranslator: () => import_serverTranslator.serverTranslator,
25
+ translate: () => import_dictionary.translate
22
26
  });
23
27
  module.exports = __toCommonJS(src_exports);
24
28
  __reExport(src_exports, require("./trans"), module.exports);
25
29
  var import_dictionary = require("./dictionary");
30
+ var import_serverTranslator = require("./serverTranslator");
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var serverTranslator_exports = {};
19
+ __export(serverTranslator_exports, {
20
+ ServerTranslator: () => ServerTranslator,
21
+ serverTranslator: () => serverTranslator
22
+ });
23
+ module.exports = __toCommonJS(serverTranslator_exports);
24
+ var import_common = require("@akanjs/common");
25
+ var import_signal = require("@akanjs/signal");
26
+ class ServerTranslator {
27
+ static #langTransMap = /* @__PURE__ */ new Map();
28
+ async init(lang) {
29
+ await this.#getTranslator(lang);
30
+ }
31
+ async #getTranslator(lang) {
32
+ const existingTrans = ServerTranslator.#langTransMap.get(lang);
33
+ if (existingTrans)
34
+ return existingTrans;
35
+ import_common.Logger.log("Initialize ServerTranslator");
36
+ const dictionary = await import_signal.fetch.getDictionary(lang);
37
+ const trans = {
38
+ dictionary,
39
+ translate: (dictKey) => {
40
+ const keyParts = dictKey.split(".");
41
+ const model = keyParts[0];
42
+ const key = keyParts.slice(1).join(".");
43
+ return dictionary[model]?.[key] ?? dictKey;
44
+ }
45
+ };
46
+ ServerTranslator.#langTransMap.set(lang, trans);
47
+ return trans;
48
+ }
49
+ getTransSync(lang, key) {
50
+ const trans = ServerTranslator.#langTransMap.get(lang);
51
+ if (!trans)
52
+ return void 0;
53
+ const { translate } = trans;
54
+ const msg = translate(key);
55
+ return msg;
56
+ }
57
+ async getTrans(lang, key) {
58
+ const { translate } = await this.#getTranslator(lang);
59
+ const msg = translate(key);
60
+ return msg;
61
+ }
62
+ async getDictionary(lang) {
63
+ const { dictionary } = await this.#getTranslator(lang);
64
+ return dictionary;
65
+ }
66
+ }
67
+ const serverTranslator = new ServerTranslator();
package/cjs/src/trans.js CHANGED
@@ -331,7 +331,7 @@ const makeDictionary = (...dicts) => {
331
331
  });
332
332
  return rootDict;
333
333
  };
334
- const languages = ["ko", "en", "zhChs", "zhCht"];
334
+ const languages = ["en", "ko", "zhChs", "zhCht"];
335
335
  const msg = {
336
336
  info: () => null,
337
337
  success: () => null,
@@ -357,5 +357,15 @@ const makeTrans = (locale) => {
357
357
  throw new Error("Invalid message");
358
358
  return message;
359
359
  };
360
- return { revert, Revert, translate, msg };
360
+ const getDictionary = (lang) => {
361
+ const langIdx = languages.indexOf(lang);
362
+ const dictionary = {};
363
+ Object.entries(locale).forEach(([key, value]) => {
364
+ dictionary[key] = Object.fromEntries(
365
+ Object.entries(value).map(([key2, value2]) => [key2, value2[langIdx]])
366
+ );
367
+ });
368
+ return dictionary;
369
+ };
370
+ return { revert, Revert, translate, msg, getDictionary };
361
371
  };
@@ -1,5 +1,7 @@
1
1
  const baseDictionary = {
2
2
  // * ==================== Endpoint ==================== * //
3
+ "api-publishPing": ["Publish Ping", "Publish Ping"],
4
+ "apidesc-publishPing": ["Publish Ping", "Publish Ping"],
3
5
  "api-ping": ["Ping", "Ping"],
4
6
  "apidesc-ping": ["Ping", "Ping"],
5
7
  "api-pingBody": ["Ping Body", "Ping Body"],
@@ -28,6 +30,10 @@ const baseDictionary = {
28
30
  "argdesc-wsPing-data": ["Data", "\uB370\uC774\uD130"],
29
31
  "api-pubsubPing": ["Pubsub Ping", "Pubsub Ping"],
30
32
  "apidesc-pubsubPing": ["Pubsub Ping", "Pubsub Ping"],
33
+ "api-getDictionary": ["Get Dictionary", "Get Dictionary"],
34
+ "apidesc-getDictionary": ["Get Dictionary", "Get Dictionary"],
35
+ "arg-getDictionary-lang": ["Language", "\uC5B8\uC5B4"],
36
+ "argdesc-getDictionary-lang": ["Language", "\uC5B8\uC5B4"],
31
37
  // * ==================== Endpoint ==================== * //
32
38
  // * ==================== Etc ==================== * //
33
39
  new: ["New", "\uC2E0\uADDC"],
@@ -38,7 +44,9 @@ const baseDictionary = {
38
44
  refreshing: ["Refreshing the page in some seconds.", "\uBA87 \uCD08 \uD6C4 \uC0C8\uB85C\uACE0\uCE68\uB429\uB2C8\uB2E4."],
39
45
  tryReconnecting: ["Try reconnecting to the server", "\uC11C\uBC84\uC5D0 \uB2E4\uC2DC \uC5F0\uACB0\uC911\uC785\uB2C8\uB2E4."],
40
46
  serverHasProblem: ["Maybe your server is having a problem.", "\uC11C\uBC84\uC5D0 \uBB38\uC81C\uAC00 \uC788\uC744 \uC218 \uC788\uC2B5\uB2C8\uB2E4."],
41
- checkServerStatus: ["Please check your server status.", "\uC11C\uBC84 \uC0C1\uD0DC\uB97C \uD655\uC778\uD574\uC8FC\uC138\uC694."]
47
+ checkServerStatus: ["Please check your server status.", "\uC11C\uBC84 \uC0C1\uD0DC\uB97C \uD655\uC778\uD574\uC8FC\uC138\uC694."],
48
+ success: ["Success", "\uC131\uACF5"],
49
+ failed: ["Failed", "\uC2E4\uD328"]
42
50
  // * ==================== Etc ==================== * //
43
51
  };
44
52
  export {
@@ -3,10 +3,11 @@ import { makeTrans } from "./trans";
3
3
  const dictionary = {
4
4
  base: baseDictionary
5
5
  };
6
- const { Revert, translate, msg } = makeTrans(dictionary);
6
+ const { Revert, translate, msg, getDictionary } = makeTrans(dictionary);
7
7
  export {
8
8
  Revert,
9
9
  dictionary,
10
+ getDictionary,
10
11
  msg,
11
12
  translate
12
13
  };
package/esm/src/index.js CHANGED
@@ -1,5 +1,10 @@
1
1
  export * from "./trans";
2
- import { dictionary } from "./dictionary";
2
+ import { Revert, translate, dictionary, getDictionary } from "./dictionary";
3
+ import { serverTranslator } from "./serverTranslator";
3
4
  export {
4
- dictionary
5
+ Revert,
6
+ dictionary,
7
+ getDictionary,
8
+ serverTranslator,
9
+ translate
5
10
  };
@@ -0,0 +1,48 @@
1
+ import { Logger } from "@akanjs/common";
2
+ import { fetch } from "@akanjs/signal";
3
+ class ServerTranslator {
4
+ static #langTransMap = /* @__PURE__ */ new Map();
5
+ async init(lang) {
6
+ await this.#getTranslator(lang);
7
+ }
8
+ async #getTranslator(lang) {
9
+ const existingTrans = ServerTranslator.#langTransMap.get(lang);
10
+ if (existingTrans)
11
+ return existingTrans;
12
+ Logger.log("Initialize ServerTranslator");
13
+ const dictionary = await fetch.getDictionary(lang);
14
+ const trans = {
15
+ dictionary,
16
+ translate: (dictKey) => {
17
+ const keyParts = dictKey.split(".");
18
+ const model = keyParts[0];
19
+ const key = keyParts.slice(1).join(".");
20
+ return dictionary[model]?.[key] ?? dictKey;
21
+ }
22
+ };
23
+ ServerTranslator.#langTransMap.set(lang, trans);
24
+ return trans;
25
+ }
26
+ getTransSync(lang, key) {
27
+ const trans = ServerTranslator.#langTransMap.get(lang);
28
+ if (!trans)
29
+ return void 0;
30
+ const { translate } = trans;
31
+ const msg = translate(key);
32
+ return msg;
33
+ }
34
+ async getTrans(lang, key) {
35
+ const { translate } = await this.#getTranslator(lang);
36
+ const msg = translate(key);
37
+ return msg;
38
+ }
39
+ async getDictionary(lang) {
40
+ const { dictionary } = await this.#getTranslator(lang);
41
+ return dictionary;
42
+ }
43
+ }
44
+ const serverTranslator = new ServerTranslator();
45
+ export {
46
+ ServerTranslator,
47
+ serverTranslator
48
+ };
package/esm/src/trans.js CHANGED
@@ -313,7 +313,7 @@ const makeDictionary = (...dicts) => {
313
313
  });
314
314
  return rootDict;
315
315
  };
316
- const languages = ["ko", "en", "zhChs", "zhCht"];
316
+ const languages = ["en", "ko", "zhChs", "zhCht"];
317
317
  const msg = {
318
318
  info: () => null,
319
319
  success: () => null,
@@ -339,7 +339,17 @@ const makeTrans = (locale) => {
339
339
  throw new Error("Invalid message");
340
340
  return message;
341
341
  };
342
- return { revert, Revert, translate, msg };
342
+ const getDictionary = (lang) => {
343
+ const langIdx = languages.indexOf(lang);
344
+ const dictionary = {};
345
+ Object.entries(locale).forEach(([key, value]) => {
346
+ dictionary[key] = Object.fromEntries(
347
+ Object.entries(value).map(([key2, value2]) => [key2, value2[langIdx]])
348
+ );
349
+ });
350
+ return dictionary;
351
+ };
352
+ return { revert, Revert, translate, msg, getDictionary };
343
353
  };
344
354
  export {
345
355
  baseTrans,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/dictionary",
3
- "version": "0.9.43",
3
+ "version": "0.9.44",
4
4
  "sourceType": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,6 @@
1
1
  export declare const baseDictionary: {
2
+ "api-publishPing": [string, string];
3
+ "apidesc-publishPing": [string, string];
2
4
  "api-ping": [string, string];
3
5
  "apidesc-ping": [string, string];
4
6
  "api-pingBody": [string, string];
@@ -27,6 +29,10 @@ export declare const baseDictionary: {
27
29
  "argdesc-wsPing-data": [string, string];
28
30
  "api-pubsubPing": [string, string];
29
31
  "apidesc-pubsubPing": [string, string];
32
+ "api-getDictionary": [string, string];
33
+ "apidesc-getDictionary": [string, string];
34
+ "arg-getDictionary-lang": [string, string];
35
+ "argdesc-getDictionary-lang": [string, string];
30
36
  new: [string, string];
31
37
  somethingWrong: [string, string];
32
38
  connecting: [string, string];
@@ -36,4 +42,6 @@ export declare const baseDictionary: {
36
42
  tryReconnecting: [string, string];
37
43
  serverHasProblem: [string, string];
38
44
  checkServerStatus: [string, string];
45
+ success: [string, string];
46
+ failed: [string, string];
39
47
  };
@@ -1,5 +1,7 @@
1
1
  export declare const dictionary: {
2
2
  readonly base: {
3
+ "api-publishPing": [string, string];
4
+ "apidesc-publishPing": [string, string];
3
5
  "api-ping": [string, string];
4
6
  "apidesc-ping": [string, string];
5
7
  "api-pingBody": [string, string];
@@ -28,6 +30,10 @@ export declare const dictionary: {
28
30
  "argdesc-wsPing-data": [string, string];
29
31
  "api-pubsubPing": [string, string];
30
32
  "apidesc-pubsubPing": [string, string];
33
+ "api-getDictionary": [string, string];
34
+ "apidesc-getDictionary": [string, string];
35
+ "arg-getDictionary-lang": [string, string];
36
+ "argdesc-getDictionary-lang": [string, string];
31
37
  new: [string, string];
32
38
  somethingWrong: [string, string];
33
39
  connecting: [string, string];
@@ -37,17 +43,23 @@ export declare const dictionary: {
37
43
  tryReconnecting: [string, string];
38
44
  serverHasProblem: [string, string];
39
45
  checkServerStatus: [string, string];
46
+ success: [string, string];
47
+ failed: [string, string];
40
48
  };
41
49
  };
42
50
  export declare const Revert: {
43
- new (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", data?: any): Error;
51
+ new (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", data?: any): Error;
44
52
  prototype: Error;
45
- }, translate: (lang: "en" | "ko" | "zhChs" | "zhCht", key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", data?: {
53
+ }, translate: (lang: "en" | "ko" | "zhChs" | "zhCht", key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", data?: {
46
54
  [key: string]: any;
47
55
  }) => string, msg: {
48
- info: (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", option?: import("./trans").TransMessageOption) => void;
49
- success: (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", option?: import("./trans").TransMessageOption) => void;
50
- error: (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", option?: import("./trans").TransMessageOption) => void;
51
- warning: (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", option?: import("./trans").TransMessageOption) => void;
52
- loading: (key: "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data", option?: import("./trans").TransMessageOption) => void;
56
+ info: (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", option?: import("./trans").TransMessageOption) => void;
57
+ success: (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", option?: import("./trans").TransMessageOption) => void;
58
+ error: (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", option?: import("./trans").TransMessageOption) => void;
59
+ warning: (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", option?: import("./trans").TransMessageOption) => void;
60
+ loading: (key: "base.apidesc-publishPing" | "base.api-publishPing" | "base.apidesc-ping" | "base.api-ping" | "base.apidesc-pingBody" | "base.api-pingBody" | "base.apidesc-pingParam" | "base.api-pingParam" | "base.apidesc-pingQuery" | "base.api-pingQuery" | "base.apidesc-pingEvery" | "base.api-pingEvery" | "base.apidesc-pingUser" | "base.api-pingUser" | "base.apidesc-pingAdmin" | "base.api-pingAdmin" | "base.apidesc-cleanup" | "base.api-cleanup" | "base.apidesc-wsPing" | "base.api-wsPing" | "base.apidesc-pubsubPing" | "base.api-pubsubPing" | "base.apidesc-getDictionary" | "base.api-getDictionary" | "base.arg-pingBody-data" | "base.argdesc-pingBody-data" | "base.arg-pingParam-id" | "base.argdesc-pingParam-id" | "base.arg-pingQuery-id" | "base.argdesc-pingQuery-id" | "base.arg-wsPing-data" | "base.argdesc-wsPing-data" | "base.arg-getDictionary-lang" | "base.argdesc-getDictionary-lang" | "base.new" | "base.somethingWrong" | "base.connecting" | "base.connected" | "base.serverDisconnected" | "base.refreshing" | "base.tryReconnecting" | "base.serverHasProblem" | "base.checkServerStatus" | "base.success" | "base.failed", option?: import("./trans").TransMessageOption) => void;
61
+ }, getDictionary: (lang: "en" | "ko" | "zhChs" | "zhCht") => {
62
+ [key: string]: {
63
+ [key: string]: string;
64
+ };
53
65
  };
package/src/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./trans";
2
- export { dictionary } from "./dictionary";
2
+ export { Revert, translate, dictionary, getDictionary } from "./dictionary";
3
+ export { serverTranslator, type ServerTranslator } from "./serverTranslator";
@@ -0,0 +1,8 @@
1
+ export declare class ServerTranslator {
2
+ #private;
3
+ init(lang: string): Promise<void>;
4
+ getTransSync(lang: string, key: string): string | undefined;
5
+ getTrans(lang: string, key: string): Promise<string>;
6
+ getDictionary(lang: string): Promise<Record<string, Record<string, string>>>;
7
+ }
8
+ export declare const serverTranslator: ServerTranslator;
package/src/trans.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type BaseFilterKey, type GetActionObject, type GetStateObject } from "@akanjs/constant";
1
+ import type { GetActionObject, GetStateObject } from "@akanjs/base";
2
+ import { type BaseFilterKey } from "@akanjs/constant";
2
3
  import { DefaultSignal } from "@akanjs/signal";
3
4
  type TranslationSingle = readonly [string, string] | readonly [string, string, string, string];
4
5
  type TranslationWithParam = readonly [string, string, {
@@ -23,9 +24,6 @@ export type ModelDictionary<Model, Insight = unknown, Filter = unknown> = {
23
24
  modelName: Translation;
24
25
  modelDesc: Translation;
25
26
  };
26
- export type SummaryDictionary<Summary> = {
27
- [K in keyof GetStateObject<Summary> as K extends string ? K | `desc-${K}` : never]: Translation;
28
- };
29
27
  export type SignalDictionary<Checker, Model = unknown> = {
30
28
  [K in keyof Omit<GetActionObject<Checker>, keyof Model> as K extends string ? `apidesc-${K}` | `api-${K}` : never]: Translation;
31
29
  } & Record<string, Translation>;
@@ -73,7 +71,7 @@ type MergeAll<T extends readonly DictType[]> = T extends readonly [
73
71
  ] ? Rest extends readonly [] ? First : MergeTwo<First, MergeAll<Rest>> : never;
74
72
  export declare const rootDictionary: DictType;
75
73
  export declare const makeDictionary: <T extends readonly [DictType, ...DictType[]]>(...dicts: T) => MergeAll<T>;
76
- declare const languages: readonly ["ko", "en", "zhChs", "zhCht"];
74
+ declare const languages: readonly ["en", "ko", "zhChs", "zhCht"];
77
75
  type Language = (typeof languages)[number];
78
76
  export interface TransMessageOption {
79
77
  key?: string;
@@ -109,5 +107,10 @@ export declare const makeTrans: <Locale extends {
109
107
  warning: (key: TransMessage<Locale>, option?: TransMessageOption) => void;
110
108
  loading: (key: TransMessage<Locale>, option?: TransMessageOption) => void;
111
109
  };
110
+ getDictionary: (lang: Language) => {
111
+ [key: string]: {
112
+ [key: string]: string;
113
+ };
114
+ };
112
115
  };
113
116
  export {};