@totvs-agro/core-mobile
Version:
Core Mobile Totvs Agro (Front-End) para utilização dos estilos do T-Faces
140 lines • 6.54 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from "@angular/core";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { coreMobileEn } from "../../i18n/core-mobile-en";
import { coreMobilePt } from "../../i18n/core-mobile-pt";
import { coreMobileEs } from "../../i18n/core-mobile-es";
var TotvsTranslateProvider = /** @class */ (function () {
function TotvsTranslateProvider() {
this.getFromBetween = {
results: [],
string: "",
getFromBetween: function (sub1, sub2) {
if (this.string.indexOf(sub1) < 0 || this.string.indexOf(sub2) < 0)
return false;
var SP = this.string.indexOf(sub1) + sub1.length;
var string1 = this.string.substr(0, SP);
var string2 = this.string.substr(SP);
var TP = string1.length + string2.indexOf(sub2);
return this.string.substring(SP, TP);
},
removeFromBetween: function (sub1, sub2) {
if (this.string.indexOf(sub1) < 0 || this.string.indexOf(sub2) < 0)
return false;
var removal = sub1 + this.getFromBetween(sub1, sub2) + sub2;
this.string = this.string.replace(removal, "");
},
getAllResults: function (sub1, sub2) {
// first check to see if we do have both substrings
if (this.string.indexOf(sub1) < 0 || this.string.indexOf(sub2) < 0)
return;
// find one result
var result = this.getFromBetween(sub1, sub2);
// push it to the results array
this.results.push(result);
// remove the most recently found one from the string
this.removeFromBetween(sub1, sub2);
// if there's more substrings
if (this.string.indexOf(sub1) > -1 && this.string.indexOf(sub2) > -1) {
this.getAllResults(sub1, sub2);
}
else
return;
},
get: function (string, sub1, sub2) {
this.results = [];
this.string = string;
this.getAllResults(sub1, sub2);
return this.results;
}
};
}
//PUBLICOS
TotvsTranslateProvider.prototype.initialize = function (lang) {
this.language = lang ? lang : window.navigator.language;
this.i18n = {};
this.i18n["PT-BR"] = coreMobilePt;
this.i18n["ES-ES"] = coreMobileEs;
this.i18n["EN-US"] = coreMobileEn;
};
;
TotvsTranslateProvider.prototype.initializeWithJson = function (json) {
this.i18n = {};
this.i18n = json;
};
;
TotvsTranslateProvider.prototype.instant = function (message) {
if (!this.i18n)
this.initialize();
return this.findMessage(message);
};
;
TotvsTranslateProvider.prototype.get = function (keys, _component, interpolateParams) {
var retorno = {};
var translatedKey = "";
var paramsFromTranslatedKey = "";
if (!(typeof keys === 'string')) {
for (var key in keys) {
translatedKey = this.instant(keys[key]);
paramsFromTranslatedKey = this.getFromBetween.get(translatedKey, "{{", "}}");
translatedKey = this.fillParameters(paramsFromTranslatedKey, translatedKey, interpolateParams);
retorno[keys[key]] = translatedKey;
}
return retorno;
}
else {
translatedKey = this.instant(String(keys));
paramsFromTranslatedKey = this.getFromBetween.get(translatedKey, "{{", "}}");
translatedKey = this.fillParameters(paramsFromTranslatedKey, translatedKey, interpolateParams);
return translatedKey;
}
};
;
//PRIVADOS
TotvsTranslateProvider.prototype.findMessage = function (_message) {
try {
if (undefined != this.i18n && null != this.i18n) {
var msg = this.i18n[this.language.toUpperCase()];
var split = String(_message).split(".");
for (var m in split) {
if (undefined != msg[split[m]] && null != msg[split[m]])
msg = msg[split[m]];
else
msg = _message;
}
return msg;
}
}
catch (e) {
return _message;
}
};
;
TotvsTranslateProvider.prototype.fillParameters = function (paramsFromTranslatedKey, translatedKey, interpolateParams) {
for (var _i = 0, paramsFromTranslatedKey_1 = paramsFromTranslatedKey; _i < paramsFromTranslatedKey_1.length; _i++) {
var paramFromTranslatedKey = paramsFromTranslatedKey_1[_i];
var valueFromParamFromTranslatedKey = paramFromTranslatedKey;
if (null != interpolateParams && undefined != interpolateParams && interpolateParams.hasOwnProperty(paramFromTranslatedKey))
valueFromParamFromTranslatedKey = interpolateParams[paramFromTranslatedKey];
translatedKey = translatedKey.replace("{{" + paramFromTranslatedKey + "}}", this.instant(valueFromParamFromTranslatedKey));
}
return translatedKey;
};
;
TotvsTranslateProvider = __decorate([
Injectable(),
__metadata("design:paramtypes", [])
], TotvsTranslateProvider);
return TotvsTranslateProvider;
}());
export { TotvsTranslateProvider };
//# sourceMappingURL=totvs-translate-provider.js.map