Skip to content

Commit 8d3e784

Browse files
committed
feat: add externalAppOnly option to control translation plugin behavior
1 parent 69d4564 commit 8d3e784

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

index.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export default class I18nPlugin extends AdminForthPlugin {
9494

9595
adminforth: IAdminForth;
9696

97+
externalAppOnly: boolean;
98+
9799
// sorted by name list of all supported languages, without en e.g. 'al|ro|uk'
98100
fullCompleatedFieldValue: string;
99101

@@ -140,7 +142,8 @@ export default class I18nPlugin extends AdminForthPlugin {
140142
throw new Error(`Invalid language code ${lang}, please define valid ISO 639-1 language code (2 lowercase letters)`);
141143
}
142144
});
143-
145+
146+
this.externalAppOnly = this.options.externalAppOnly === true;
144147

145148
// find primary key field
146149
this.primaryKeyFieldName = resourceConfig.columns.find(c => c.primaryKey)?.name;
@@ -265,20 +268,22 @@ export default class I18nPlugin extends AdminForthPlugin {
265268
))
266269
};
267270
// add underLogin component
268-
(adminforth.config.customization.loginPageInjections.underInputs).push({
269-
file: this.componentPath('LanguageUnderLogin.vue'),
270-
meta: compMeta
271-
});
271+
if (!this.externalAppOnly) {
272+
(adminforth.config.customization.loginPageInjections.underInputs).push({
273+
file: this.componentPath('LanguageUnderLogin.vue'),
274+
meta: compMeta
275+
});
272276

273-
(adminforth.config.customization.globalInjections.userMenu).push({
274-
file: this.componentPath('LanguageInUserMenu.vue'),
275-
meta: compMeta
276-
});
277+
(adminforth.config.customization.globalInjections.userMenu).push({
278+
file: this.componentPath('LanguageInUserMenu.vue'),
279+
meta: compMeta
280+
});
277281

278-
adminforth.config.customization.globalInjections.everyPageBottom.push({
279-
file: this.componentPath('LanguageEveryPageLoader.vue'),
280-
meta: compMeta
281-
});
282+
adminforth.config.customization.globalInjections.everyPageBottom.push({
283+
file: this.componentPath('LanguageEveryPageLoader.vue'),
284+
meta: compMeta
285+
});
286+
}
282287

283288
// disable create allowedActions for translations
284289
resourceConfig.options.allowedActions.create = false;
@@ -735,7 +740,9 @@ JSON.stringify(strings.reduce((acc: object, s: { en_string: string }): object =>
735740
}
736741

737742
// in this plugin we will use plugin to fill the database with missing language messages
738-
this.tryProcessAndWatch(adminforth);
743+
if (!this.externalAppOnly) {
744+
this.tryProcessAndWatch(adminforth);
745+
}
739746

740747
adminforth.tr = async (msg: string | null | undefined, category: string, lang: string, params, pluralizationNumber: number): Promise<string> => {
741748
if (!msg) {

types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ export interface PluginOptions {
3636
* semiautomatically (creates a bulk action for generating translations)
3737
*/
3838
completeAdapter?: CompletionAdapter
39+
40+
/**
41+
* Optionally translation plugin available to translate only external applications (like SEO-facing or user-facing services),
42+
* not AdminForth applications
43+
*/
44+
externalAppOnly?: boolean;
3945
}

0 commit comments

Comments
 (0)