@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
|
@@ -51,6 +51,7 @@ TranslatePipe = __decorate([
|
|
|
51
51
|
var TranslationsModule_1;
|
|
52
52
|
const TranslationsConfig = new InjectionToken('translationConfig');
|
|
53
53
|
const USER_INFO = 'com.senior.token';
|
|
54
|
+
const LENGTH_DEFAULT = 2;
|
|
54
55
|
let TranslationsModule = TranslationsModule_1 = class TranslationsModule {
|
|
55
56
|
static forRoot(translationsConfigs) {
|
|
56
57
|
return {
|
|
@@ -90,7 +91,7 @@ TranslationsModule = TranslationsModule_1 = __decorate([
|
|
|
90
91
|
})
|
|
91
92
|
], TranslationsModule);
|
|
92
93
|
function factory(translate, injector, http, cookieService) {
|
|
93
|
-
return () => new Promise(resolve => {
|
|
94
|
+
return () => new Promise((resolve) => {
|
|
94
95
|
const locationInitialized = injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
|
|
95
96
|
locationInitialized.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
96
97
|
let locale = 'pt-BR';
|
|
@@ -98,50 +99,27 @@ function factory(translate, injector, http, cookieService) {
|
|
|
98
99
|
const configs = getFlatArray(injector.get(TranslationsConfig, Promise.resolve(null)));
|
|
99
100
|
try {
|
|
100
101
|
let userData = JSON.parse(cookieService.get(USER_INFO));
|
|
101
|
-
if (
|
|
102
|
+
if (userDataIsNull(userData)) {
|
|
102
103
|
userData = yield user.getUserData();
|
|
103
104
|
}
|
|
104
|
-
locale = userData
|
|
105
|
+
locale = getLocale(userData);
|
|
105
106
|
}
|
|
106
107
|
catch (ex) {
|
|
107
108
|
console.warn('Unable to obtain user locale');
|
|
108
109
|
}
|
|
109
|
-
const fallback = configs
|
|
110
|
-
|
|
111
|
-
const defaultsLanguages = configs
|
|
112
|
-
.reduce((result, configs) => (Object.assign(Object.assign({}, result), configs.defaultsLanguages)), {});
|
|
110
|
+
const fallback = configs.reduce((result, configs) => (Object.assign(Object.assign({}, result), configs.fallback)), {});
|
|
111
|
+
const defaultsLanguages = configs.reduce((result, configs) => (Object.assign(Object.assign({}, result), configs.defaultsLanguages)), {});
|
|
113
112
|
translate.setTranslation(locale, fallback);
|
|
114
113
|
translate.setDefaultLang(locale);
|
|
115
|
-
let
|
|
114
|
+
let configTranslate = {};
|
|
116
115
|
if (defaultsLanguages) {
|
|
117
|
-
|
|
118
|
-
const language = {};
|
|
119
|
-
language['locale'] = key.replace('_', '-');
|
|
120
|
-
language['translation'] = defaultsLanguages[key];
|
|
121
|
-
return language;
|
|
122
|
-
}, []);
|
|
123
|
-
let foundLocaleUser = languages.find((results) => results.locale === locale);
|
|
124
|
-
if (!foundLocaleUser) {
|
|
125
|
-
foundLocaleUser = languages.find((results) => {
|
|
126
|
-
return results.locale.length === 2 && results.locale === locale.split('-')[0];
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (foundLocaleUser) {
|
|
130
|
-
fallbackByLocale = foundLocaleUser['translation'];
|
|
131
|
-
}
|
|
116
|
+
configTranslate = getConfigTranslate(defaultsLanguages, locale);
|
|
132
117
|
}
|
|
133
118
|
const translationsPromises = configs.map((config) => getTranslationsRequest(config, locale));
|
|
134
|
-
yield Promise.all(translationsPromises).then(results => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
file['content'] && translate.setTranslation(locale, file['content'], true);
|
|
139
|
-
translate.setTranslation(locale, fallbackByLocale, true);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
translate.setTranslation(locale, fallbackByLocale, true);
|
|
143
|
-
file['content'] && translate.setTranslation(locale, file['content'], true);
|
|
144
|
-
}
|
|
119
|
+
yield Promise.all(translationsPromises).then((results) => {
|
|
120
|
+
const usedFallback = translate['overriden'];
|
|
121
|
+
results.forEach((file, index) => {
|
|
122
|
+
setTranslations(file['content'], usedFallback, locale, index, configTranslate.fallbackByLocale);
|
|
145
123
|
});
|
|
146
124
|
return translate.use(locale).toPromise();
|
|
147
125
|
});
|
|
@@ -149,25 +127,40 @@ function factory(translate, injector, http, cookieService) {
|
|
|
149
127
|
}
|
|
150
128
|
catch (err) {
|
|
151
129
|
console.warn('Error setting translations. Using local fallback.', err);
|
|
152
|
-
translate
|
|
130
|
+
translate
|
|
131
|
+
.use(locale)
|
|
132
|
+
.toPromise()
|
|
133
|
+
.then(() => {
|
|
153
134
|
resolve();
|
|
154
135
|
});
|
|
155
136
|
}
|
|
156
137
|
}));
|
|
157
138
|
});
|
|
139
|
+
function setTranslations(content, usedFallback, locale, index, fallbackByLocale) {
|
|
140
|
+
if (usedFallback) {
|
|
141
|
+
content && translate.setTranslation(locale, content, true);
|
|
142
|
+
translate.setTranslation(locale, fallbackByLocale, true);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
if (index === 0) {
|
|
146
|
+
translate.setTranslation(locale, fallbackByLocale, true);
|
|
147
|
+
}
|
|
148
|
+
content && translate.setTranslation(locale, content, true);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
158
151
|
function getTranslationsRequest({ domain, service }, language) {
|
|
159
152
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
160
153
|
try {
|
|
161
154
|
if (!domain && !service) {
|
|
162
155
|
throw new Error(`domain and service not found`);
|
|
163
156
|
}
|
|
164
|
-
const params = new HttpParams()
|
|
165
|
-
.set('domainName', domain)
|
|
166
|
-
.set('serviceName', service)
|
|
167
|
-
.set('format', 'FLAT_JSON');
|
|
157
|
+
const params = new HttpParams().set('domainName', domain).set('serviceName', service).set('format', 'FLAT_JSON');
|
|
168
158
|
const headers = new HttpHeaders().set('Authorization', yield user.getAuthHeader());
|
|
169
159
|
const url = 'platform/translation_hub/queries/getTranslationBundle';
|
|
170
|
-
const bundleFiles = yield http
|
|
160
|
+
const bundleFiles = yield http
|
|
161
|
+
.get(url, { headers, params })
|
|
162
|
+
.toPromise()
|
|
163
|
+
.then((res) => res.bundleFiles);
|
|
171
164
|
let languageBundle = language && bundleFiles.find((bundle) => bundle.language === language);
|
|
172
165
|
let overriden = false;
|
|
173
166
|
if (!languageBundle) {
|
|
@@ -202,6 +195,31 @@ function factory(translate, injector, http, cookieService) {
|
|
|
202
195
|
return [...result, item];
|
|
203
196
|
}, []);
|
|
204
197
|
}
|
|
198
|
+
function userDataIsNull(data) {
|
|
199
|
+
return !data || Object.keys(data).length === 0;
|
|
200
|
+
}
|
|
201
|
+
function getConfigTranslate(defaultsLanguages, locale) {
|
|
202
|
+
const languages = Object.keys(defaultsLanguages).map((key) => {
|
|
203
|
+
const language = {};
|
|
204
|
+
language['locale'] = key.replace('_', '-');
|
|
205
|
+
language['translation'] = defaultsLanguages[key];
|
|
206
|
+
return language;
|
|
207
|
+
}, []);
|
|
208
|
+
const result = { languages };
|
|
209
|
+
result['foundLocaleUser'] = languages.find((results) => results.locale === locale);
|
|
210
|
+
if (!result['foundLocaleUser']) {
|
|
211
|
+
result['foundLocaleUser'] = languages.find((results) => {
|
|
212
|
+
return results.locale.length === LENGTH_DEFAULT && results.locale === locale.split('-')[0];
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (result['foundLocaleUser']) {
|
|
216
|
+
result['fallbackByLocale'] = result['foundLocaleUser']['translation'];
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
function getLocale(userData) {
|
|
221
|
+
return userData.locale || 'pt-BR';
|
|
222
|
+
}
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
const fallback = {
|
|
@@ -2235,5 +2253,5 @@ SpotlightModule = __decorate([
|
|
|
2235
2253
|
* Generated bundle index. Do not edit.
|
|
2236
2254
|
*/
|
|
2237
2255
|
|
|
2238
|
-
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 };
|
|
2256
|
+
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 };
|
|
2239
2257
|
//# sourceMappingURL=seniorsistemas-platform-components.js.map
|