@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 CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@steedos/i18n",
3
3
  "private": false,
4
- "version": "2.2.50",
4
+ "version": "2.2.51-beta.4",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
8
- "compile": "tsc",
9
- "prepare": "tsc",
8
+ "build": "tsc",
10
9
  "test": "echo \"Error: no test specified\" && exit 1"
11
10
  },
12
11
  "author": "",
13
12
  "license": "ISC",
14
13
  "dependencies": {
15
- "@steedos/cachers": "2.2.50",
14
+ "@steedos/cachers": "2.2.51-beta.4",
16
15
  "i18next": "^19.3.4",
17
16
  "i18next-sprintf-postprocessor": "^0.2.2",
18
17
  "i18next-xhr-backend": "^3.2.2"
@@ -23,5 +22,5 @@
23
22
  "publishConfig": {
24
23
  "access": "public"
25
24
  },
26
- "gitHead": "7859a5ac5bcc9c0089d52ce9246eee1c83022816"
25
+ "gitHead": "975061203a5c8ee2ed2ab495cfed25a100304c96"
27
26
  }
@@ -1,3 +0,0 @@
1
- export declare const InitCoreI18n: () => void;
2
- export declare const InitCoreTranslations: () => void;
3
- export declare const loadCoreTranslations: () => any;
@@ -1,2 +0,0 @@
1
- export declare const exportObjectI18n: (req: any, res: any) => Promise<void>;
2
- export declare const toYml: (date: StringMap, options?: any) => any;
@@ -1,8 +0,0 @@
1
- export declare const translationI18nMenus: (lng: string, menus: Array<any>) => void;
2
- export declare const translationI18nApps: (lng: string, apps: StringMap) => void;
3
- export declare const getAppI18nTemplate: (lng: string, appId: string, _app: StringMap) => {};
4
- export declare const appFallbackKeys: {
5
- getAppLabelKey: (appId: any) => string;
6
- getAppDescriptionKey: (appId: any) => string;
7
- getMenuLabelKey: (menuId: any) => string;
8
- };
@@ -1,13 +0,0 @@
1
- export declare const translationI18nObject: (lng: string, objectName: string, object: StringMap) => void;
2
- export declare const addObjectsI18n: (i18nArray: any) => void;
3
- export declare const translationI18nObjects: (lng: string, objects: StringMap) => void;
4
- export declare const getObjectI18nTemplate: (lng: string, objectName: string, _object: StringMap) => {};
5
- export declare const fallbackKeys: {
6
- getObjectLabelKey: (objectName: any) => string;
7
- getObjectFieldLabelKey: (objectName: any, name: any) => string;
8
- getObjectFieldInlineHelpTextLabelKey: (objectName: any, name: any) => string;
9
- getObjectFieldGroupKey: (objectName: any, name: any) => string;
10
- getObjectFieldOptionsLabelKey: (objectName: any, name: any, value: any) => string;
11
- getObjectActionLabelKey: (objectName: any, name: any) => string;
12
- getObjectListviewLabelKey: (objectName: any, name: any) => string;
13
- };
package/lib/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- export declare const _t: (key: any, options: StringMap) => any;
2
- export declare const t: (key: any, parameters: any, locale: string) => any;
3
- /**
4
- * Adds a complete bundle.
5
- * 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.
6
- * 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.
7
- * @param lng
8
- * @param ns
9
- * @param resources
10
- * @param deep
11
- * @param overwrite
12
- */
13
- export declare const addResourceBundle: (lng: string, ns: string, resources: any, deep?: boolean, overwrite?: boolean) => any;
14
- export declare const getResourceBundle: (lng: string, ns: string) => any;
15
- export declare const getDataByLanguage: (lng: string) => any;
16
- export declare const exists: (key: string, options: StringMap) => any;
17
- export declare const changeLanguage: (lng: string, options?: any, callback?: Callback) => any;
18
- export declare const format: (value: any, format?: string, lng?: string) => any;
19
- export declare const getLanguages: () => any;
20
- export declare const loadLanguages: (lngs: any, callback: any) => any;
21
- export declare const loadNamespaces: (ns: any, callback: any) => any;
22
- export declare const on: (event: events, listener: (...args: any[]) => void) => any;
23
- export declare const off: (event: string, listener: (...args: any[]) => void) => any;
24
- export * from './i18n/i18n';
25
- export * from './i18n/i18n.app';
26
- export * from './translations';
package/lib/locales.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const locales: (req: any, res: any) => Promise<void>;
package/lib/router.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare const initExportObjectI18nTemplateRouter: ({ app }: {
2
- app: any;
3
- }) => void;
4
- export declare const initLocalesRouter: ({ app }: {
5
- app: any;
6
- }) => void;
@@ -1,24 +0,0 @@
1
- export * from './objectTranslation';
2
- export * from './translation';
3
- export * from './templates/objectTranslation';
4
- export * from './templates/translation';
5
- export declare const convertObject: (object: StringMap) => void;
6
- export declare enum SteedosTranslationPrefixKeys {
7
- Object = "CustomObject",
8
- Field = "CustomField",
9
- Action = "CustomAction",
10
- Listview = "CustomListview",
11
- Permission = "CustomPermission",
12
- ValidationRule = "CustomValidationRule",
13
- Application = "CustomApplication",
14
- Permissionset = "CustomPermissionset",
15
- Profile = "CustomProfile",
16
- Report = "CustomReport",
17
- Workflow = "Workflow",
18
- Layout = "Layout",
19
- Client = "Client",
20
- Server = "Server",
21
- Function = "Function",
22
- Router = "Router",
23
- Trigger = "Trigger"
24
- }
@@ -1,5 +0,0 @@
1
- export declare const translationObjectLabel: (lng: any, name: any, def: any) => any;
2
- export declare const translationObject: (lng: string, objectName: string, object: StringMap, convert?: boolean, ignoreBase?: boolean) => any;
3
- export declare const translationObjects: (lng: string, objects: StringMap) => void;
4
- export declare const getObjectTranslationTemplate: (lng: string, objectName: string, _object: StringMap) => {};
5
- export declare const addObjectsTranslation: (i18nArray: any) => void;
@@ -1,3 +0,0 @@
1
- export declare const getObjectMetadataTranslationTemplate: (lng: string, objectName: string, _object: StringMap, ignoreBase?: boolean) => {
2
- name: string;
3
- };
@@ -1,5 +0,0 @@
1
- export declare const getAppMetadataTranslationTemplate: (lng: string, appId: string, _app: StringMap) => {
2
- CustomApplications: {
3
- [x: string]: {};
4
- };
5
- };
@@ -1,7 +0,0 @@
1
- export declare const translationApp: (lng: string, appId: string, app: StringMap) => void;
2
- export declare const translationMenus: (lng: string, menus: Array<any>) => void;
3
- export declare const translationApps: (lng: string, apps: StringMap) => void;
4
- export declare const getAppTranslationTemplate: (lng: string, appId: string, _app: StringMap) => {};
5
- export declare function convertTranslationData(record: any): any;
6
- export declare const convertTranslation: (_translation: any) => {};
7
- export declare const addTranslations: (translations: any) => void;
package/src/core_i18n.ts DELETED
@@ -1,23 +0,0 @@
1
- import { addResourceBundle, addTranslations } from './index';
2
- const path = require('path');
3
- const objectql = require('@steedos/objectql');
4
- const _ = require("underscore");
5
-
6
- export const InitCoreI18n = function(){
7
- let filePath = path.join(__dirname, '..', 'i18n', '**');
8
- let results = objectql.loadI18n(filePath);
9
- _.each(results, function(item){
10
- addResourceBundle(item.lng, 'translation', item.data);
11
- })
12
- }
13
-
14
- export const InitCoreTranslations = function(){
15
- let results = loadCoreTranslations();
16
- addTranslations(results);
17
- }
18
-
19
- export const loadCoreTranslations = function(){
20
- let filePath = path.join(__dirname, '..', 'translations', '**');
21
- let results = objectql.loadTranslations(filePath);
22
- return results;
23
- }
@@ -1,23 +0,0 @@
1
- import { getObjectI18nTemplate } from './i18n/i18n';
2
- const objectql = require('@steedos/objectql');
3
-
4
-
5
- export const exportObjectI18n = async (req: any, res: any)=>{
6
- let lng = req.params.lng;
7
- let objectName = req.params.objectName;
8
- let object = objectql.getOriginalObjectConfig(objectName); //getOriginalObjectConfig
9
- res.setHeader('Content-type', 'application/x-msdownload');
10
- res.setHeader('Content-Disposition', 'attachment;filename='+encodeURI(`${objectName}.${lng}.i18n.yml`));
11
- res.setHeader('Transfer-Encoding', '')
12
- if(object){
13
- let data = toYml(getObjectI18nTemplate(lng, objectName, object));
14
- res.send(data)
15
- }else{
16
- res.send({})
17
- }
18
- }
19
-
20
- export const toYml = function(date: StringMap, options?){
21
- const yaml = require('js-yaml');
22
- return yaml.dump(date, options).replace(/: ''/g, ': '); //, {sortKeys: true}
23
- }
@@ -1,82 +0,0 @@
1
- import { _t, exists } from '../index';
2
- const _ = require("underscore");
3
- const clone = require("clone");
4
-
5
- const APP_NS = 'translation';
6
- const KEYSEPARATOR: string = '_';
7
-
8
- const appT = function(key , lng){
9
- let options: any = {lng: lng, ns: APP_NS}
10
- if(KEYSEPARATOR === '.'){
11
- options.keySeparator = false
12
- }
13
- if(exists(key, options)){
14
- return _t(key, options)
15
- }
16
- }
17
-
18
- const getAppLabelKey = function(appId){
19
- return `app${KEYSEPARATOR}${appId}${KEYSEPARATOR}name`
20
- }
21
-
22
- const getAppDescriptionKey = function(appId){
23
- return `app${KEYSEPARATOR}${appId}${KEYSEPARATOR}description`
24
- }
25
-
26
- const getMenuLabelKey = function(menuId){
27
- return `menu${KEYSEPARATOR}${menuId}`
28
- }
29
-
30
- const getAppLabel = function(lng, appId, def){
31
- let key = getAppLabelKey(appId);
32
- return appT(key, lng) || def || ''
33
- }
34
-
35
- const getAppDescription = function(lng, appId, def){
36
- let key = getAppDescriptionKey(appId);
37
- return appT(key, lng) || def || ''
38
- }
39
-
40
- const getMenuLabel = function(lng, menuId, def){
41
- let key = getMenuLabelKey(menuId);
42
- return appT(key, lng) || def || ''
43
- }
44
-
45
- const translationI18nApp = function(lng: string, appId: string, app: StringMap){
46
- app.label = getAppLabel(lng, appId, app.label || app.name);
47
- // app.name = app.label
48
- app.description = getAppDescription(lng, appId, app.description);
49
- translationI18nMenus(lng, app.admin_menus);
50
- }
51
-
52
- export const translationI18nMenus = function(lng: string, menus: Array<any>){
53
- _.each(menus, function(menu){
54
- let label = getMenuLabel(lng, menu._id, menu.label || menu.name);
55
- menu.label = label;
56
- menu.name = label;
57
- })
58
- }
59
-
60
- export const translationI18nApps = function(lng: string, apps: StringMap){
61
- _.each(apps, function(app, name){
62
- translationI18nApp(lng, name, app);
63
- })
64
- }
65
-
66
- export const getAppI18nTemplate = function(lng: string, appId: string, _app: StringMap){
67
- let app = clone(_app);
68
- let template = {};
69
- template[getAppLabelKey(appId)] = getAppLabel(lng, appId, app.label || app.name);
70
- template[getAppDescriptionKey(appId)] = getAppDescription(lng, appId, app.description);
71
-
72
- _.each(app.admin_menus, function(menu){
73
- template[getMenuLabelKey( menu._id)] = getMenuLabel(lng, menu._id, menu.label || menu.name);
74
- })
75
- return template;
76
- }
77
-
78
- export const appFallbackKeys = {
79
- getAppLabelKey,
80
- getAppDescriptionKey,
81
- getMenuLabelKey
82
- }
package/src/i18n/i18n.ts DELETED
@@ -1,289 +0,0 @@
1
- import { _t, exists, addResourceBundle } from '../index';
2
- const _ = require("underscore");
3
- const clone = require("clone");
4
-
5
- const KEYSEPARATOR: string = '_';
6
-
7
- const BASE_OBJECT = 'base';
8
- const CORE_OBJECT = 'core';
9
-
10
- //translation 为默认的命名空间
11
- const OBJECT_NS = 'translation'; // objects
12
-
13
- const objectT = function(key , lng){
14
- let options: any = {lng: lng, ns: OBJECT_NS}
15
- if(KEYSEPARATOR === '.'){
16
- options.keySeparator = false
17
- }
18
- if(exists(key, options)){
19
- return _t(key, options)
20
- }
21
- }
22
-
23
- const getObjectLabelKey = function(objectName){
24
- return `${objectName}__object`;
25
- }
26
-
27
- const getObjectFieldLabelKey = function(objectName, name){
28
- if(name){
29
- name = name.replace(/\./g, '_');
30
- }
31
- return `${objectName}${KEYSEPARATOR}field${KEYSEPARATOR}${name}`
32
- }
33
-
34
- const getObjectFieldInlineHelpTextLabelKey = function(objectName, name){
35
- let fieldLabelKey = getObjectFieldLabelKey(objectName, name);
36
- return `${fieldLabelKey}${KEYSEPARATOR}inlineHelpText`
37
- }
38
-
39
- //TODO ${objectName}_group_${key}
40
- const getObjectFieldGroupKey = function(objectName, name){
41
- //转小写后,替换掉 % . 空格
42
- let groupKey = name.toLocaleLowerCase().replace(/\%/g, '_').replace(/\./g, '_').replace(/\ /g, '_')
43
- return `${objectName}${KEYSEPARATOR}group${KEYSEPARATOR}${groupKey}`
44
- }
45
-
46
- const getObjectFieldOptionsLabelKey = function(objectName, name, value){
47
- if(name){
48
- name = name.replace(/\./g, '_');
49
- }
50
- return `${objectName}${KEYSEPARATOR}field${KEYSEPARATOR}${name}${KEYSEPARATOR}options${KEYSEPARATOR}${value}`
51
- }
52
-
53
- const getObjectActionLabelKey = function(objectName, name){
54
- return `${objectName}${KEYSEPARATOR}action${KEYSEPARATOR}${name}`
55
- }
56
-
57
- const getObjectListviewLabelKey = function(objectName, name){
58
- return `${objectName}${KEYSEPARATOR}listview${KEYSEPARATOR}${name}`
59
- }
60
-
61
- //TODO picklists,picklist_options objects
62
- // const getObjectPicklistLabelKey = function(){
63
-
64
- // }
65
-
66
- // const isMeteor = () => {
67
- // return (typeof Meteor != "undefined")
68
- // }
69
-
70
-
71
- const getBaseObjectName = function(datasource){
72
- if(!datasource){
73
- return '';
74
- }
75
- let baseObjectName = CORE_OBJECT;
76
- if(datasource === 'default' || datasource === 'meteor'){
77
- baseObjectName = BASE_OBJECT;
78
- }
79
- return baseObjectName;
80
- }
81
-
82
- const getObjectLabel = function(lng, name, def){
83
- let key = getObjectLabelKey(name);
84
- return objectT(key, lng) || def || ''
85
- }
86
-
87
- const getObjectFieldLabel = function(lng, objectName, name, def, datasource?){
88
- let key = getObjectFieldLabelKey(objectName, name);
89
- let label = objectT(key, lng);
90
- if(!label){
91
- let baseObjectName = getBaseObjectName(datasource);
92
- if(baseObjectName && objectName != BASE_OBJECT && objectName != CORE_OBJECT){
93
- label = getObjectFieldLabel(lng, baseObjectName, name, def, datasource)
94
- }
95
- }
96
- return label || def || ''
97
- }
98
-
99
- const getObjectFieldInlineHelpTextLabel = function(lng, objectName, name, def, datasource?){
100
- let key = getObjectFieldInlineHelpTextLabelKey(objectName, name);
101
- let label = objectT(key, lng);
102
- if(!label){
103
- let baseObjectName = getBaseObjectName(datasource);
104
- if(baseObjectName && objectName != BASE_OBJECT && objectName != CORE_OBJECT){
105
- label = getObjectFieldInlineHelpTextLabel(lng, baseObjectName, name, def, datasource)
106
- }
107
- }
108
- return label || def || ''
109
- }
110
-
111
- const getObjectFieldGroup = function(lng, objectName, name, def){
112
- let key = getObjectFieldGroupKey(objectName, name);
113
- return objectT(key, lng) || def || ''
114
- }
115
-
116
- const getObjectFieldOptionsLabel = function(lng, objectName, name, value, def, datasource?){
117
- let key = getObjectFieldOptionsLabelKey(objectName, name, value);
118
- let label = objectT(key, lng);
119
- if(!label){
120
- let baseObjectName = getBaseObjectName(datasource);
121
- if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
122
- label = getObjectFieldOptionsLabel(lng, baseObjectName, name, value, def, datasource)
123
- }
124
- }
125
- return label || def || ''
126
- }
127
-
128
-
129
- const getObjectActionLabel = function(lng, objectName, name, def, datasource?){
130
- let key = getObjectActionLabelKey(objectName, name);
131
- let label = objectT(key, lng);
132
- if(!label){
133
- let baseObjectName = getBaseObjectName(datasource);
134
- if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
135
- label = getObjectActionLabel(lng, baseObjectName, name, def, datasource)
136
- }
137
- }
138
- return label || def || ''
139
- }
140
-
141
- const getObjectListviewLabel = function(lng, objectName, name, def, datasource?){
142
- let key = getObjectListviewLabelKey(objectName, name);
143
- let label = objectT(key, lng);
144
- if(!label){
145
- let baseObjectName = getBaseObjectName(datasource);
146
- if(baseObjectName && objectName!= BASE_OBJECT && objectName != CORE_OBJECT){
147
- label = getObjectListviewLabel(lng, baseObjectName, name, def, datasource)
148
- }
149
- }
150
- return label || def || ''
151
- }
152
-
153
- const getOption = function (option) {
154
- var foo;
155
- foo = option.split(":");
156
- if (foo.length > 1) {
157
- return {
158
- label: foo[0],
159
- value: foo[1]
160
- };
161
- } else {
162
- return {
163
- label: foo[0],
164
- value: foo[0]
165
- };
166
- }
167
- };
168
-
169
- const convertObject = function (object: StringMap) {
170
- _.forEach(object.fields, function (field, key) {
171
- let _options = [];
172
- if (field.options && _.isString(field.options)) {
173
- try {
174
- //支持\n或者英文逗号分割,
175
- _.forEach(field.options.split("\n"), function (option) {
176
- var options;
177
- if (option.indexOf(",")) {
178
- options = option.split(",");
179
- return _.forEach(options, function (_option) {
180
- return _options.push(getOption(_option));
181
- });
182
- } else {
183
- return _options.push(getOption(option));
184
- }
185
- });
186
- field.options = _options;
187
- } catch (error) {
188
- console.error("convertFieldsOptions error: ", field.options, error);
189
- }
190
- } else if (field.options && !_.isFunction(field.options) && !_.isArray(field.options) && _.isObject(field.options)) {
191
- _.each(field.options, function (v, k) {
192
- return _options.push({
193
- label: v,
194
- value: k
195
- });
196
- });
197
- field.options = _options;
198
- }
199
- })
200
- }
201
-
202
- //TODO 处理继承字段base, core 的字段
203
- export const translationI18nObject = function(lng: string, objectName: string, object: StringMap){
204
- object.label = getObjectLabel(lng, objectName, object.label);
205
- _.each(object.fields, function(field, fieldName){
206
- field.label = getObjectFieldLabel(lng, objectName, fieldName, field.label, object.datasource);
207
- if(field.inlineHelpText){
208
- field.inlineHelpText = getObjectFieldInlineHelpTextLabel(lng, objectName, fieldName, field.inlineHelpText, object.datasource)
209
- }
210
- if(field.group){
211
- field.group = getObjectFieldGroup(lng, objectName, field.group, field.group);
212
- }
213
- if(field.options){
214
- let _options = [];
215
- _.each(field.options, function(op){
216
- if(_.has(op, 'value')){
217
- let _label = getObjectFieldOptionsLabel(lng, objectName, fieldName, op.value, op.label, object.datasource)
218
- _options.push(_.extend({}, op, {label: _label}))
219
- }else{
220
- _options.push(op)
221
- }
222
- })
223
- field.options = _options;
224
- }
225
- })
226
-
227
- _.each(object.actions, function(action, actionName){
228
- action.label = getObjectActionLabel(lng, objectName, actionName, action.label, object.datasource);
229
- })
230
-
231
- _.each(object.list_views, function(list_view, viewName){
232
- list_view.label = getObjectListviewLabel(lng, objectName, viewName, list_view.label, object.datasource);
233
- })
234
- }
235
-
236
- export const addObjectsI18n = function(i18nArray){
237
- _.each(i18nArray, function(item){
238
- addResourceBundle(item.lng, OBJECT_NS, item.data, true, true);
239
- })
240
- }
241
-
242
- export const translationI18nObjects = function(lng: string, objects: StringMap){
243
- _.each(objects, function(object, name){
244
- translationI18nObject(lng, name, object);
245
- })
246
- }
247
-
248
- export const getObjectI18nTemplate = function(lng: string ,objectName: string, _object: StringMap){
249
- let object = clone(_object);
250
- convertObject(object);
251
- let template = {};
252
- template[getObjectLabelKey(objectName)] = getObjectLabel(lng, objectName, object.label);
253
- _.each(object.fields, function(field, fieldName){
254
- template[getObjectFieldLabelKey(objectName, fieldName)] = getObjectFieldLabel(lng, objectName, fieldName, field.label);
255
- if(field.inlineHelpText){
256
- template[getObjectFieldInlineHelpTextLabelKey(objectName, fieldName)] = getObjectFieldInlineHelpTextLabel(lng, objectName, fieldName, field.inlineHelpText, object.datasource)
257
- }
258
- if(field.group){
259
- template[getObjectFieldGroupKey(objectName, field.group)] = getObjectFieldGroup(lng, objectName, field.group, field.group);
260
- }
261
- if(field.options){
262
- _.each(field.options, function(op){
263
- if(_.has(op, 'value')){
264
- template[getObjectFieldOptionsLabelKey(objectName, fieldName, op.value)] = getObjectFieldOptionsLabel(lng, objectName, fieldName, op.value, op.label);
265
- }
266
- })
267
- }
268
- })
269
-
270
- _.each(object.actions, function(action, actionName){
271
- template[getObjectActionLabelKey( objectName, actionName)] = getObjectActionLabel(lng, objectName, actionName, action.label);
272
- })
273
-
274
- _.each(object.list_views, function(list_view, viewName){
275
- template[getObjectListviewLabelKey(objectName, viewName)] = getObjectListviewLabel(lng, objectName, viewName, list_view.label);
276
- })
277
-
278
- return template;
279
- }
280
-
281
- export const fallbackKeys = {
282
- getObjectLabelKey,
283
- getObjectFieldLabelKey,
284
- getObjectFieldInlineHelpTextLabelKey,
285
- getObjectFieldGroupKey,
286
- getObjectFieldOptionsLabelKey,
287
- getObjectActionLabelKey,
288
- getObjectListviewLabelKey,
289
- }