@koine/i18n 2.0.0-beta.30 → 2.0.0-beta.32

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.
@@ -21,7 +21,7 @@ type I18nSummaryFile = {
21
21
  words: number;
22
22
  characters: number;
23
23
  };
24
- export declare function i18nGenerateSummary(options: I18nGenerateSummaryOptions): Promise<{
24
+ export declare function generateSummary(options: I18nGenerateSummaryOptions): Promise<{
25
25
  data: I18nSummary;
26
26
  md: string;
27
27
  }>;
@@ -20,42 +20,47 @@ function getWords(value, options) {
20
20
  }
21
21
  return out;
22
22
  }
23
- function i18nSummaryGetDataEntry(options, file) {
23
+ function getSummaryDataEntry(options, file) {
24
24
  var locale = file.locale, path = file.path;
25
25
  var url = "".concat(options.sourceUrl, "/").concat(locale, "/").concat(path);
26
26
  var words = getWords(file.data);
27
27
  var wordsCount = words.split(" ").filter(Boolean).length;
28
28
  var characters = words.split(" ").filter(Boolean).join("").length;
29
29
  return {
30
+ characters: characters,
30
31
  locale: locale,
31
32
  path: path,
32
33
  url: url,
33
34
  words: wordsCount,
34
- characters: characters,
35
35
  };
36
36
  }
37
- function i18nSummaryGetData(options) {
37
+ function getSummaryData(options) {
38
38
  var files = options.files, defaultLocale = options.defaultLocale;
39
39
  var data = {};
40
40
  for (var i = 0; i < files.length; i++) {
41
41
  var file = files[i];
42
42
  var locale = file.locale;
43
- var entry = i18nSummaryGetDataEntry(options, file);
43
+ var entry = getSummaryDataEntry(options, file);
44
44
  data[locale] = data[locale] || {};
45
45
  data[locale].files = data[locale].files || [];
46
46
  data[locale].files.push(entry);
47
47
  }
48
- data = Object.fromEntries(Object.entries(data).sort(function (_a) {
49
- var _b = __read(_a, 1), a = _b[0];
50
- return a === defaultLocale ? -1 : 1;
48
+ data = Object.fromEntries(Object.entries(data).sort(function (_a, _b) {
49
+ var _c = __read(_a, 1), a = _c[0];
50
+ var _d = __read(_b, 1), b = _d[0];
51
+ return a === defaultLocale ? -1 : a.localeCompare(b);
51
52
  }));
52
53
  forin(data, function (locale, dataPerLocale) {
53
- data[locale].words = arraySum(dataPerLocale.files.map(function (f) { return f.words; }));
54
54
  data[locale].characters = arraySum(dataPerLocale.files.map(function (f) { return f.characters; }));
55
+ data[locale].files = data[locale].files.sort(function (a, b) {
56
+ return a.path.localeCompare(b.path);
57
+ });
58
+ data[locale].words = arraySum(dataPerLocale.files.map(function (f) { return f.words; }));
59
+ data[locale] = Object.fromEntries(Object.entries(data[locale]).sort());
55
60
  });
56
61
  return data;
57
62
  }
58
- function i18nSummaryGetDataByPath(data) {
63
+ function getSummaryDataByPath(data) {
59
64
  var out = {};
60
65
  forin(data, function (locale, dataPerLocale) {
61
66
  var files = dataPerLocale.files;
@@ -69,8 +74,8 @@ function i18nSummaryGetDataByPath(data) {
69
74
  out = Object.fromEntries(Object.entries(out).sort());
70
75
  return out;
71
76
  }
72
- function i18nGenerateSummaryMarkdownByPath(_options, data) {
73
- var dataByPath = i18nSummaryGetDataByPath(data);
77
+ function generateSummaryMarkdownByPath(_options, data) {
78
+ var dataByPath = getSummaryDataByPath(data);
74
79
  var output = "";
75
80
  var body = "";
76
81
  var locales = [];
@@ -90,11 +95,13 @@ function i18nGenerateSummaryMarkdownByPath(_options, data) {
90
95
  });
91
96
  output += "<table><thead><tr>";
92
97
  output += "<th ".concat(styleBorder, ">file path</th>");
93
- output += locales.map(function () { return "<th>lang</th><th>words</th><th ".concat(styleBorder, ">chars</th>"); });
98
+ output += locales
99
+ .map(function () { return "<th>lang</th><th>words</th><th ".concat(styleBorder, ">chars</th>"); })
100
+ .join("");
94
101
  output += "</tr></thead><tbody>".concat(body, "</tbody></table>\n");
95
102
  return output;
96
103
  }
97
- function i18nGenerateSummaryMarkdownByLocale(options, data) {
104
+ function generateSummaryMarkdownByLocale(options, data) {
98
105
  var output = "";
99
106
  var body = "";
100
107
  forin(data, function (locale, dataPerLocale) {
@@ -112,20 +119,20 @@ function i18nGenerateSummaryMarkdownByLocale(options, data) {
112
119
  output += "</tr></thead><tbody>".concat(body, "</tbody></table>\n");
113
120
  return output;
114
121
  }
115
- function i18nGenerateSummaryMarkdown(options, data) {
122
+ function generateSummaryMarkdown(options, data) {
116
123
  var output = "# Summary\n";
117
124
  output += "\n### By locale\n\n";
118
- output += i18nGenerateSummaryMarkdownByLocale(options, data);
125
+ output += generateSummaryMarkdownByLocale(options, data);
119
126
  output += "\n### By file path\n\n";
120
- output += i18nGenerateSummaryMarkdownByPath(options, data);
127
+ output += generateSummaryMarkdownByPath(options, data);
121
128
  return output;
122
129
  }
123
- export function i18nGenerateSummary(options) {
130
+ export function generateSummary(options) {
124
131
  return __awaiter(this, void 0, void 0, function () {
125
132
  var data, md;
126
133
  return __generator(this, function (_a) {
127
- data = i18nSummaryGetData(options);
128
- md = i18nGenerateSummaryMarkdown(options, data);
134
+ data = getSummaryData(options);
135
+ md = generateSummaryMarkdown(options, data);
129
136
  return [2, { data: data, md: md }];
130
137
  });
131
138
  });
@@ -1,5 +1,5 @@
1
1
  import type { I18nIndexedFile } from "./types.js";
2
- export declare function i18nGenerateTypes(options: {
2
+ export declare function generateTypes(options: {
3
3
  defaultLocale: string;
4
4
  files: I18nIndexedFile[];
5
5
  }): Promise<string>;
@@ -99,7 +99,7 @@ function getType(value) {
99
99
  out = out.replace(/;+/g, ";");
100
100
  return out;
101
101
  }
102
- export function i18nGenerateTypes(options) {
102
+ export function generateTypes(options) {
103
103
  return __awaiter(this, void 0, void 0, function () {
104
104
  var defaultLocale, files, defaultLocaleFiles, header, footer, out, i, _a, path, data, namespace, format;
105
105
  return __generator(this, function (_b) {
@@ -3,7 +3,7 @@ type I18nGetFsDataOutput = {
3
3
  locales: I18nIndexedLocale[];
4
4
  files: I18nIndexedFile[];
5
5
  };
6
- export declare function i18nGetFsData(options: {
6
+ export declare function getFsData(options: {
7
7
  cwd: string;
8
8
  onlyFilesForLocales?: string[];
9
9
  }): Promise<I18nGetFsDataOutput>;
@@ -2,8 +2,8 @@ import { __awaiter, __generator } from "tslib";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { glob } from "glob";
5
- import { i18nGetLocalesFolders } from "./i18nGetLocalesFolders.js";
6
- export function i18nGetFsData(options) {
5
+ import { getLocalesFolders } from "./getLocalesFolders.js";
6
+ export function getFsData(options) {
7
7
  return __awaiter(this, void 0, void 0, function () {
8
8
  var cwd, _a, onlyFilesForLocales, locales, dataOutput;
9
9
  var _this = this;
@@ -11,7 +11,7 @@ export function i18nGetFsData(options) {
11
11
  switch (_b.label) {
12
12
  case 0:
13
13
  cwd = options.cwd, _a = options.onlyFilesForLocales, onlyFilesForLocales = _a === void 0 ? [] : _a;
14
- return [4, i18nGetLocalesFolders({ cwd: cwd })];
14
+ return [4, getLocalesFolders({ cwd: cwd })];
15
15
  case 1:
16
16
  locales = _b.sent();
17
17
  dataOutput = { locales: locales, files: [] };
@@ -1,4 +1,4 @@
1
1
  import type { I18nIndexedLocale } from "./types.js";
2
- export declare function i18nGetLocalesFolders(options: {
2
+ export declare function getLocalesFolders(options: {
3
3
  cwd: string;
4
4
  }): Promise<I18nIndexedLocale[]>;
@@ -2,7 +2,7 @@ import { __awaiter, __generator } from "tslib";
2
2
  import { join } from "node:path";
3
3
  import { glob } from "glob";
4
4
  var ignoredFolderNames = ["node_modules"];
5
- export function i18nGetLocalesFolders(options) {
5
+ export function getLocalesFolders(options) {
6
6
  return __awaiter(this, void 0, void 0, function () {
7
7
  var cwd, folders, output;
8
8
  return __generator(this, function (_a) {
@@ -0,0 +1,7 @@
1
+ export { generateSummary } from "./generateSummary.js";
2
+ export { generateTypes } from "./generateTypes.js";
3
+ export { getFsData } from "./getFsData.js";
4
+ export { getLocalesFolders } from "./getLocalesFolders.js";
5
+ export { writeTypes } from "./writeTypes.js";
6
+ export { writeSummary } from "./writeSummary.js";
7
+ export * from "./types.js";
@@ -0,0 +1,7 @@
1
+ export { generateSummary } from "./generateSummary.js";
2
+ export { generateTypes } from "./generateTypes.js";
3
+ export { getFsData } from "./getFsData.js";
4
+ export { getLocalesFolders } from "./getLocalesFolders.js";
5
+ export { writeTypes } from "./writeTypes.js";
6
+ export { writeSummary } from "./writeSummary.js";
7
+ export * from "./types.js";
@@ -0,0 +1,14 @@
1
+ export type I18nLocale = string & {
2
+ branded: true;
3
+ };
4
+ export type I18nIndexedFile = {
5
+ path: string;
6
+ locale: I18nLocale;
7
+ data: {
8
+ [key: string]: any;
9
+ };
10
+ };
11
+ export type I18nIndexedLocale = {
12
+ path: string;
13
+ code: I18nLocale;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { type I18nGenerateSummaryConfig } from "./i18nGenerateSummary.js";
2
- export declare function i18nWriteSummary(options: {
1
+ import { type I18nGenerateSummaryConfig } from "./generateSummary.js";
2
+ export declare function writeSummary(options: {
3
3
  cwd: string;
4
4
  outputJson: string;
5
5
  outputMarkdown: string;
@@ -1,21 +1,21 @@
1
1
  import { __awaiter, __generator } from "tslib";
2
2
  import { join } from "node:path";
3
3
  import { fsWrite } from "@koine/node";
4
- import { i18nGenerateSummary, } from "./i18nGenerateSummary.js";
5
- import { i18nGetFsData } from "./i18nGetFsData.js";
6
- export function i18nWriteSummary(options) {
4
+ import { generateSummary, } from "./generateSummary.js";
5
+ import { getFsData } from "./getFsData.js";
6
+ export function writeSummary(options) {
7
7
  return __awaiter(this, void 0, void 0, function () {
8
8
  var cwd, defaultLocale, outputJson, outputMarkdown, sourceUrl, data, summary;
9
9
  return __generator(this, function (_a) {
10
10
  switch (_a.label) {
11
11
  case 0:
12
12
  cwd = options.cwd, defaultLocale = options.defaultLocale, outputJson = options.outputJson, outputMarkdown = options.outputMarkdown, sourceUrl = options.sourceUrl;
13
- return [4, i18nGetFsData({
13
+ return [4, getFsData({
14
14
  cwd: cwd,
15
15
  })];
16
16
  case 1:
17
17
  data = _a.sent();
18
- return [4, i18nGenerateSummary({
18
+ return [4, generateSummary({
19
19
  files: data.files,
20
20
  defaultLocale: defaultLocale,
21
21
  sourceUrl: sourceUrl,
@@ -1,4 +1,4 @@
1
- export declare function i18nWriteTypes(options: {
1
+ export declare function writeTypes(options: {
2
2
  cwd: string;
3
3
  defaultLocale: string;
4
4
  outputTypes: string;
@@ -1,22 +1,22 @@
1
1
  import { __awaiter, __generator } from "tslib";
2
2
  import { join } from "node:path";
3
3
  import { fsWrite } from "@koine/node";
4
- import { i18nGenerateTypes } from "./i18nGenerateTypes.js";
5
- import { i18nGetFsData } from "./i18nGetFsData.js";
6
- export function i18nWriteTypes(options) {
4
+ import { generateTypes } from "./generateTypes.js";
5
+ import { getFsData } from "./getFsData.js";
6
+ export function writeTypes(options) {
7
7
  return __awaiter(this, void 0, void 0, function () {
8
8
  var cwd, defaultLocale, outputTypes, data, types;
9
9
  return __generator(this, function (_a) {
10
10
  switch (_a.label) {
11
11
  case 0:
12
12
  cwd = options.cwd, defaultLocale = options.defaultLocale, outputTypes = options.outputTypes;
13
- return [4, i18nGetFsData({
13
+ return [4, getFsData({
14
14
  cwd: cwd,
15
15
  onlyFilesForLocales: [defaultLocale],
16
16
  })];
17
17
  case 1:
18
18
  data = _a.sent();
19
- return [4, i18nGenerateTypes({ files: data.files, defaultLocale: defaultLocale })];
19
+ return [4, generateTypes({ files: data.files, defaultLocale: defaultLocale })];
20
20
  case 2:
21
21
  types = _a.sent();
22
22
  return [4, fsWrite(join(cwd, outputTypes), types)];
package/index.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  export { createTo } from "./createTo.js";
2
- export { i18nGenerateSummary } from "./i18nGenerateSummary.js";
3
- export { i18nGenerateTypes } from "./i18nGenerateTypes.js";
4
- export { i18nGetFsData } from "./i18nGetFsData.js";
5
- export { i18nGetLocalesFolders } from "./i18nGetLocalesFolders.js";
6
- export { i18nWriteTypes } from "./i18nWriteTypes.js";
7
- export { i18nWriteSummary } from "./i18nWriteSummary.js";
2
+ export { isDynamicRouteId } from "./isDynamicRouteId.js";
3
+ export { isStaticRouteId } from "./isStaticRouteId.js";
4
+ export { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
8
5
  export * from "./types.js";
package/index.js CHANGED
@@ -1,8 +1,5 @@
1
1
  export { createTo } from "./createTo.js";
2
- export { i18nGenerateSummary } from "./i18nGenerateSummary.js";
3
- export { i18nGenerateTypes } from "./i18nGenerateTypes.js";
4
- export { i18nGetFsData } from "./i18nGetFsData.js";
5
- export { i18nGetLocalesFolders } from "./i18nGetLocalesFolders.js";
6
- export { i18nWriteTypes } from "./i18nWriteTypes.js";
7
- export { i18nWriteSummary } from "./i18nWriteSummary.js";
2
+ export { isDynamicRouteId } from "./isDynamicRouteId.js";
3
+ export { isStaticRouteId } from "./isStaticRouteId.js";
4
+ export { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
8
5
  export * from "./types.js";
@@ -0,0 +1,3 @@
1
+ import type { ToRoute, ToRouteDynamic } from "./types.js";
2
+ export declare function isDynamicRouteId(routeId: ToRoute): routeId is ToRouteDynamic;
3
+ export default isDynamicRouteId;
@@ -0,0 +1,5 @@
1
+ import { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
2
+ export function isDynamicRouteId(routeId) {
3
+ return routeHasDynamicPortion(routeId);
4
+ }
5
+ export default isDynamicRouteId;
@@ -0,0 +1,3 @@
1
+ import type { ToRoute, ToRouteStatic } from "./types.js";
2
+ export declare function isStaticRouteId(routeId: ToRoute): routeId is ToRouteStatic;
3
+ export default isStaticRouteId;
@@ -0,0 +1,5 @@
1
+ import { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
2
+ export function isStaticRouteId(routeId) {
3
+ return !routeHasDynamicPortion(routeId);
4
+ }
5
+ export default isStaticRouteId;
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@koine/i18n",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/node": "2.0.0-beta.30",
6
- "@koine/utils": "2.0.0-beta.30"
5
+ "@koine/node": "2.0.0-beta.32",
6
+ "@koine/utils": "2.0.0-beta.32"
7
7
  },
8
8
  "peerDependenciesMeta": {
9
9
  "prettier": {
@@ -22,23 +22,38 @@
22
22
  "./createTo": {
23
23
  "import": "./createTo.js"
24
24
  },
25
- "./i18nGenerateSummary": {
26
- "import": "./i18nGenerateSummary.js"
25
+ "./generate/generateSummary": {
26
+ "import": "./generate/generateSummary.js"
27
27
  },
28
- "./i18nGenerateTypes": {
29
- "import": "./i18nGenerateTypes.js"
28
+ "./generate/generateTypes": {
29
+ "import": "./generate/generateTypes.js"
30
30
  },
31
- "./i18nGetFsData": {
32
- "import": "./i18nGetFsData.js"
31
+ "./generate/getFsData": {
32
+ "import": "./generate/getFsData.js"
33
33
  },
34
- "./i18nGetLocalesFolders": {
35
- "import": "./i18nGetLocalesFolders.js"
34
+ "./generate/getLocalesFolders": {
35
+ "import": "./generate/getLocalesFolders.js"
36
36
  },
37
- "./i18nWriteSummary": {
38
- "import": "./i18nWriteSummary.js"
37
+ "./generate": {
38
+ "import": "./generate/index.js"
39
39
  },
40
- "./i18nWriteTypes": {
41
- "import": "./i18nWriteTypes.js"
40
+ "./generate/types": {
41
+ "import": "./generate/types.js"
42
+ },
43
+ "./generate/writeSummary": {
44
+ "import": "./generate/writeSummary.js"
45
+ },
46
+ "./generate/writeTypes": {
47
+ "import": "./generate/writeTypes.js"
48
+ },
49
+ "./isDynamicRouteId": {
50
+ "import": "./isDynamicRouteId.js"
51
+ },
52
+ "./isStaticRouteId": {
53
+ "import": "./isStaticRouteId.js"
54
+ },
55
+ "./routeHasDynamicPortion": {
56
+ "import": "./routeHasDynamicPortion.js"
42
57
  },
43
58
  "./types": {
44
59
  "import": "./types.js"
@@ -48,5 +63,5 @@
48
63
  "prettier": "^3.1.1",
49
64
  "glob": "^10.3.10"
50
65
  },
51
- "version": "2.0.0-beta.30"
66
+ "version": "2.0.0-beta.32"
52
67
  }
@@ -0,0 +1,2 @@
1
+ export declare function routeHasDynamicPortion(routeIdOrPortion: string): boolean;
2
+ export default routeHasDynamicPortion;
@@ -0,0 +1,4 @@
1
+ export function routeHasDynamicPortion(routeIdOrPortion) {
2
+ return /\[/.test(routeIdOrPortion);
3
+ }
4
+ export default routeHasDynamicPortion;
package/types.d.ts CHANGED
@@ -1,18 +1,4 @@
1
1
  import type { Split } from "@koine/utils";
2
- export type I18nLocale = string & {
3
- branded: true;
4
- };
5
- export type I18nIndexedFile = {
6
- path: string;
7
- locale: I18nLocale;
8
- data: {
9
- [key: string]: any;
10
- };
11
- };
12
- export type I18nIndexedLocale = {
13
- path: string;
14
- code: I18nLocale;
15
- };
16
2
  type MergeDictionaries<T, K> = Omit<T, keyof K> & K;
17
3
  type Join<A, Sep extends string = "", R extends string = ""> = A extends [
18
4
  infer First,
@@ -60,9 +46,10 @@ export type TranslationOptions = undefined | TranslationShortcut | {
60
46
  default?: string;
61
47
  };
62
48
  export type Translate<TNamespace extends TranslateNamespace | undefined = TranslateNamespace> = TNamespace extends TranslateNamespace ? TranslateNamespaced<TNamespace> : TranslateDefault;
63
- export type TranslateDefault = <TPath extends TranslationsAllPaths>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TranslationAtPath<TPath>;
64
- export type TranslateNamespaced<TNamespace extends TranslateNamespace> = <TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TranslationAtPathFromNamespace<TNamespace, TPath>;
65
- export type TranslateLoose = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => string;
49
+ export type TranslateDefault = <TPath extends TranslationsAllPaths, TReturn = TranslationAtPath<TPath>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
50
+ export type TranslateNamespaced<TNamespace extends TranslateNamespace> = <TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>, TReturn = TranslationAtPathFromNamespace<TNamespace, TPath>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
51
+ export type TranslateLoose<TReturn = string> = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
52
+ export type TranslateLoosest<TReturn = any> = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
66
53
  export type TranslatedRoute = TranslationsPaths<TranslationsDictionary["~"], false>;
67
54
  export type TranslatedRoutesChildrenOf<TStarts extends string, T extends string = TranslatedRoute> = T extends `${TStarts}.${infer First}.${infer Second}` ? First | `${First}.${Second}` : T extends `${TStarts}.${infer First}` ? First : never;
68
55
  type OnlyStatic<T extends string> = T extends `${string}.[${string}].${string}` | `${string}.[${string}]` | `[${string}].${string}` | `[${string}]` ? never : T;
package/_helpers.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { ToRoute, ToRouteDynamic, ToRouteStatic } from "./types.js";
2
- export declare function routeHasDynamicPortion(routeIdOrPortion: string): boolean;
3
- export declare function isStaticRouteId(routeId: ToRoute): routeId is ToRouteStatic;
4
- export declare function isDynamicRouteId(routeId: ToRoute): routeId is ToRouteDynamic;
package/_helpers.js DELETED
@@ -1,9 +0,0 @@
1
- export function routeHasDynamicPortion(routeIdOrPortion) {
2
- return /\[/.test(routeIdOrPortion);
3
- }
4
- export function isStaticRouteId(routeId) {
5
- return !routeHasDynamicPortion(routeId);
6
- }
7
- export function isDynamicRouteId(routeId) {
8
- return routeHasDynamicPortion(routeId);
9
- }