@seniorsistemas/platform-components 5.3.0 → 5.3.1
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/bundles/seniorsistemas-platform-components.umd.js +59 -40
- package/bundles/seniorsistemas-platform-components.umd.js.map +1 -1
- package/bundles/seniorsistemas-platform-components.umd.min.js +2 -2
- package/bundles/seniorsistemas-platform-components.umd.min.js.map +1 -1
- package/esm2015/modules/translations/translations.module.js +59 -41
- package/esm5/modules/translations/translations.module.js +59 -41
- package/fesm2015/seniorsistemas-platform-components.js +59 -41
- package/fesm2015/seniorsistemas-platform-components.js.map +1 -1
- package/fesm5/seniorsistemas-platform-components.js +59 -41
- package/fesm5/seniorsistemas-platform-components.js.map +1 -1
- package/modules/translations/translations.module.d.ts +1 -0
- package/package.json +2 -2
- package/seniorsistemas-platform-components.metadata.json +1 -1
- package/modules/cyclic-json-interceptor/custom.d.ts +0 -4
|
@@ -55,6 +55,7 @@ var TranslatePipe = /** @class */ (function () {
|
|
|
55
55
|
|
|
56
56
|
var TranslationsConfig = new InjectionToken('translationConfig');
|
|
57
57
|
var USER_INFO = 'com.senior.token';
|
|
58
|
+
var LENGTH_DEFAULT = 2;
|
|
58
59
|
var TranslationsModule = /** @class */ (function () {
|
|
59
60
|
function TranslationsModule() {
|
|
60
61
|
}
|
|
@@ -104,7 +105,7 @@ function factory(translate, injector, http, cookieService) {
|
|
|
104
105
|
return new Promise(function (resolve) {
|
|
105
106
|
var locationInitialized = injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
|
|
106
107
|
locationInitialized.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
107
|
-
var locale, configs, userData, ex_1, fallback,
|
|
108
|
+
var locale, configs, userData, ex_1, fallback, defaultsLanguages, configTranslate_1, translationsPromises, err_1;
|
|
108
109
|
return __generator(this, function (_a) {
|
|
109
110
|
switch (_a.label) {
|
|
110
111
|
case 0:
|
|
@@ -117,55 +118,32 @@ function factory(translate, injector, http, cookieService) {
|
|
|
117
118
|
case 2:
|
|
118
119
|
_a.trys.push([2, 5, , 6]);
|
|
119
120
|
userData = JSON.parse(cookieService.get(USER_INFO));
|
|
120
|
-
if (!(
|
|
121
|
+
if (!userDataIsNull(userData)) return [3 /*break*/, 4];
|
|
121
122
|
return [4 /*yield*/, user.getUserData()];
|
|
122
123
|
case 3:
|
|
123
124
|
userData = _a.sent();
|
|
124
125
|
_a.label = 4;
|
|
125
126
|
case 4:
|
|
126
|
-
locale = userData
|
|
127
|
+
locale = getLocale(userData);
|
|
127
128
|
return [3 /*break*/, 6];
|
|
128
129
|
case 5:
|
|
129
130
|
ex_1 = _a.sent();
|
|
130
131
|
console.warn('Unable to obtain user locale');
|
|
131
132
|
return [3 /*break*/, 6];
|
|
132
133
|
case 6:
|
|
133
|
-
fallback = configs
|
|
134
|
-
|
|
135
|
-
defaultsLanguages_1 = configs
|
|
136
|
-
.reduce(function (result, configs) { return (__assign(__assign({}, result), configs.defaultsLanguages)); }, {});
|
|
134
|
+
fallback = configs.reduce(function (result, configs) { return (__assign(__assign({}, result), configs.fallback)); }, {});
|
|
135
|
+
defaultsLanguages = configs.reduce(function (result, configs) { return (__assign(__assign({}, result), configs.defaultsLanguages)); }, {});
|
|
137
136
|
translate.setTranslation(locale, fallback);
|
|
138
137
|
translate.setDefaultLang(locale);
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
var language = {};
|
|
143
|
-
language['locale'] = key.replace('_', '-');
|
|
144
|
-
language['translation'] = defaultsLanguages_1[key];
|
|
145
|
-
return language;
|
|
146
|
-
}, []);
|
|
147
|
-
foundLocaleUser = languages.find(function (results) { return results.locale === locale; });
|
|
148
|
-
if (!foundLocaleUser) {
|
|
149
|
-
foundLocaleUser = languages.find(function (results) {
|
|
150
|
-
return results.locale.length === 2 && results.locale === locale.split('-')[0];
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (foundLocaleUser) {
|
|
154
|
-
fallbackByLocale_1 = foundLocaleUser['translation'];
|
|
155
|
-
}
|
|
138
|
+
configTranslate_1 = {};
|
|
139
|
+
if (defaultsLanguages) {
|
|
140
|
+
configTranslate_1 = getConfigTranslate(defaultsLanguages, locale);
|
|
156
141
|
}
|
|
157
142
|
translationsPromises = configs.map(function (config) { return getTranslationsRequest(config, locale); });
|
|
158
143
|
return [4 /*yield*/, Promise.all(translationsPromises).then(function (results) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
file['content'] && translate.setTranslation(locale, file['content'], true);
|
|
163
|
-
translate.setTranslation(locale, fallbackByLocale_1, true);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
translate.setTranslation(locale, fallbackByLocale_1, true);
|
|
167
|
-
file['content'] && translate.setTranslation(locale, file['content'], true);
|
|
168
|
-
}
|
|
144
|
+
var usedFallback = translate['overriden'];
|
|
145
|
+
results.forEach(function (file, index) {
|
|
146
|
+
setTranslations(file['content'], usedFallback, locale, index, configTranslate_1.fallbackByLocale);
|
|
169
147
|
});
|
|
170
148
|
return translate.use(locale).toPromise();
|
|
171
149
|
})];
|
|
@@ -176,7 +154,10 @@ function factory(translate, injector, http, cookieService) {
|
|
|
176
154
|
case 8:
|
|
177
155
|
err_1 = _a.sent();
|
|
178
156
|
console.warn('Error setting translations. Using local fallback.', err_1);
|
|
179
|
-
translate
|
|
157
|
+
translate
|
|
158
|
+
.use(locale)
|
|
159
|
+
.toPromise()
|
|
160
|
+
.then(function () {
|
|
180
161
|
resolve();
|
|
181
162
|
});
|
|
182
163
|
return [3 /*break*/, 9];
|
|
@@ -186,6 +167,18 @@ function factory(translate, injector, http, cookieService) {
|
|
|
186
167
|
}); });
|
|
187
168
|
});
|
|
188
169
|
};
|
|
170
|
+
function setTranslations(content, usedFallback, locale, index, fallbackByLocale) {
|
|
171
|
+
if (usedFallback) {
|
|
172
|
+
content && translate.setTranslation(locale, content, true);
|
|
173
|
+
translate.setTranslation(locale, fallbackByLocale, true);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (index === 0) {
|
|
177
|
+
translate.setTranslation(locale, fallbackByLocale, true);
|
|
178
|
+
}
|
|
179
|
+
content && translate.setTranslation(locale, content, true);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
189
182
|
function getTranslationsRequest(_a, language) {
|
|
190
183
|
var _this = this;
|
|
191
184
|
var domain = _a.domain, service = _a.service;
|
|
@@ -198,17 +191,17 @@ function factory(translate, injector, http, cookieService) {
|
|
|
198
191
|
if (!domain && !service) {
|
|
199
192
|
throw new Error("domain and service not found");
|
|
200
193
|
}
|
|
201
|
-
params = new HttpParams()
|
|
202
|
-
.set('domainName', domain)
|
|
203
|
-
.set('serviceName', service)
|
|
204
|
-
.set('format', 'FLAT_JSON');
|
|
194
|
+
params = new HttpParams().set('domainName', domain).set('serviceName', service).set('format', 'FLAT_JSON');
|
|
205
195
|
_b = (_a = new HttpHeaders()).set;
|
|
206
196
|
_c = ['Authorization'];
|
|
207
197
|
return [4 /*yield*/, user.getAuthHeader()];
|
|
208
198
|
case 1:
|
|
209
199
|
headers = _b.apply(_a, _c.concat([_d.sent()]));
|
|
210
200
|
url = 'platform/translation_hub/queries/getTranslationBundle';
|
|
211
|
-
return [4 /*yield*/, http
|
|
201
|
+
return [4 /*yield*/, http
|
|
202
|
+
.get(url, { headers: headers, params: params })
|
|
203
|
+
.toPromise()
|
|
204
|
+
.then(function (res) { return res.bundleFiles; })];
|
|
212
205
|
case 2:
|
|
213
206
|
bundleFiles = _d.sent();
|
|
214
207
|
languageBundle = language && bundleFiles.find(function (bundle) { return bundle.language === language; });
|
|
@@ -251,6 +244,31 @@ function factory(translate, injector, http, cookieService) {
|
|
|
251
244
|
return __spread(result, [item]);
|
|
252
245
|
}, []);
|
|
253
246
|
}
|
|
247
|
+
function userDataIsNull(data) {
|
|
248
|
+
return !data || Object.keys(data).length === 0;
|
|
249
|
+
}
|
|
250
|
+
function getConfigTranslate(defaultsLanguages, locale) {
|
|
251
|
+
var languages = Object.keys(defaultsLanguages).map(function (key) {
|
|
252
|
+
var language = {};
|
|
253
|
+
language['locale'] = key.replace('_', '-');
|
|
254
|
+
language['translation'] = defaultsLanguages[key];
|
|
255
|
+
return language;
|
|
256
|
+
}, []);
|
|
257
|
+
var result = { languages: languages };
|
|
258
|
+
result['foundLocaleUser'] = languages.find(function (results) { return results.locale === locale; });
|
|
259
|
+
if (!result['foundLocaleUser']) {
|
|
260
|
+
result['foundLocaleUser'] = languages.find(function (results) {
|
|
261
|
+
return results.locale.length === LENGTH_DEFAULT && results.locale === locale.split('-')[0];
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (result['foundLocaleUser']) {
|
|
265
|
+
result['fallbackByLocale'] = result['foundLocaleUser']['translation'];
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
function getLocale(userData) {
|
|
270
|
+
return userData.locale || 'pt-BR';
|
|
271
|
+
}
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
var fallback = {
|
|
@@ -2456,5 +2474,5 @@ var SpotlightModule = /** @class */ (function () {
|
|
|
2456
2474
|
* Generated bundle index. Do not edit.
|
|
2457
2475
|
*/
|
|
2458
2476
|
|
|
2459
|
-
export { AdvancedFilterComponent, AdvancedFilterModule, AdvancedFilterService, AppRoutingModule, CyclicJsonInterceptorModule, FeatureToggleModule, FeatureToggleService, Filter, FilterType, FormFilter, HttpInterceptorModule, PermissionsModule, PermissionsService, RestUrl, Scope, SpotlightComponent, SpotlightModule, TranslationsConfig, TranslationsModule, USER_INFO, XServicesUrl, factory, promise, fallback as ɵa, CalendarOptionsService as ɵb, FormFilterComponent as ɵc, MapValuesPipe as ɵd, TranslatePipe as ɵe, CyclicJsonInterceptor as ɵf, HttpInterceptor as ɵg, RESOURCES as ɵh, ENVIRONMENT as ɵi, Environment as ɵk, fallback$1 as ɵl, SpotlightService as ɵm, TranslatePipe$1 as ɵn };
|
|
2477
|
+
export { AdvancedFilterComponent, AdvancedFilterModule, AdvancedFilterService, AppRoutingModule, CyclicJsonInterceptorModule, FeatureToggleModule, FeatureToggleService, Filter, FilterType, FormFilter, HttpInterceptorModule, LENGTH_DEFAULT, PermissionsModule, PermissionsService, RestUrl, Scope, SpotlightComponent, SpotlightModule, TranslationsConfig, TranslationsModule, USER_INFO, XServicesUrl, factory, promise, fallback as ɵa, CalendarOptionsService as ɵb, FormFilterComponent as ɵc, MapValuesPipe as ɵd, TranslatePipe as ɵe, CyclicJsonInterceptor as ɵf, HttpInterceptor as ɵg, RESOURCES as ɵh, ENVIRONMENT as ɵi, Environment as ɵk, fallback$1 as ɵl, SpotlightService as ɵm, TranslatePipe$1 as ɵn };
|
|
2460
2478
|
//# sourceMappingURL=seniorsistemas-platform-components.js.map
|