@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.
@@ -1,93 +0,0 @@
1
- import * as _ from 'underscore';
2
- import { translationObject } from '../index';
3
- const clone = require("clone");
4
-
5
- function keysToJSON(keys, source){
6
- const json = {};
7
- _.each(keys, function(key){
8
- if(key === 'help'){
9
- json[key] = source['inlineHelpText'] || '';
10
- }else{
11
- json[key] = source[key] || '';
12
- }
13
- })
14
- return json;
15
- }
16
-
17
- function getObjectTranslationTemplate(object){
18
- return keysToJSON(['label', 'description'], object);
19
- }
20
-
21
- function getFieldTranslationKeys(field){
22
- switch (field.type) {
23
- case 'select':
24
- return keysToJSON(['label', 'help', 'options', 'description'], field);
25
- default:
26
- return keysToJSON(['label', 'help', 'description'], field);
27
- }
28
- }
29
-
30
- function getListViewTranslationKeys(listView){
31
- return keysToJSON(['label'], listView);
32
- }
33
-
34
- function getActionTranslationKeys(action){
35
- return keysToJSON(['label'], action);
36
- }
37
-
38
- function getFieldsTranslationTemplate(fields){
39
- const template = {};
40
- _.each(fields, function(field, fieldName){
41
- template[fieldName] = getFieldTranslationKeys(field);
42
- })
43
- return template;
44
- }
45
-
46
- function getActionsTranslationTemplate(actions){
47
- const template = {};
48
- _.each(actions, function(action, actionName){
49
- template[actionName] = getActionTranslationKeys(action);
50
- })
51
- return template;
52
- }
53
-
54
- function getListviewsTranslationTemplate(listviews){
55
- const template = {};
56
- _.each(listviews, function(list_view, viewName){
57
- template[viewName] = getListViewTranslationKeys(list_view);
58
- })
59
- return template;
60
- }
61
-
62
- function getFieldGroupsTemplate(fields, tFields){
63
- const template = {};
64
- _.each(fields, function(field, fieldName){
65
- if(field.group){
66
- let groupKey = field.group.toLocaleLowerCase().replace(/\%/g, '_').replace(/\./g, '_').replace(/\ /g, '_')
67
- template[groupKey] = tFields[fieldName].group;
68
- }
69
- })
70
- return template;
71
- }
72
-
73
- export const getObjectMetadataTranslationTemplate = function(lng: string , objectName: string, _object: StringMap, ignoreBase = false){
74
- let object = clone(_object);
75
- if( ignoreBase != true){
76
- translationObject(lng, objectName, object, true, ignoreBase);
77
- }
78
- let template = Object.assign({}, getObjectTranslationTemplate(object));
79
- template = Object.assign({}, template, {fields: getFieldsTranslationTemplate(object.fields)});
80
- const groupsTemplate = getFieldGroupsTemplate(_object.fields, object.fields);
81
- if(!_.isEmpty(groupsTemplate)){
82
- template = Object.assign({}, template, {groups: groupsTemplate});
83
- }
84
- const listViewsTemplate = getListviewsTranslationTemplate(object.list_views);
85
- if(!_.isEmpty(listViewsTemplate)){
86
- template = Object.assign({}, template, {listviews: listViewsTemplate});
87
- }
88
- const actionsTemplate = getActionsTranslationTemplate(object.actions);
89
- if(!_.isEmpty(actionsTemplate)){
90
- template = Object.assign({}, template, {actions: actionsTemplate});
91
- }
92
- return Object.assign({name: objectName}, template)
93
- }
@@ -1,36 +0,0 @@
1
- import * as _ from 'underscore';
2
- import { translationApp } from '../index';
3
- const clone = require("clone");
4
-
5
- function keysToJSON(keys, source){
6
- const json = {};
7
- _.each(keys, function(key){
8
- json[key] = source[key] || '';
9
- })
10
- return json;
11
- }
12
-
13
- const getAppTranslationTemplate = function(app){
14
- return keysToJSON(['name', 'description'], app);
15
- }
16
-
17
- // const getMenuTranslationKeys = function(menu){
18
- // return keysToJSON(['label'], menu);
19
- // }
20
-
21
- // const getMenuTranslationTemplate = function(menus){
22
- // const template = {};
23
- // _.each(menus, function(menu){
24
- // template[menu._id] = getMenuTranslationKeys(menu);
25
- // })
26
- // return template;
27
- // }
28
-
29
- export const getAppMetadataTranslationTemplate = function(lng: string, appId: string, _app: StringMap){
30
- let app = clone(_app);
31
- translationApp(lng, appId, app);
32
- let template = Object.assign({}, {CustomApplications: {[appId]: getAppTranslationTemplate(app)}});
33
- // template = Object.assign({}, template, {CustomMenus: getMenuTranslationTemplate(app.admin_menus)});
34
- return template;
35
- }
36
-
@@ -1,183 +0,0 @@
1
- import { _t, exists, addResourceBundle } from '../index';
2
- import * as _ from 'underscore';
3
- import { SteedosTranslationPrefixKeys } from './';
4
- import { appFallbackKeys } from '../i18n/i18n.app';
5
-
6
- const clone = require("clone");
7
-
8
- const NAMESPACE = 'translation';
9
- const KEYSEPARATOR: string = '.';
10
-
11
- const CUSTOMAPPLICATIONS_KEY = 'app';
12
- const MENU_KEY = 'menu';
13
-
14
- const getPrefix = function(key?){
15
- switch (key) {
16
- case CUSTOMAPPLICATIONS_KEY:
17
- return SteedosTranslationPrefixKeys.Application
18
- default:
19
- return 'CustomLabels';
20
- }
21
- }
22
-
23
- const getCustomLabelKey = function(key){
24
- const prefix = getPrefix();
25
- return [prefix, key].join(KEYSEPARATOR);
26
- }
27
-
28
- const translation = function(key , lng){
29
- let options: any = {lng: lng, ns: NAMESPACE}
30
- if(KEYSEPARATOR === '.'){
31
- options.keySeparator = false
32
- }
33
- if(exists(key, options)){
34
- return _t(key, options)
35
- }
36
- }
37
-
38
- const getAppNameKey = function(appId){
39
- const prefix = getPrefix(CUSTOMAPPLICATIONS_KEY);
40
- return [prefix, appId, 'name'].join(KEYSEPARATOR);
41
- }
42
-
43
- const getAppDescriptionKey = function(appId){
44
- const prefix = getPrefix(CUSTOMAPPLICATIONS_KEY);
45
- return [prefix, appId, 'description'].join(KEYSEPARATOR);
46
- }
47
-
48
- const getMenuLabelKey = function(menuId){
49
- const prefix = getPrefix(MENU_KEY);
50
- return [prefix, `menu_${menuId}`].join(KEYSEPARATOR);
51
- }
52
-
53
- const translationAppName = function(lng, appId, def){
54
- let key = getAppNameKey(appId);
55
- let keys = [key];
56
- let fallbackKey = appFallbackKeys.getAppLabelKey(appId);
57
- if(fallbackKey){
58
- keys.push(fallbackKey);
59
- }
60
- return translation(keys, lng) || def || ''
61
- }
62
-
63
- const translationAppDescription = function(lng, appId, def){
64
- let key = getAppDescriptionKey(appId);
65
- let keys = [key];
66
- let fallbackKey = appFallbackKeys.getAppDescriptionKey(appId);
67
- if(fallbackKey){
68
- keys.push(fallbackKey);
69
- }
70
- return translation(keys, lng) || def || ''
71
- }
72
-
73
- const translationMenuLabel = function(lng, menuId, def){
74
- let key = getMenuLabelKey(menuId);
75
- let keys = [key];
76
- let fallbackKey = appFallbackKeys.getMenuLabelKey(menuId);
77
- if(fallbackKey){
78
- keys.push(fallbackKey);
79
- }
80
- return translation(keys, lng) || def || ''
81
- }
82
-
83
- export const translationApp = function(lng: string, appId: string, app: StringMap){
84
- app.label = translationAppName(lng, appId, app.label || app.name);
85
- // app.name = app.label
86
- app.description = translationAppDescription(lng, appId, app.description);
87
- translationMenus(lng, app.admin_menus);
88
- }
89
-
90
- export const translationMenus = function(lng: string, menus: Array<any>){
91
- _.each(menus, function(menu){
92
- let label = translationMenuLabel(lng, menu._id, menu.label || menu.name);
93
- menu.label = label;
94
- menu.name = label;
95
- })
96
- }
97
-
98
- export const translationApps = function(lng: string, apps: StringMap){
99
- _.each(apps, function(app, name){
100
- translationApp(lng, name, app);
101
- })
102
- }
103
-
104
- export const getAppTranslationTemplate = function(lng: string, appId: string, _app: StringMap){
105
- let app = clone(_app);
106
- let template = {};
107
- template[getAppNameKey(appId)] = translationAppName(lng, appId, app.label || app.name);
108
- template[getAppDescriptionKey(appId)] = translationAppDescription(lng, appId, app.description);
109
-
110
- _.each(app.admin_menus, function(menu){
111
- template[getMenuLabelKey( menu._id)] = translationMenuLabel(lng, menu._id, menu.label || menu.name);
112
- })
113
- return template;
114
- }
115
-
116
- let processChildren = (item, parentKey, object) => {
117
- if (_.isArray(object)) {
118
- _.each(object, function (_citem) {
119
- processChildren(_citem, '', _citem);
120
- })
121
- } else if(object){
122
- _.each(_.keys(object), function (k) {
123
- let childKey = parentKey ? `${parentKey}.${k}` : k;
124
- let childValue = object[k];
125
- if (typeof childValue === "object") {
126
- if (_.isArray(childValue)) {
127
- _.each(childValue, function (_citem) {
128
- processChildren(_citem, childKey, childValue);
129
- })
130
- } else {
131
- processChildren(item, childKey, childValue);
132
- }
133
- }
134
- else {
135
- item[childKey] = childValue;
136
- }
137
- })
138
- }
139
- }
140
-
141
- export function convertTranslationData(record) {
142
- for (let k in record) {
143
- if (typeof record[k] === "object") {
144
- processChildren(record, k, record[k]);
145
- }
146
- }
147
- return record;
148
- }
149
-
150
- export const convertTranslation = function(_translation){
151
- let translation = clone(_translation);
152
- let template = {};
153
-
154
- _.each(translation.CustomApplications, function(app, appId){
155
- template[getAppNameKey(appId)] = app.name;
156
- template[getAppDescriptionKey(appId)] = app.description;
157
- })
158
-
159
- // _.each(translation.CustomMenus, function(menu, menuId){
160
- // template[getMenuLabelKey(menuId)] = menu.label;
161
- // })
162
-
163
- _.each(translation.CustomLabels, function(labelValue, labelKey){
164
- if(labelKey != 'simpleschema' && _.isObject(labelValue)){
165
- const levelData = convertTranslationData({[labelKey]: labelValue});
166
- _.each(levelData, function(value, key){
167
- if(!_.isObject(value)){
168
- template[getCustomLabelKey(key)] = value;
169
- }
170
- })
171
- }else{
172
- template[getCustomLabelKey(labelKey)] = labelValue;
173
- }
174
- })
175
- return template;
176
- }
177
-
178
- export const addTranslations = function(translations){
179
- _.each(translations, function(item){
180
- let data = convertTranslation(item.data);
181
- addResourceBundle(item.lng, NAMESPACE, data, true, true);
182
- })
183
- }
package/src/type.d.ts DELETED
@@ -1,8 +0,0 @@
1
- type StringMap = { [key: string]: any };
2
- type Callback = (error: any, t: Function) => void;
3
- type events = "initialized" | "loaded" | "failedLoading" | "missingKey" | 'added' | 'removed' | 'languageChanged' | string;
4
- declare interface XMLHttpRequest {}
5
- declare var window;
6
- declare var Meteor:any;
7
- declare var $: any;
8
- declare var XMLHttpRequest: any;
package/tsconfig.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./lib",
4
- "target": "es5",
5
- "module": "commonjs",
6
- "moduleResolution": "node",
7
- "importHelpers": true,
8
- "emitDecoratorMetadata": true,
9
- "experimentalDecorators": true,
10
- "sourceMap": true,
11
- "noImplicitAny": false,
12
- "declaration": true,
13
- "noFallthroughCasesInSwitch": true,
14
- //"noImplicitReturns": true,
15
- "stripInternal": true,
16
- "pretty": true,
17
- "noUnusedLocals": true,
18
- "downlevelIteration": true,
19
- "strictNullChecks": false,
20
- "skipLibCheck": true,
21
- "lib": [
22
- "es5",
23
- "es6",
24
- "es2015",
25
- "es2016",
26
- "es2017",
27
- "esnext"
28
- ],
29
- },
30
- "include": [
31
- "./src/**/*"
32
- ],
33
- "exclude": [
34
- "../../node_modules/"
35
- ]
36
- }