@adminforth/i18n 2.0.21 → 2.0.23
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/index.d.ts +80 -0
- package/dist/types.d.ts +74 -0
- package/package.json +3 -3
- package/tsconfig.json +1 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { AdminForthPlugin } from "adminforth";
|
|
2
|
+
import type { IAdminForth, IHttpServer, AdminForthResourceColumn, AdminForthResource, AdminUser } from "adminforth";
|
|
3
|
+
import type { PluginOptions, SupportedLanguage } from './types.js';
|
|
4
|
+
interface IFailedTranslation {
|
|
5
|
+
lang: SupportedLanguage;
|
|
6
|
+
en_string: string;
|
|
7
|
+
failedReason: string;
|
|
8
|
+
}
|
|
9
|
+
interface ICachingAdapter {
|
|
10
|
+
get(key: string): Promise<any>;
|
|
11
|
+
set(key: string, value: any): Promise<void>;
|
|
12
|
+
clear(key: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export default class I18nPlugin extends AdminForthPlugin {
|
|
15
|
+
options: PluginOptions;
|
|
16
|
+
emailField: AdminForthResourceColumn;
|
|
17
|
+
passwordField: AdminForthResourceColumn;
|
|
18
|
+
authResource: AdminForthResource;
|
|
19
|
+
emailConfirmedField?: AdminForthResourceColumn;
|
|
20
|
+
trFieldNames: Partial<Record<SupportedLanguage, string>>;
|
|
21
|
+
enFieldName: string;
|
|
22
|
+
cache: ICachingAdapter;
|
|
23
|
+
primaryKeyFieldName: string;
|
|
24
|
+
menuItemWithBadgeId: string;
|
|
25
|
+
adminforth: IAdminForth;
|
|
26
|
+
externalAppOnly: boolean;
|
|
27
|
+
fullCompleatedFieldValue: string;
|
|
28
|
+
primaryLanguage: SupportedLanguage;
|
|
29
|
+
constructor(options: PluginOptions);
|
|
30
|
+
computeCompletedFieldValue(record: any): Promise<string>;
|
|
31
|
+
updateUntranslatedMenuBadge(): Promise<void>;
|
|
32
|
+
modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource): Promise<void>;
|
|
33
|
+
generateAndSaveBunch(prompt: string, strings: {
|
|
34
|
+
en_string: string;
|
|
35
|
+
category: string;
|
|
36
|
+
schemaKey?: string;
|
|
37
|
+
}[], translations: any[], updateStrings: Record<string, {
|
|
38
|
+
updates: any;
|
|
39
|
+
category: string;
|
|
40
|
+
strId: string;
|
|
41
|
+
enStr: string;
|
|
42
|
+
translatedStr: string;
|
|
43
|
+
}>, lang: string, failedToTranslate: IFailedTranslation[], needToTranslateByLang: Record<string, any>, jobId: string, promptCost: number): Promise<void>;
|
|
44
|
+
getTranslateToLangTasks(langIsoCode: SupportedLanguage, strings: {
|
|
45
|
+
id: string;
|
|
46
|
+
en_string: string;
|
|
47
|
+
category: string;
|
|
48
|
+
}[], plurals: boolean, translations: any[], updateStrings: Record<string, {
|
|
49
|
+
updates: any;
|
|
50
|
+
category: string;
|
|
51
|
+
strId: string;
|
|
52
|
+
enStr: string;
|
|
53
|
+
translatedStr: string;
|
|
54
|
+
}>, needToTranslateByLang: Record<string, any>, adminUser: AdminUser): Promise<any>;
|
|
55
|
+
bulkTranslate({ selectedIds, selectedLanguages, adminUser }: {
|
|
56
|
+
selectedIds: string[];
|
|
57
|
+
selectedLanguages?: SupportedLanguage[];
|
|
58
|
+
adminUser: AdminUser;
|
|
59
|
+
}): Promise<string>;
|
|
60
|
+
processExtractedMessages(adminforth: IAdminForth, filePath: string): Promise<void>;
|
|
61
|
+
tryProcessAndWatch(adminforth: IAdminForth): Promise<void>;
|
|
62
|
+
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource): void;
|
|
63
|
+
applyPluralization(str: string, number: number, lang: string): string;
|
|
64
|
+
slavicPluralRule(choice: any, choicesLength: any): 0 | 2 | 1 | 3;
|
|
65
|
+
instanceUniqueRepresentation(pluginOptions: any): string;
|
|
66
|
+
getCategoryTranslations(category: string, lang: string): Promise<Record<string, string>>;
|
|
67
|
+
languagesList(): Promise<{
|
|
68
|
+
code: SupportedLanguage;
|
|
69
|
+
nameOnNative: string;
|
|
70
|
+
nameEnglish: string;
|
|
71
|
+
emojiFlag: string;
|
|
72
|
+
svgFlagB64: string;
|
|
73
|
+
}[]>;
|
|
74
|
+
feedCategoryTranslations(messages: {
|
|
75
|
+
en_string: string;
|
|
76
|
+
source: string;
|
|
77
|
+
}[], category: string): Promise<void>;
|
|
78
|
+
setupEndpoints(server: IHttpServer): void;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CompletionAdapter } from 'adminforth';
|
|
2
|
+
import type { LanguageCode } from 'iso-639-1';
|
|
3
|
+
import { iso31661Alpha2ToAlpha3 } from 'iso-3166';
|
|
4
|
+
import { type PluginsCommonOptions } from "adminforth";
|
|
5
|
+
type Alpha2Code = keyof typeof iso31661Alpha2ToAlpha3;
|
|
6
|
+
type Bcp47LanguageTag = `${LanguageCode}-${Alpha2Code}`;
|
|
7
|
+
export type SupportedLanguage = LanguageCode | Bcp47LanguageTag;
|
|
8
|
+
export interface PluginOptions extends PluginsCommonOptions {
|
|
9
|
+
supportedLanguages: SupportedLanguage[];
|
|
10
|
+
/**
|
|
11
|
+
* Each translation string will be stored in a separate field, you can remap it to existing columns using this option
|
|
12
|
+
* By default it will assume field are named like `${lang_code}_string` (e.g. 'en_string', 'uk_string', 'ja_string', 'fr_string')
|
|
13
|
+
*/
|
|
14
|
+
translationFieldNames: Partial<Record<SupportedLanguage, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* Each string has a category, e.g. it might come from 'frontend' or some message from backend or column name on backend
|
|
17
|
+
* To deliver translations efficiently we need to store the category of each string.
|
|
18
|
+
* We recommend to put index on this column
|
|
19
|
+
*/
|
|
20
|
+
categoryFieldName: string;
|
|
21
|
+
/**
|
|
22
|
+
* Language selector on login page order
|
|
23
|
+
*/
|
|
24
|
+
loginPageLanguageSelectorOrder?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Optional source field to store e.g. file name where it first was captured
|
|
27
|
+
*/
|
|
28
|
+
sourceFieldName?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional field to save list of completed translations
|
|
31
|
+
* Helps to filter out strings which are not translated. If you define this field plugin will automatically
|
|
32
|
+
*/
|
|
33
|
+
completedFieldName?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Optionally translation plugin supports LLM completion adapter (like OpenAI) for generating translations
|
|
36
|
+
* semiautomatically (creates a bulk action for generating translations)
|
|
37
|
+
*/
|
|
38
|
+
completeAdapter?: CompletionAdapter;
|
|
39
|
+
/**
|
|
40
|
+
* Optionally translation plugin available to translate only external applications (like SEO-facing or user-facing services),
|
|
41
|
+
* not AdminForth applications
|
|
42
|
+
*/
|
|
43
|
+
externalAppOnly?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* You can enable "Reviewed" checkbox for each translation string by defing this field,
|
|
46
|
+
* it should be a JSON field (underlyng database type should be TEXT or JSON)
|
|
47
|
+
*/
|
|
48
|
+
reviewedCheckboxesFieldName?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Primary language for the application. This is the default language shown to users.
|
|
51
|
+
* English is always used as the source language for translations, even if primaryLanguage is different.
|
|
52
|
+
* When a translation is missing for the primaryLanguage, English will be shown as fallback.
|
|
53
|
+
* Defaults to 'en' if not specified.
|
|
54
|
+
*/
|
|
55
|
+
primaryLanguage?: SupportedLanguage;
|
|
56
|
+
/**
|
|
57
|
+
* Ask translator to treat some code from supportedLanguages as exact BCP47 tag. Read docs for details.
|
|
58
|
+
* key - one of the values form supportedLanguages, value -BCP47 tag
|
|
59
|
+
*/
|
|
60
|
+
translateLangAsBCP47Code?: Partial<Record<LanguageCode, Bcp47LanguageTag>>;
|
|
61
|
+
/**
|
|
62
|
+
* Batch size of one translation generation request.
|
|
63
|
+
* This is an optional parameter that can be used to control the size of strings sent in a single request to the completion adapter.
|
|
64
|
+
* Default value is 30000 tokens
|
|
65
|
+
*/
|
|
66
|
+
inputTokensPerBatch?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Limit of parallel translation generation requests.
|
|
69
|
+
* This is an optional parameter that can be used to control the number of concurrent requests sent to the completion adapter.
|
|
70
|
+
* Default value is 20
|
|
71
|
+
*/
|
|
72
|
+
parallelTranslationLimit?: number;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/i18n",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.23",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"p-limit": "^7.3.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"adminforth": "^
|
|
41
|
+
"adminforth": "^3.0.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^22.10.7",
|
|
45
|
-
"adminforth": "^
|
|
45
|
+
"adminforth": "^3.0.1",
|
|
46
46
|
"i18n-iso-countries": "^7.13.0",
|
|
47
47
|
"semantic-release": "^24.2.1",
|
|
48
48
|
"semantic-release-slack-bot": "^4.0.2",
|
package/tsconfig.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
|
|
4
4
|
"module": "node16", /* Specify what module code is generated. */
|
|
5
|
+
"declaration": true,
|
|
5
6
|
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
6
7
|
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
|
|
7
8
|
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|