i18n的一些修改

This commit is contained in:
Xu Chang 2023-08-15 19:35:34 +08:00
parent 7e3659c164
commit 8cecf9fb97
12 changed files with 85 additions and 56 deletions

View File

@ -36,10 +36,7 @@ exports.desc = {
{
name: "relationId"
},
],
config: {
unique: true
}
]
}
]
};

View File

@ -1,7 +1,7 @@
import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey, SubQueryPredicateMetadata } from "../../types/Demand";
import { OneOf } from "../../types/Polyfill";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, AggregationResult } from "../../types/Entity";
import { GenericAction } from "../../actions/action";
import { ReadOnlyAction } from "../../actions/action";
import { String } from "../../types/DataType";
import { EntityShape } from "../../types/Entity";
import * as ModiEntity from "../ModiEntity/Schema";
@ -116,7 +116,7 @@ export declare type I18nIdSubQuery = Selection<I18nIdProjection>;
export declare type EntityDef = {
Schema: Schema;
OpSchema: OpSchema;
Action: OakMakeAction<GenericAction> | string;
Action: OakMakeAction<ReadOnlyAction> | string;
Selection: Selection;
Aggregation: Aggregation;
Operation: Operation;

View File

@ -37,6 +37,7 @@ exports.desc = {
type: "object"
}
},
actionType: "crud",
actions: action_1.genericActions
static: true,
actionType: "readOnly",
actions: action_1.readOnlyActions
};

View File

