@sumaris-net/ngx-components 0.28.3 → 0.28.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/bundles/sumaris-net.ngx-components.umd.js +47 -9
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/src/app/shared/services/translate-context.service.js +38 -13
- package/fesm2015/sumaris-net.ngx-components.js +36 -10
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/shared/services/translate-context.service.d.ts +10 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -2854,23 +2854,42 @@
|
|
|
2854
2854
|
TranslateContextService.prototype.get = function (key, context, interpolateParams) {
|
|
2855
2855
|
var _this = this;
|
|
2856
2856
|
// No context: do a normal translate
|
|
2857
|
-
if (!isNil(context))
|
|
2857
|
+
if (!key || !isNil(context))
|
|
2858
2858
|
return this.translate.get(key, interpolateParams);
|
|
2859
2859
|
// Compute a contextual i18n key, using the context as suffix
|
|
2860
|
-
var
|
|
2860
|
+
var contextualKeys = this.contextualKeys(key, context);
|
|
2861
2861
|
// Return the contextual translation, or default of not exists
|
|
2862
|
-
return this.translate.get(
|
|
2863
|
-
.pipe(operators.
|
|
2862
|
+
return this.translate.get(contextualKeys, interpolateParams)
|
|
2863
|
+
.pipe(operators.map(function (translations) { return _this.findFirstValid(contextualKeys, translations) || key; }));
|
|
2864
2864
|
};
|
|
2865
2865
|
TranslateContextService.prototype.instant = function (key, context, interpolateParams) {
|
|
2866
2866
|
// No context: do a normal translate
|
|
2867
|
-
if (isNilOrBlank(context))
|
|
2867
|
+
if (!key || isNilOrBlank(context))
|
|
2868
2868
|
return this.translate.instant(key, interpolateParams);
|
|
2869
2869
|
// Compute a contextual i18n key, using the context as suffix
|
|
2870
|
-
var
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2870
|
+
var contextualKeys = this.contextualKeys(key, context);
|
|
2871
|
+
var translations = this.translate.instant(contextualKeys, interpolateParams);
|
|
2872
|
+
return this.findFirstValid(contextualKeys, translations) || key;
|
|
2873
|
+
};
|
|
2874
|
+
/**
|
|
2875
|
+
* Compute contextual i18n keys, using the context as suffix.<br>
|
|
2876
|
+
* Suffix can be simple name (like 'aaa' - will return ['<key>.aaa']) or complexe (like 'aaa.bbb' - will return ['<key>.aaa.bbb', '<key>.aaa']
|
|
2877
|
+
*
|
|
2878
|
+
* @param key
|
|
2879
|
+
* @param context
|
|
2880
|
+
* @private
|
|
2881
|
+
*/
|
|
2882
|
+
TranslateContextService.prototype.contextualKeys = function (key, context) {
|
|
2883
|
+
var _this = this;
|
|
2884
|
+
return context.split('.')
|
|
2885
|
+
.filter(isNotNilOrBlank)
|
|
2886
|
+
.reduce(function (res, item) {
|
|
2887
|
+
var inheritedContext = res.length > 0 ? (res[res.length - 1] + '.') : '';
|
|
2888
|
+
return res.concat(inheritedContext + item);
|
|
2889
|
+
}, [])
|
|
2890
|
+
.reverse() // Start with children, ends with parent key
|
|
2891
|
+
.map(function (contextItem) { return _this.contextualKey(key, contextItem); })
|
|
2892
|
+
.concat(key);
|
|
2874
2893
|
};
|
|
2875
2894
|
/**
|
|
2876
2895
|
* Compute a contextual i18n key, using the context as suffix
|
|
@@ -2890,6 +2909,25 @@
|
|
|
2890
2909
|
? "" + context + key
|
|
2891
2910
|
: parts.slice(0, parts.length - 1).concat(context + parts[parts.length - 1]).join('.');
|
|
2892
2911
|
};
|
|
2912
|
+
TranslateContextService.prototype.findFirstValid = function (keys, translations) {
|
|
2913
|
+
var e_1, _a;
|
|
2914
|
+
try {
|
|
2915
|
+
// For eac contextual key: try to find translation, then use the first valid
|
|
2916
|
+
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
2917
|
+
var key = keys_1_1.value;
|
|
2918
|
+
if (translations[key] !== key)
|
|
2919
|
+
return translations[key];
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2923
|
+
finally {
|
|
2924
|
+
try {
|
|
2925
|
+
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
|
2926
|
+
}
|
|
2927
|
+
finally { if (e_1) throw e_1.error; }
|
|
2928
|
+
}
|
|
2929
|
+
return undefined;
|
|
2930
|
+
};
|
|
2893
2931
|
return TranslateContextService;
|
|
2894
2932
|
}());
|
|
2895
2933
|
TranslateContextService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function TranslateContextService_Factory() { return new TranslateContextService(i0__namespace.ɵɵinject(i1__namespace$1.TranslateService)); }, token: TranslateContextService, providedIn: "root" });
|