This commit is contained in:
Xu Chang 2022-06-17 15:44:54 +08:00
parent 8671ce5a01
commit 47d0d27820
4 changed files with 74 additions and 0 deletions

10
lib/aspects/locales.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
export declare function getTranslations(options: {
namespace: string | string[];
locale: string;
}): {
common: {
action: {
confirm: string;
};
};
};

38
lib/aspects/locales.js Normal file
View File

@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTranslations = void 0;
function getTranslations(options) {
const { namespace, locale } = options;
// 表示entity locale表示zh_CN
let translations = {};
return {
common: {
action: {
confirm: '确定2',
},
},
};
// const getTranslations = (ns: string) => {
// const entityName = ns.substring(0, 1).toUpperCase() + ns.substring(1);
// const entityName2 = ns.toLowerCase();
// try {
// const data = require(`${entityName}/locales/${locale}.ts`).default;
// assign(translations, {
// [entityName2]: data,
// });
// }
// catch (err) {
// throw err
// }
// };
// if (namespace instanceof Array) {
// namespace.forEach((ns) => {
// getTranslations(ns);
// })
// }
// else {
// getTranslations(namespace);
// }
// return translations;
}
exports.getTranslations = getTranslations;

13
lib/features/locales.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
import { EntityDict, Aspect, Context } from 'oak-domain/lib/types';
import { Feature } from '../types/Feature';
export declare class Locales extends Feature<EntityDict, Context<EntityDict>, Record<string, Aspect<EntityDict, Context<EntityDict>>>> {
get(namespace: string | string[], locale: string, scene: string): Promise<{
translations: {
common: {
action: {
confirm: string;
};
};
};
}>;
}

13
lib/features/locales.js Normal file
View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Locales = void 0;
const Feature_1 = require("../types/Feature");
class Locales extends Feature_1.Feature {
async get(namespace, locale, scene) {
const translations = await this.getAspectProxy().getTranslations({ namespace, locale }, scene);
return {
translations,
};
}
}
exports.Locales = Locales;