UNPKG

laravel-jstools

Version:

JS tools for building front-side of Laravel applications

35 lines (34 loc) 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TranslateService = void 0; const laravel_jstools_di_1 = require("laravel-jstools-di"); const helpers_1 = require("../../scripts/helpers"); class TranslateService extends laravel_jstools_di_1.Service { constructor(data) { super(); this.namespaceList = { rules: 'app.validation', omxCommon: 'vendor.support.common', omxCurrency: 'vendor.support.currency', }; this.langDefault = data.langDefault; this.langCurrent = data.langCurrent; this.translationList = data.translationList; } t(key, replaceList, lang) { const locale = lang === undefined ? this.langCurrent : lang; let text = (0, helpers_1.getProp)(this.translationList, `${locale}.${key}`); for (const prop of Object.keys(replaceList || {})) { text = text.replace(`:${prop}`, replaceList[prop]); } return text; } t__validate(rule, replaceList, lang) { const attr = 'attribute'; if (attr in replaceList) { replaceList[attr] = this.t(`${this.namespaceList.rules}.attributes.${replaceList[attr]}`, {}, lang); } return this.t(`${this.namespaceList.rules}.${rule}`, replaceList, lang); } } exports.TranslateService = TranslateService;