feat: add plugin.t() method
This commit is contained in:
parent
7f0d699590
commit
95a5cab44c
@ -1,3 +1,4 @@
|
|||||||
|
import { TFuncKey, TOptions } from 'i18next';
|
||||||
import type { Application } from './Application';
|
import type { Application } from './Application';
|
||||||
|
|
||||||
export class Plugin<T = any> {
|
export class Plugin<T = any> {
|
||||||
@ -38,4 +39,8 @@ export class Plugin<T = any> {
|
|||||||
async beforeLoad() {}
|
async beforeLoad() {}
|
||||||
|
|
||||||
async load() {}
|
async load() {}
|
||||||
|
|
||||||
|
t(text: TFuncKey | TFuncKey[], options: TOptions = {}) {
|
||||||
|
return this.app.i18n.t(text, { ns: this.options?.['packageName'], ...(options as any) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Model } from '@nocobase/database';
|
import { Model } from '@nocobase/database';
|
||||||
|
import { LoggerOptions } from '@nocobase/logger';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import type { TFuncKey, TOptions } from 'i18next';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { Application } from './application';
|
import { Application } from './application';
|
||||||
import { InstallOptions, getExposeChangelogUrl, getExposeReadmeUrl } from './plugin-manager';
|
import { InstallOptions, getExposeChangelogUrl, getExposeReadmeUrl } from './plugin-manager';
|
||||||
import { checkAndGetCompatible } from './plugin-manager/utils';
|
import { checkAndGetCompatible } from './plugin-manager/utils';
|
||||||
import { LoggerOptions, createLogger, getLoggerFilePath } from '@nocobase/logger';
|
|
||||||
|
|
||||||
export interface PluginInterface {
|
export interface PluginInterface {
|
||||||
beforeLoad?: () => void;
|
beforeLoad?: () => void;
|
||||||
@ -116,6 +117,10 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t(text: TFuncKey | TFuncKey[], options: TOptions = {}) {
|
||||||
|
return this.app.i18n.t(text, { ns: this.options['packageName'], ...(options as any) });
|
||||||
|
}
|
||||||
|
|
||||||
async toJSON(options: any = {}) {
|
async toJSON(options: any = {}) {
|
||||||
const { locale = 'en-US' } = options;
|
const { locale = 'en-US' } = options;
|
||||||
const { name, packageName, packageJson } = this.options;
|
const { name, packageName, packageJson } = this.options;
|
||||||
|
Loading…
Reference in New Issue
Block a user