@ -158,14 +158,6 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
entity: "actionAuth";
entityId: ForeignKey<"ActionAuth">;
} | {
entity?: never;
entityId?: never;
i18n: I18n.CreateSingleOperation;
} | {
entity: "i18n";
entityId: ForeignKey<"I18n">;
i18n: I18n.UpdateOperation;
} | {
entity: "i18n";
entityId: ForeignKey<"I18n">;
@ -248,10 +240,6 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
actionAuth?: ActionAuth.CreateSingleOperation | ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
i18n?: I18n.CreateSingleOperation | I18n.UpdateOperation | I18n.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relation?: Relation.CreateSingleOperation | Relation.UpdateOperation | Relation.RemoveOperation;
entityId?: never;
@ -283,8 +271,6 @@ export declare type RemoveOperationData = {} & (({
modi?: Modi.UpdateOperation | Modi.RemoveOperation;
})) & ({
actionAuth?: ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
} | {
i18n?: I18n.UpdateOperation | I18n.RemoveOperation;
} | {
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
} | {

View File

@ -155,14 +155,6 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
entity: "actionAuth";
entityId: ForeignKey<"ActionAuth">;
} | {
entity?: never;
entityId?: never;
i18n: I18n.CreateSingleOperation;
} | {
entity: "i18n";
entityId: ForeignKey<"I18n">;
i18n: I18n.UpdateOperation;
} | {
entity: "i18n";
entityId: ForeignKey<"I18n">;
@ -239,10 +231,6 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
actionAuth?: ActionAuth.CreateSingleOperation | ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
i18n?: I18n.CreateSingleOperation | I18n.UpdateOperation | I18n.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relation?: Relation.CreateSingleOperation | Relation.UpdateOperation | Relation.RemoveOperation;
entityId?: never;
@ -272,8 +260,6 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & ({
actionAuth?: ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
} | {
i18n?: I18n.UpdateOperation | I18n.RemoveOperation;
} | {
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
} | {

View File

@ -42,7 +42,7 @@ exports.NUMERICAL_LITERL_DEFAULT_SCALE = 2;
exports.INT_LITERL_DEFAULT_WIDTH = 4;
// 暂放在这儿
exports.SYSTEM_RESERVE_ENTITIES = ['user', 'relation', 'oper', 'operEntity', 'modi', 'modiEntity',
'userRelation', 'actionAuth', 'relationAuth', 'relation', 'userEntityGrant'];
'userRelation', 'actionAuth', 'relationAuth', 'relation', 'userEntityGrant', 'i18n'];
// 项目依赖的第三方oak lib配置文件所在的固定路径
var OAK_EXTERNAL_LIBS_FILEPATH = function (path) {
return path_1.default.join(path, 'config/oakExternalLib.json');

View File

@ -77,9 +77,9 @@ var LocaleBuilder = /** @class */ (function () {
};
LocaleBuilder.prototype.parseFile = function (module, namespace, position, filename, filepath, watch) {
var _this = this;
var language = filename.split('.')[0];
var language = (filename.split('.')[0]).replace('_', '-'); // 历史原因会命名成zh_CN.json
var data = require(filepath);
var ns = "".concat(module, "-").concat(namespace);
var ns = module ? "".concat(module, "-").concat(namespace) : (0, string_1.firstLetterLowerCase)(namespace);
this.locales[ns] = [module, position, language, data];
if (watch) {
fs_1.default.watch(filepath, function () {
@ -99,8 +99,9 @@ var LocaleBuilder = /** @class */ (function () {
_this.parseFile(module, nsPrefix, position, file, filepath, watch);
}
else if (stat.isDirectory() && !inLocale) {
var nsPrefix2 = nsPrefix ? "".concat(nsPrefix, "-").concat(file) : file;
var isLocaleFolder = file === localeFolderName;
_this.traverse(module, isLocaleFolder ? nsPrefix : "".concat(nsPrefix, "-").concat(file), isLocaleFolder ? position : (0, path_1.join)(position, file), (0, path_1.join)(dirPath, file), isLocaleFolder, localeFolderName, watch);
_this.traverse(module, isLocaleFolder ? nsPrefix : nsPrefix2, isLocaleFolder ? position : (0, path_1.join)(position, file), (0, path_1.join)(dirPath, file), isLocaleFolder, localeFolderName, watch);
}
});
};
@ -109,20 +110,44 @@ var LocaleBuilder = /** @class */ (function () {
var packageJson = (0, path_1.join)(root, 'package.json');
var name = require(packageJson).name;
var pagePath = (0, path_1.join)(src ? 'src' : 'lib', 'pages');
this.traverse(name, 'p', 'pages', (0, path_1.join)(root, pagePath), false, 'locales', watch);
this.traverse(name, 'p', pagePath, (0, path_1.join)(root, pagePath), false, 'locales', watch);
var componentPath = (0, path_1.join)(src ? 'src' : 'lib', 'components');
this.traverse(name, 'c', 'components', (0, path_1.join)(root, componentPath), false, 'locales', watch);
var localePath = (0, path_1.join)(src ? 'src' : 'lib', 'locales');
this.traverse(name, 'c', componentPath, (0, path_1.join)(root, componentPath), false, 'locales', watch);
var localePath = (0, path_1.join)(root, src ? 'src' : 'lib', 'locales');
if (fs_1.default.existsSync(localePath)) {
var files = fs_1.default.readdirSync(localePath);
files.forEach(function (file) {
var filepath = (0, path_1.join)(localePath, file);
var stat = fs_1.default.statSync(filepath);
if (stat.isDirectory()) {
_this.traverse(name, "l-".concat(file), (0, path_1.join)('locales', file), (0, path_1.join)(root, localePath, file), true, file, watch);
_this.traverse(name, "l-".concat(file), (0, path_1.join)('locales', file), (0, path_1.join)(localePath, file), true, file, watch);
}
});
}
if (!this.asLib && src) {
// 不是lib的话将oak-app-domain中的对象的locale也收集起来
var domainPath = (0, path_1.join)(root, 'src', 'oak-app-domain');
if (fs_1.default.existsSync(domainPath)) {
this.traverse('', '', 'oak-app-domain', domainPath, false, 'locales', watch);
}
// 还有web和wechatMp的目录
var webSrcPath = (0, path_1.join)('web', 'src');
this.traverse(name, 'w', webSrcPath, (0, path_1.join)(root, webSrcPath), false, 'locales', watch);
// 小程序可能有多于一个按规范用wechatMp, wechatMp2这样命名
var wechatMpSrcPath = (0, path_1.join)('wechatMp', 'src');
this.traverse(name, 'wmp', wechatMpSrcPath, (0, path_1.join)(root, webSrcPath), false, 'locales', watch);
var iter = 1;
while (true) {
var mpSrcPath = "".concat(wechatMpSrcPath).concat(iter);
if (fs_1.default.existsSync((0, path_1.join)(root, mpSrcPath))) {
this.traverse(name, "wmp".concat(iter), mpSrcPath, (0, path_1.join)(root, mpSrcPath), false, 'locales', watch);
iter++;
}
else {
break;
}
}
}
};
LocaleBuilder.prototype.build = function (watch) {
this.buildproject(this.pwd, true, watch);

View File

@ -24,9 +24,6 @@ var entityDesc = {
name: 'relation',
},
],
config: {
unique: true,
},
},
],
};

View File

@ -14,4 +14,8 @@ var entityDesc = {
},
},
},
configuration: {
actionType: 'readOnly',
static: true,
}
};

View File

@ -38,7 +38,7 @@ export const INT_LITERL_DEFAULT_WIDTH = 4;
// 暂放在这儿
export const SYSTEM_RESERVE_ENTITIES = ['user', 'relation', 'oper', 'operEntity', 'modi', 'modiEntity',
'userRelation', 'actionAuth', 'relationAuth', 'relation', 'userEntityGrant'];
'userRelation', 'actionAuth', 'relationAuth', 'relation', 'userEntityGrant', 'i18n'];
// 项目依赖的第三方oak lib配置文件所在的固定路径
export const OAK_EXTERNAL_LIBS_FILEPATH = (path: string) => {

View File

@ -5,7 +5,7 @@ import { join } from 'path';
import { v4 } from 'uuid';
import fs from 'fs';
import { OAK_EXTERNAL_LIBS_FILEPATH } from './env';
import { unescapeUnicode } from '../utils/string';
import { firstLetterLowerCase, unescapeUnicode } from '../utils/string';
/**
* object展开编译为一棵语法树string和object两种键值对象
@ -193,9 +193,9 @@ export default class LocaleBuilder {
}
private parseFile(module: string, namespace: string, position: string, filename: string, filepath: string, watch?: boolean) {
const language = filename.split('.')[0];
const language = (filename.split('.')[0]).replace('_', '-'); // 历史原因会命名成zh_CN.json
const data = require(filepath);
const ns = `${module}-${namespace}`;
const ns = module ? `${module}-${namespace}` : firstLetterLowerCase(namespace);
this.locales[ns] = [module, position, language, data];
if (watch) {
@ -217,8 +217,9 @@ export default class LocaleBuilder {
this.parseFile(module, nsPrefix, position, file, filepath, watch);
}
else if (stat.isDirectory() && !inLocale) {
const nsPrefix2 = nsPrefix ? `${nsPrefix}-${file}` : file;
const isLocaleFolder = file === localeFolderName;
this.traverse(module, isLocaleFolder ? nsPrefix : `${nsPrefix}-${file}`, isLocaleFolder ? position : join(position, file), join(dirPath, file), isLocaleFolder, localeFolderName, watch);
this.traverse(module, isLocaleFolder ? nsPrefix : nsPrefix2, isLocaleFolder ? position : join(position, file), join(dirPath, file), isLocaleFolder, localeFolderName, watch);
}
}
);
@ -228,11 +229,11 @@ export default class LocaleBuilder {
const packageJson = join(root, 'package.json');
const { name } = require(packageJson);
const pagePath = join(src ? 'src' : 'lib', 'pages');
this.traverse(name, 'p', 'pages', join(root, pagePath), false, 'locales', watch);
this.traverse(name, 'p', pagePath, join(root, pagePath), false, 'locales', watch);
const componentPath = join(src ? 'src' : 'lib', 'components');
this.traverse(name, 'c', 'components', join(root, componentPath), false, 'locales', watch);
this.traverse(name, 'c', componentPath, join(root, componentPath), false, 'locales', watch);
const localePath = join(src ? 'src' : 'lib', 'locales');
const localePath = join(root, src ? 'src' : 'lib', 'locales');
if (fs.existsSync(localePath)) {
const files = fs.readdirSync(localePath);
files.forEach(
@ -240,11 +241,39 @@ export default class LocaleBuilder {
const filepath = join(localePath, file);
const stat = fs.statSync(filepath);
if (stat.isDirectory()) {
this.traverse(name, `l-${file}`, join('locales', file), join(root, localePath, file), true, file, watch);
this.traverse(name, `l-${file}`, join('locales', file), join(localePath, file), true, file, watch);
}
}
);
}
if (!this.asLib && src) {
// 不是lib的话将oak-app-domain中的对象的locale也收集起来
const domainPath = join(root, 'src', 'oak-app-domain');
if (fs.existsSync(domainPath)) {
this.traverse('', '', 'oak-app-domain', domainPath, false, 'locales', watch);
}
// 还有web和wechatMp的目录
const webSrcPath = join('web', 'src');
this.traverse(name, 'w', webSrcPath, join(root, webSrcPath), false, 'locales', watch);
// 小程序可能有多于一个按规范用wechatMp, wechatMp2这样命名
const wechatMpSrcPath = join('wechatMp', 'src');
this.traverse(name, 'wmp', wechatMpSrcPath, join(root, webSrcPath), false, 'locales', watch);
let iter = 1;
while (true) {
const mpSrcPath = `${wechatMpSrcPath}${iter}`;
if (fs.existsSync(join(root, mpSrcPath))) {
this.traverse(name, `wmp${iter}`, mpSrcPath, join(root, mpSrcPath), false, 'locales', watch);
iter++;
}
else {
break;
}
}
}
}
build(watch?: boolean) {

View File

@ -23,4 +23,8 @@ const entityDesc: EntityDesc<Schema> = {
},
},
},
configuration: {
actionType: 'readOnly',
static: true,
}
};