@steedos/i18n 2.2.50 → 2.2.51-beta.4
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/package.json +4 -5
- package/lib/core_i18n.d.ts +0 -3
- package/lib/export_object_i18n.d.ts +0 -2
- package/lib/i18n/i18n.app.d.ts +0 -8
- package/lib/i18n/i18n.d.ts +0 -13
- package/lib/index.d.ts +0 -26
- package/lib/locales.d.ts +0 -1
- package/lib/router.d.ts +0 -6
- package/lib/translations/index.d.ts +0 -24
- package/lib/translations/objectTranslation.d.ts +0 -5
- package/lib/translations/templates/objectTranslation.d.ts +0 -3
- package/lib/translations/templates/translation.d.ts +0 -5
- package/lib/translations/translation.d.ts +0 -7
- package/src/core_i18n.ts +0 -23
- package/src/export_object_i18n.ts +0 -23
- package/src/i18n/i18n.app.ts +0 -82
- package/src/i18n/i18n.ts +0 -289
- package/src/index.ts +0 -180
- package/src/locales.ts +0 -10
- package/src/router.ts +0 -10
- package/src/translations/index.ts +0 -95
- package/src/translations/objectTranslation.ts +0 -401
- package/src/translations/templates/objectTranslation.ts +0 -93
- package/src/translations/templates/translation.ts +0 -36
- package/src/translations/translation.ts +0 -183
- package/src/type.d.ts +0 -8
- package/tsconfig.json +0 -36
package/src/index.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
let i18next = require("i18next");
|
|
2
|
-
const sprintf = require("i18next-sprintf-postprocessor");
|
|
3
|
-
const _ = require("underscore");
|
|
4
|
-
// const XHR = require('i18next-xhr-backend');
|
|
5
|
-
|
|
6
|
-
const loadResources = {};
|
|
7
|
-
|
|
8
|
-
if(!i18next.use){
|
|
9
|
-
i18next = i18next.default
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
i18next.use(sprintf).init({
|
|
13
|
-
lng: 'en',
|
|
14
|
-
debug: process.env.I18N_DEBUG || false,
|
|
15
|
-
fallbackNS: [], //'translation'
|
|
16
|
-
fallbackLng: [],
|
|
17
|
-
interpolation: {
|
|
18
|
-
prefix: "{$",
|
|
19
|
-
suffix: "}"
|
|
20
|
-
},
|
|
21
|
-
// resources: {
|
|
22
|
-
// en: {
|
|
23
|
-
// translation: {}
|
|
24
|
-
// },
|
|
25
|
-
// 'zh-CN': {
|
|
26
|
-
// translation: {}
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
}, function (err: any, t: any) {
|
|
30
|
-
if(process.env.I18N_DEBUG){
|
|
31
|
-
console.log('i18n initialized and ready to go');
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const _t = function(key: any, options: StringMap){
|
|
36
|
-
return i18next.t(key, options)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const t = function(key: any, parameters: any, locale: string){
|
|
40
|
-
if(!key){
|
|
41
|
-
return key;
|
|
42
|
-
}
|
|
43
|
-
if (locale === "zh-cn") {
|
|
44
|
-
locale = "zh-CN";
|
|
45
|
-
}
|
|
46
|
-
let keys;
|
|
47
|
-
if(_.isArray(key)){
|
|
48
|
-
keys = key;
|
|
49
|
-
}else{
|
|
50
|
-
keys = [`CustomLabels.${key}`, key];
|
|
51
|
-
}
|
|
52
|
-
if ((parameters != null) && !(_.isObject(parameters))) {
|
|
53
|
-
return _t(keys, { lng: locale, postProcess: 'sprintf', sprintf: [parameters], keySeparator: false});
|
|
54
|
-
} else {
|
|
55
|
-
return _t(keys, Object.assign({lng: locale}, {keySeparator: false}, parameters));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Adds a complete bundle.
|
|
61
|
-
* Setting deep (default false) param to true will extend existing translations in that file. Setting deep and overwrite (default false) to true it will overwrite existing translations in that file.
|
|
62
|
-
* So omitting deep and overwrite will overwrite all existing translations with the one provided in resources. Using deep you can choose to keep existing nested translation and to overwrite those with the new ones.
|
|
63
|
-
* @param lng
|
|
64
|
-
* @param ns
|
|
65
|
-
* @param resources
|
|
66
|
-
* @param deep
|
|
67
|
-
* @param overwrite
|
|
68
|
-
*/
|
|
69
|
-
export const addResourceBundle = function(lng: string, ns: string, resources: any, deep?: boolean, overwrite?: boolean){
|
|
70
|
-
return i18next.addResourceBundle(lng, ns, resources, deep, overwrite);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const getResourceBundle = function(lng: string, ns: string){
|
|
74
|
-
return i18next.getResourceBundle(lng, ns);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const getDataByLanguage = function(lng: string){
|
|
78
|
-
return i18next.getDataByLanguage(lng);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const exists = function(key: string, options: StringMap){
|
|
82
|
-
return i18next.exists(key, options);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const changeLanguage = function(lng: string, options: any = {}, callback?: Callback){
|
|
86
|
-
let rootUrl = options.rootUrl;
|
|
87
|
-
let ns = options.ns || 'translation';
|
|
88
|
-
// console.log('changeLanguage', lng, ns, options);
|
|
89
|
-
if(typeof window != 'undefined' && rootUrl){
|
|
90
|
-
if(!rootUrl.endsWith('/')){
|
|
91
|
-
rootUrl = `${rootUrl}/`
|
|
92
|
-
}
|
|
93
|
-
// let connector = i18next.services.backendConnector;
|
|
94
|
-
// connector.backend = new XHR(i18next.services, {
|
|
95
|
-
// loadPath: `${rootUrl}locales/${lng}/${ns}`
|
|
96
|
-
// });
|
|
97
|
-
// connector.load([lng],[ns],function(err){
|
|
98
|
-
// i18next.changeLanguage(lng, callback);
|
|
99
|
-
// })
|
|
100
|
-
let loadPath = `${rootUrl}locales/${lng}/${ns}`
|
|
101
|
-
if(loadResources[loadPath] > 0){
|
|
102
|
-
i18next.changeLanguage(lng, callback);
|
|
103
|
-
}else if(loadResources[loadPath] != 0){
|
|
104
|
-
loadResources[loadPath] = 0;
|
|
105
|
-
var request = new XMLHttpRequest();
|
|
106
|
-
request.overrideMimeType("application/json")
|
|
107
|
-
request.open('GET', loadPath, false);
|
|
108
|
-
request.send(null);
|
|
109
|
-
|
|
110
|
-
if(request.status === 200){
|
|
111
|
-
loadResources[loadPath] = 1;
|
|
112
|
-
}else{
|
|
113
|
-
loadResources[loadPath] = -1;
|
|
114
|
-
}
|
|
115
|
-
exports.addResourceBundle(lng, ns, JSON.parse(request.response) || {});
|
|
116
|
-
i18next.changeLanguage(lng, callback);
|
|
117
|
-
|
|
118
|
-
// if($ && $.ajax && _.isFunction($.ajax)){
|
|
119
|
-
// let res = $.ajax({async: false, type: 'GET', url: loadPath, dataType: "json", contentType: "application/json"});
|
|
120
|
-
// if(res.status === 200){
|
|
121
|
-
// loadResources[loadPath] = 1;
|
|
122
|
-
// }else{
|
|
123
|
-
// loadResources[loadPath] = -1;
|
|
124
|
-
// }
|
|
125
|
-
// exports.addResourceBundle(lng, ns, res.responseJSON || {});
|
|
126
|
-
// i18next.changeLanguage(lng, callback);
|
|
127
|
-
// }else{
|
|
128
|
-
// let backend = new XHR(
|
|
129
|
-
// i18next.services,
|
|
130
|
-
// {
|
|
131
|
-
// loadPath: loadPath,
|
|
132
|
-
// },
|
|
133
|
-
// );
|
|
134
|
-
// backend.read(lng, ns, function(err, data) {
|
|
135
|
-
// if(err){
|
|
136
|
-
// loadResources[loadPath] = -1;
|
|
137
|
-
// }else{
|
|
138
|
-
// loadResources[loadPath] = 1
|
|
139
|
-
// }
|
|
140
|
-
// addResourceBundle(lng, ns, data);
|
|
141
|
-
// i18next.changeLanguage(lng, callback);
|
|
142
|
-
// });
|
|
143
|
-
// }
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}else{
|
|
147
|
-
return i18next.changeLanguage(lng, callback);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const format = function(value: any, format?: string, lng?: string){
|
|
152
|
-
return i18next.format(value, format, lng);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export const getLanguages = function(){
|
|
156
|
-
return i18next.languages;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export const loadLanguages = function(lngs: any, callback: any){
|
|
160
|
-
return i18next.loadLanguages(lngs, callback);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export const loadNamespaces = function(ns: any, callback: any){
|
|
164
|
-
return i18next.loadNamespaces(ns, callback);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
//Events
|
|
168
|
-
export const on = function(event: events, listener: (...args: any[]) => void){
|
|
169
|
-
return i18next.on(event, listener)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export const off = function(event: string, listener: (...args: any[]) => void){
|
|
173
|
-
return i18next.off(event, listener)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export * from './i18n/i18n'
|
|
177
|
-
|
|
178
|
-
export * from './i18n/i18n.app'
|
|
179
|
-
|
|
180
|
-
export * from './translations'
|
package/src/locales.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getResourceBundle, getDataByLanguage } from './index';
|
|
2
|
-
|
|
3
|
-
export const locales = async (req: any, res: any) => {
|
|
4
|
-
let ns = req.params.ns;
|
|
5
|
-
if(ns == 'all'){
|
|
6
|
-
res.send(getDataByLanguage(req.params.lng));
|
|
7
|
-
}else{
|
|
8
|
-
res.send(getResourceBundle(req.params.lng, ns));
|
|
9
|
-
}
|
|
10
|
-
}
|
package/src/router.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { exportObjectI18n } from './export_object_i18n'
|
|
2
|
-
import { locales } from './locales'
|
|
3
|
-
|
|
4
|
-
export const initExportObjectI18nTemplateRouter = function({ app }){
|
|
5
|
-
app.use("/locales/export/:lng/:objectName", exportObjectI18n);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const initLocalesRouter = function({ app }){
|
|
9
|
-
app.use("/locales/:lng/:ns", locales);
|
|
10
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: baozhoutao@steedos.com
|
|
3
|
-
* @Date: 2022-03-28 09:35:34
|
|
4
|
-
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2022-06-10 09:51:51
|
|
6
|
-
* @Description:
|
|
7
|
-
*/
|
|
8
|
-
import * as _ from 'underscore';
|
|
9
|
-
|
|
10
|
-
export * from './objectTranslation';
|
|
11
|
-
export * from './translation';
|
|
12
|
-
export * from './templates/objectTranslation';
|
|
13
|
-
export * from './templates/translation';
|
|
14
|
-
|
|
15
|
-
const getOption = function (option) {
|
|
16
|
-
var foo;
|
|
17
|
-
foo = option.split(":");
|
|
18
|
-
if (foo.length > 1) {
|
|
19
|
-
return {
|
|
20
|
-
label: foo[0],
|
|
21
|
-
value: foo[1]
|
|
22
|
-
};
|
|
23
|
-
} else {
|
|
24
|
-
return {
|
|
25
|
-
label: foo[0],
|
|
26
|
-
value: foo[0]
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const convertObject = function (object: StringMap) {
|
|
32
|
-
_.forEach(object.fields, function (field, key) {
|
|
33
|
-
let _options = [];
|
|
34
|
-
if (field.options && _.isString(field.options)) {
|
|
35
|
-
try {
|
|
36
|
-
//支持\n或者英文逗号分割,
|
|
37
|
-
_.forEach(field.options.split("\n"), function (option) {
|
|
38
|
-
var options;
|
|
39
|
-
if (option.indexOf(",")) {
|
|
40
|
-
options = option.split(",");
|
|
41
|
-
_.forEach(options, function (_option) {
|
|
42
|
-
return _options.push(getOption(_option));
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
_options.push(getOption(option));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
field.options = _options;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error("convertFieldsOptions error: ", field.options, error);
|
|
51
|
-
}
|
|
52
|
-
}else if(field.options && _.isArray(field.options)){
|
|
53
|
-
try {
|
|
54
|
-
_.forEach(field.options, function(option){
|
|
55
|
-
if(_.isString(option)){
|
|
56
|
-
_options.push(getOption(option))
|
|
57
|
-
}else{
|
|
58
|
-
_options.push(option)
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
field.options = _options;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error("Creator.convertFieldsOptions", field.options, error)
|
|
64
|
-
}
|
|
65
|
-
}else if (field.options && !_.isFunction(field.options) && !_.isArray(field.options) && _.isObject(field.options)) {
|
|
66
|
-
_.each(field.options, function (v, k) {
|
|
67
|
-
return _options.push({
|
|
68
|
-
label: v,
|
|
69
|
-
value: k
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
field.options = _options;
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export enum SteedosTranslationPrefixKeys {
|
|
78
|
-
Object = 'CustomObject',
|
|
79
|
-
Field = 'CustomField',
|
|
80
|
-
Action = 'CustomAction',
|
|
81
|
-
Listview = 'CustomListview',
|
|
82
|
-
Permission = 'CustomPermission',
|
|
83
|
-
ValidationRule = 'CustomValidationRule',
|
|
84
|
-
Application = 'CustomApplication',
|
|
85
|
-
Permissionset = 'CustomPermissionset',
|
|
86
|
-
Profile = 'CustomProfile',
|
|
87
|
-
Report = 'CustomReport',
|
|
88
|
-
Workflow = 'Workflow',
|
|
89
|
-
Layout = 'Layout',
|
|
90
|
-
Client = 'Client',
|
|
91
|
-
Server = 'Server',
|
|
92
|
-
Function = 'Function',
|
|
93
|
-
Router = 'Router',
|
|
94
|
-
Trigger = 'Trigger'
|
|
95
|
-
}
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import * as _ from 'underscore';
|
|
2
|
-
import { SteedosTranslationPrefixKeys } from './';
|
|
3
|
-
import { _t, exists, addResourceBundle } from '../index';
|
|
4
|
-
import { convertObject } from './index';
|
|
5
|
-
import { fallbackKeys } from '../i18n/i18n';
|
|
6
|
-
const crypto = require('crypto')
|
|
7
|
-
import { getCacher } from '@steedos/cachers';
|
|
8
|
-
|
|
9
|
-
const Cacher = getCacher('lru.translations.objects');
|
|
10
|
-
|
|
11
|
-
function getMD5(data){
|
|
12
|
-
let md5 = crypto.createHash('md5');
|
|
13
|
-
return md5.update(data).digest('hex');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const getCacherKey = function(lng, objectConfig){
|
|
17
|
-
return `${lng}_${objectConfig.name}_${getMD5(JSON.stringify(objectConfig))}`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const clone = require("clone");
|
|
21
|
-
|
|
22
|
-
const KEYSEPARATOR: string = '.';
|
|
23
|
-
|
|
24
|
-
const BASE_OBJECT = 'base';
|
|
25
|
-
const CORE_OBJECT = 'core';
|
|
26
|
-
|
|
27
|
-
const OBJECT_NS = 'translation';
|
|
28
|
-
|
|
29
|
-
const OBJECT_KEY = 'object';
|
|
30
|
-
const FIELD_KEY = 'field';
|
|
31
|
-
const LISTVIEW_KEY = 'listview';
|
|
32
|
-
const ACTION_KEY = 'action';
|
|
33
|
-
|
|
34
|
-
const translation = function(key, lng){
|
|
35
|
-
let options: any = {lng: lng, ns: OBJECT_NS}
|
|
36
|
-
if(KEYSEPARATOR === '.'){
|
|
37
|
-
options.keySeparator = false
|
|
38
|
-
}
|
|
39
|
-
if(exists(key, options)){
|
|
40
|
-
return _t(key, options)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// const isMeteor = () => {
|
|
45
|
-
// return (typeof Meteor != "undefined")
|
|
46
|
-
// }
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const getBaseObjectName = function(datasource){
|
|
50
|
-
if(!datasource){
|
|
51
|
-
return '';
|
|
52
|
-
}
|
|
53
|
-
let baseObjectName = CORE_OBJECT;
|
|
54
|
-
if(datasource === 'default' || datasource === 'meteor'){
|
|
55
|
-
baseObjectName = BASE_OBJECT;
|
|
56
|
-
}
|
|
57
|
-
return baseObjectName;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const getPrefix = function(key?){
|
|
61
|
-
switch (key) {
|
|
62
|
-
case OBJECT_KEY:
|
|
63
|
-
return SteedosTranslationPrefixKeys.Object
|
|
64
|
-
case FIELD_KEY:
|
|
65
|
-
return SteedosTranslationPrefixKeys.Field
|
|
66
|
-
case LISTVIEW_KEY:
|
|
67
|
-
return SteedosTranslationPrefixKeys.Listview
|
|
68
|
-
case ACTION_KEY:
|
|
69
|
-
return SteedosTranslationPrefixKeys.Action
|
|
70
|
-
default:
|
|
71
|
-
return 'CustomLabels';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const getObjectcustomLabelKey = function(key){
|
|
76
|
-
const prefix = getPrefix();
|
|
77
|
-
//objectName,
|
|
78
|
-
return [prefix, key].join(KEYSEPARATOR);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const getObjectLabelKey = function(objectName){
|
|
82
|
-
const prefix = getPrefix(OBJECT_KEY);
|
|
83
|
-
return [prefix, objectName, 'label'].join(KEYSEPARATOR);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const getObjectDescriptionKey = function(objectName){
|
|
87
|
-
const prefix = getPrefix(OBJECT_KEY);
|
|
88
|
-
return [prefix, objectName, 'description'].join(KEYSEPARATOR);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const getFieldLabelKey = function(objectName, name){
|
|
92
|
-
if(name){
|
|
93
|
-
name = name.replace(/\./g, '_');
|
|
94
|
-
}
|
|
95
|
-
const prefix = getPrefix(FIELD_KEY);
|
|
96
|
-
return [prefix, objectName, name, 'label'].join(KEYSEPARATOR);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const getFieldHelpKey = function(objectName, name){
|
|
100
|
-
if(name){
|
|
101
|
-
name = name.replace(/\./g, '_');
|
|
102
|
-
}
|
|
103
|
-
const prefix = getPrefix(FIELD_KEY);
|
|
104
|
-
return [prefix, objectName, name, 'help'].join(KEYSEPARATOR);
|
|
105
|
-
}
|
|
106
|
-
const getFieldDescriptionKey = function(objectName, name){
|
|
107
|
-
if(name){
|
|
108
|
-
name = name.replace(/\./g, '_');
|
|
109
|
-
}
|
|
110
|
-
const prefix = getPrefix(FIELD_KEY);
|
|
111
|
-
return [prefix, objectName, name, 'description'].join(KEYSEPARATOR);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const getFieldGroupKey = function(objectName, name){
|
|
115
|
-
//转小写后,替换掉 % . 空格
|
|
116
|
-
let groupKey = name.toLocaleLowerCase().replace(/\%/g, '_').replace(/\./g, '_').replace(/\ /g, '_')
|
|
117
|
-
const prefix = getPrefix(FIELD_KEY);
|
|
118
|
-
return [prefix, objectName, 'group', groupKey].join(KEYSEPARATOR);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const getFieldOptionsLabelKey = function(objectName, name, value){
|
|
122
|
-
if(name){
|
|
123
|
-
name = name.replace(/\./g, '_');
|
|
124
|
-
}
|
|
125
|
-
const prefix = getPrefix(FIELD_KEY);
|
|
126
|
-
return [prefix, objectName, name, 'options', value].join(KEYSEPARATOR);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const getActionLabelKey = function(objectName, name){
|
|
130
|
-
const prefix = getPrefix(ACTION_KEY);
|
|
131
|
-
return [prefix, objectName, name].join(KEYSEPARATOR);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const getListviewLabelKey = function(objectName, name){
|
|
135
|
-
const prefix = getPrefix(LISTVIEW_KEY);
|
|
136
|
-
return [prefix, objectName, name].join(KEYSEPARATOR);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export const translationObjectLabel = function(lng, name, def){
|
|
140
|
-
let key = getObjectLabelKey(name);
|
|
141
|
-
let keys = [key];
|
|
142
|
-
let fallbackKey = fallbackKeys.getObjectLabelKey(name);
|
|
143
|
-
if(fallbackKey){
|
|
144
|
-
keys.push(fallbackKey);
|
|
145
|
-
}
|
|
146
|
-
return translation(keys, lng) || def || ''
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const translationObjectDescription = function(lng, name, def){
|
|
150
|
-
let key = getObjectDescriptionKey(name)
|
|
151
|
-
return translation(key, lng) || def || ''
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const translationFieldLabel = function(lng, objectName, name, def, datasource?, ignoreBase?){
|
|
155
|
-
let key = getFieldLabelKey(objectName, name);
|
|
156
|
-
let keys = [key];
|
|
157
|
-
let fallbackKey = fallbackKeys.getObjectFieldLabelKey(objectName, name);
|
|
158
|
-
if(fallbackKey){
|
|
159
|
-
keys.push(fallbackKey);
|
|
160
|
-
}
|
|
161
|
-
let label = translation(keys, lng);
|
|
162
|
-
if(ignoreBase != true && !label){
|
|
163
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
164
|
-
if(baseObjectName && objectName != BASE_OBJECT && objectName != CORE_OBJECT){
|
|
165
|
-
label = translationFieldLabel(lng, baseObjectName, name, def, datasource)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return label || def || ''
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const translationFieldHelp = function(lng, objectName, name, def, datasource?, ignoreBase?){
|
|
172
|
-
let key = getFieldHelpKey(objectName, name);
|
|
173
|
-
let keys = [key];
|
|
174
|
-
let fallbackKey = fallbackKeys.getObjectFieldInlineHelpTextLabelKey(objectName, name);
|
|
175
|
-
if(fallbackKey){
|
|
176
|
-
keys.push(fallbackKey);
|
|
177
|
-
}
|
|
178
|
-
let label = translation(keys, lng);
|
|
179
|
-
if(ignoreBase != true && !label){
|
|
180
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
181
|
-
if(baseObjectName && objectName != BASE_OBJECT && objectName != CORE_OBJECT){
|
|
182
|
-
label = translationFieldHelp(lng, baseObjectName, name, def, datasource)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return label || def || ''
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const translationFieldDescription = function(lng, objectName, name, def, datasource?, ignoreBase?){
|
|
189
|
-
let key = getFieldDescriptionKey(objectName, name);
|
|
190
|
-
let keys = [key];
|
|
191
|
-
let label = translation(keys, lng);
|
|
192
|
-
if(ignoreBase != true && !label){
|
|
193
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
194
|
-
if(baseObjectName && objectName != BASE_OBJECT && objectName != CORE_OBJECT){
|
|
195
|
-
label = translationFieldDescription(lng, baseObjectName, name, def, datasource)
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return label || def || ''
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const translationFieldGroup = function(lng, objectName, name, def){
|
|
202
|
-
let key = getFieldGroupKey(objectName, name);
|
|
203
|
-
let keys = [key];
|
|
204
|
-
let fallbackKey = fallbackKeys.getObjectFieldGroupKey(objectName, name);
|
|
205
|
-
if(fallbackKey){
|
|
206
|
-
keys.push(fallbackKey);
|
|
207
|
-
}
|
|
208
|
-
return translation(keys, lng) || def || ''
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const translationFieldOptionsLabel = function(lng, objectName, name, value, def, datasource?, ignoreBase?){
|
|
212
|
-
let key = getFieldOptionsLabelKey(objectName, name, value);
|
|
213
|
-
let keys = [key];
|
|
214
|
-
let fallbackKey = fallbackKeys.getObjectFieldOptionsLabelKey(objectName, name, value);
|
|
215
|
-
if(fallbackKey){
|
|
216
|
-
keys.push(fallbackKey);
|
|
217
|
-
}
|
|
218
|
-
let label = translation(keys, lng);
|
|
219
|
-
if(ignoreBase != true && !label){
|
|
220
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
221
|
-
if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
|
|
222
|
-
label = translationFieldOptionsLabel(lng, baseObjectName, name, value, def, datasource)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return label || def || ''
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const translationActionLabel = function(lng, objectName, name, def, datasource?, ignoreBase?){
|
|
229
|
-
let key = getActionLabelKey(objectName, name);
|
|
230
|
-
let keys = [key];
|
|
231
|
-
let fallbackKey = fallbackKeys.getObjectActionLabelKey(objectName, name);
|
|
232
|
-
if(fallbackKey){
|
|
233
|
-
keys.push(fallbackKey);
|
|
234
|
-
}
|
|
235
|
-
let label = translation(keys, lng);
|
|
236
|
-
if(ignoreBase != true && !label){
|
|
237
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
238
|
-
if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
|
|
239
|
-
label = translationActionLabel(lng, baseObjectName, name, def, datasource)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return label || def || ''
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const translationListviewLabel = function(lng, objectName, name, def, datasource?, ignoreBase?){
|
|
246
|
-
let key = getListviewLabelKey(objectName, name);
|
|
247
|
-
let keys = [key];
|
|
248
|
-
let fallbackKey = fallbackKeys.getObjectListviewLabelKey(objectName, name);
|
|
249
|
-
if(fallbackKey){
|
|
250
|
-
keys.push(fallbackKey);
|
|
251
|
-
}
|
|
252
|
-
let label = translation(keys, lng);
|
|
253
|
-
if(ignoreBase != true && !label){
|
|
254
|
-
let baseObjectName = getBaseObjectName(datasource);
|
|
255
|
-
if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
|
|
256
|
-
label = translationListviewLabel(lng, baseObjectName, name, def, datasource)
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return label || def || ''
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export const translationObject = function(lng: string, objectName: string, object: StringMap, convert?: boolean, ignoreBase = false){
|
|
263
|
-
const cacheKey = getCacherKey(lng, object);
|
|
264
|
-
const fromCacher = Cacher.get(cacheKey);
|
|
265
|
-
if(fromCacher){
|
|
266
|
-
return Object.assign(object, fromCacher);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if(convert){
|
|
270
|
-
convertObject(object);
|
|
271
|
-
}
|
|
272
|
-
object.label = translationObjectLabel(lng, objectName, object.label);
|
|
273
|
-
object.description = translationObjectDescription(lng, objectName, object.description);
|
|
274
|
-
_.each(object.fields, function(field, fieldName){
|
|
275
|
-
field.label = translationFieldLabel(lng, objectName, fieldName, field.label, object.datasource, ignoreBase);
|
|
276
|
-
if(field.inlineHelpText){
|
|
277
|
-
field.inlineHelpText = translationFieldHelp(lng, objectName, fieldName, field.inlineHelpText, object.datasource, ignoreBase)
|
|
278
|
-
}
|
|
279
|
-
if(field.group){
|
|
280
|
-
field.group = translationFieldGroup(lng, objectName, field.group, field.group);
|
|
281
|
-
}
|
|
282
|
-
if(field.options){
|
|
283
|
-
let _options = [];
|
|
284
|
-
_.each(field.options, function(op){
|
|
285
|
-
if(_.has(op, 'value')){
|
|
286
|
-
let _label = translationFieldOptionsLabel(lng, objectName, fieldName, op.value, op.label, object.datasource, ignoreBase)
|
|
287
|
-
_options.push(_.extend({}, op, {label: _label}))
|
|
288
|
-
}else{
|
|
289
|
-
_options.push(op)
|
|
290
|
-
}
|
|
291
|
-
})
|
|
292
|
-
field.options = _options;
|
|
293
|
-
}
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
_.each(object.actions, function(action, actionName){
|
|
297
|
-
action.label = translationActionLabel(lng, objectName, actionName, action.label, object.datasource, ignoreBase);
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
_.each(object.list_views, function(list_view, viewName){
|
|
301
|
-
list_view.label = translationListviewLabel(lng, objectName, viewName, list_view.label, object.datasource, ignoreBase);
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
Cacher.set(cacheKey, object)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export const translationObjects = function(lng: string, objects: StringMap){
|
|
308
|
-
_.each(objects, function(object, name){
|
|
309
|
-
translationObject(lng, name, object);
|
|
310
|
-
})
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export const getObjectTranslationTemplate = function(lng: string ,objectName: string, _object: StringMap){
|
|
314
|
-
let object = clone(_object);
|
|
315
|
-
convertObject(object);
|
|
316
|
-
let template = {};
|
|
317
|
-
template[getObjectLabelKey(objectName)] = translationObjectLabel(lng, objectName, object.label);
|
|
318
|
-
template[getObjectDescriptionKey(objectName)] = translationObjectDescription(lng, objectName, object.description);
|
|
319
|
-
_.each(object.fields, function(field, fieldName){
|
|
320
|
-
template[getFieldLabelKey(objectName, fieldName)] = translationFieldLabel(lng, objectName, fieldName, field.label);
|
|
321
|
-
if(field.inlineHelpText){
|
|
322
|
-
template[getFieldHelpKey(objectName, fieldName)] = translationFieldHelp(lng, objectName, fieldName, field.inlineHelpText, object.datasource)
|
|
323
|
-
}
|
|
324
|
-
if(field.description){
|
|
325
|
-
template[getFieldDescriptionKey(objectName, fieldName)] = translationFieldDescription(lng, objectName, fieldName, field.description, object.datasource)
|
|
326
|
-
}
|
|
327
|
-
if(field.group){
|
|
328
|
-
template[getFieldGroupKey(objectName, field.group)] = translationFieldGroup(lng, objectName, field.group, field.group);
|
|
329
|
-
}
|
|
330
|
-
if(field.options){
|
|
331
|
-
_.each(field.options, function(op){
|
|
332
|
-
if(_.has(op, 'value')){
|
|
333
|
-
template[getFieldOptionsLabelKey(objectName, fieldName, op.value)] = translationFieldOptionsLabel(lng, objectName, fieldName, op.value, op.label);
|
|
334
|
-
}
|
|
335
|
-
})
|
|
336
|
-
}
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
_.each(object.actions, function(action, actionName){
|
|
340
|
-
template[getActionLabelKey( objectName, actionName)] = translationActionLabel(lng, objectName, actionName, action.label);
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
_.each(object.list_views, function(list_view, viewName){
|
|
344
|
-
template[getListviewLabelKey(objectName, viewName)] = translationListviewLabel(lng, objectName, viewName, list_view.label);
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
return template;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function convertObjectTranslation(objectTranslation, filePath){
|
|
351
|
-
let object = clone(objectTranslation);
|
|
352
|
-
convertObject(object);
|
|
353
|
-
let template = {};
|
|
354
|
-
let objectName = object.name;
|
|
355
|
-
if(!objectName){
|
|
356
|
-
console.error('Error: Invalid objectTranslation:' + filePath);
|
|
357
|
-
}
|
|
358
|
-
template[getObjectLabelKey(objectName)] = object.label;
|
|
359
|
-
template[getObjectDescriptionKey(objectName)] = object.description;
|
|
360
|
-
_.each(object.fields, function(field, fieldName){
|
|
361
|
-
template[getFieldLabelKey(objectName, fieldName)] = field.label;
|
|
362
|
-
if(field.help){
|
|
363
|
-
template[getFieldHelpKey(objectName, fieldName)] = field.help;
|
|
364
|
-
}
|
|
365
|
-
if(field.description){
|
|
366
|
-
template[getFieldDescriptionKey(objectName, fieldName)] = field.description;
|
|
367
|
-
}
|
|
368
|
-
if(field.options){
|
|
369
|
-
_.each(field.options, function(op){
|
|
370
|
-
if(_.has(op, 'value')){
|
|
371
|
-
template[getFieldOptionsLabelKey(objectName, fieldName, op.value)] = op.label;
|
|
372
|
-
}
|
|
373
|
-
})
|
|
374
|
-
}
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
_.each(object.groups, function(value, key){
|
|
378
|
-
template[getFieldGroupKey(objectName, key)] = value;
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
_.each(object.actions, function(action, actionName){
|
|
382
|
-
template[getActionLabelKey( objectName, actionName)] = action.label;
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
_.each(object.listviews, function(list_view, viewName){
|
|
386
|
-
template[getListviewLabelKey(objectName, viewName)] = list_view.label;
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
_.each(object.CustomLabels, function(value, key){
|
|
391
|
-
template[getObjectcustomLabelKey(key)] = value;
|
|
392
|
-
})
|
|
393
|
-
return template;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export const addObjectsTranslation = function(i18nArray){
|
|
397
|
-
_.each(i18nArray, function(item){
|
|
398
|
-
let translation = convertObjectTranslation(item.data, item.__filename);
|
|
399
|
-
addResourceBundle(item.lng, OBJECT_NS, translation, true, true);
|
|
400
|
-
})
|
|
401
|
-
}
|