dfx-translate
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -30,21 +30,20 @@ (function (global, factory) { | ||
// noinspection JSUnusedLocalSymbols | ||
var Translator = /** @class */ (function () { | ||
function Translator(config, http) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b; | ||
this.config = config; | ||
this.http = http; | ||
this.translation = {}; | ||
this.autoGeneratedTranslation = {}; | ||
this.translations = {}; | ||
this.autoGeneratedTranslations = {}; | ||
this.defaultLanguage = 'de'; | ||
this.autoGeneratedDefaultLanguage = 'en'; | ||
this.defaultLanguage = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.defaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 2 ? (_c = this.config) === null || _c === void 0 ? void 0 : _c.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.autoGeneratedDefaultLanguage) === null || _e === void 0 ? void 0 : _e.length) > 2 ? (_f = this.config) === null || _f === void 0 ? void 0 : _f.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
this.defaultLanguage = ((_a = config === null || config === void 0 ? void 0 : config.defaultLanguage) === null || _a === void 0 ? void 0 : _a.length) > 0 ? config.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_b = config === null || config === void 0 ? void 0 : config.autoGeneratedDefaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 0 ? config.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
} | ||
Translator.prototype.translate = function (key) { | ||
if (this.translation[key]) { | ||
return this.translation[key]; | ||
if (this.translations[key]) { | ||
return this.translations[key]; | ||
} | ||
else if (this.autoGeneratedTranslation[key]) { | ||
return this.autoGeneratedTranslation[key]; | ||
else if (this.autoGeneratedTranslations[key]) { | ||
return this.autoGeneratedTranslations[key]; | ||
} | ||
@@ -58,11 +57,11 @@ else { | ||
if (lang === 'DEFAULT') { | ||
var langCookie = localStorage.getItem('language'); | ||
if (langCookie == null) { | ||
var language = localStorage.getItem('language'); | ||
if (language != null) { | ||
lang = language; | ||
console.log('Language cookie found! Using ' + lang); | ||
} | ||
else { | ||
lang = this.defaultLanguage; | ||
console.log('No language cookie found! Using de as default'); | ||
} | ||
else { | ||
console.log('Language cookie found! Using ' + lang); | ||
lang = langCookie; | ||
} | ||
} | ||
@@ -75,16 +74,18 @@ else { | ||
var langPath = "assets/i18n/" + (lang || _this.defaultLanguage) + ".json"; | ||
// noinspection JSUnusedLocalSymbols | ||
_this.http.get(langPath).subscribe(function (translation) { | ||
_this.translation = Object.assign({}, translation || {}); | ||
resolve(_this.translation); | ||
_this.translations = Object.assign({}, translation || {}); | ||
resolve(_this.translations); | ||
}, function (error) { | ||
_this.translation = {}; | ||
resolve(_this.translation); | ||
_this.translations = {}; | ||
resolve(_this.translations); | ||
}); | ||
var autoLangPath = "assets/i18n/" + (lang || _this.autoGeneratedDefaultLanguage) + "_auto.json"; | ||
// noinspection JSUnusedLocalSymbols | ||
_this.http.get(autoLangPath).subscribe(function (translation) { | ||
_this.autoGeneratedTranslation = Object.assign({}, translation || {}); | ||
resolve(_this.autoGeneratedTranslation); | ||
_this.autoGeneratedTranslations = Object.assign({}, translation || {}); | ||
resolve(_this.autoGeneratedTranslations); | ||
}, function (error) { | ||
_this.autoGeneratedTranslation = {}; | ||
resolve(_this.autoGeneratedTranslation); | ||
_this.autoGeneratedTranslations = {}; | ||
resolve(_this.autoGeneratedTranslations); | ||
}); | ||
@@ -110,11 +111,11 @@ }); | ||
var TranslatePipe = /** @class */ (function () { | ||
function TranslatePipe(translator) { | ||
this.translator = translator; | ||
function TranslatePipe(translate) { | ||
this.translate = translate; | ||
} | ||
TranslatePipe.prototype.transform = function (key) { | ||
if (this.translator.translation[key]) { | ||
return this.translator.translation[key]; | ||
if (this.translate.translations[key]) { | ||
return this.translate.translations[key]; | ||
} | ||
else if (this.translator.autoGeneratedTranslation[key]) { | ||
return this.translator.autoGeneratedTranslation[key]; | ||
else if (this.translate.autoGeneratedTranslations[key]) { | ||
return this.translate.autoGeneratedTranslations[key]; | ||
} | ||
@@ -129,10 +130,7 @@ else { | ||
TranslatePipe.ɵpipe = i0__namespace.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0__namespace, type: TranslatePipe, name: "tr", pure: false }); | ||
TranslatePipe.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0__namespace, type: TranslatePipe }); | ||
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0__namespace, type: TranslatePipe, decorators: [{ | ||
type: i0.Injectable | ||
}, { | ||
type: i0.Pipe, | ||
args: [{ | ||
name: 'tr', | ||
pure: false | ||
pure: false, | ||
}] | ||
@@ -148,3 +146,3 @@ }], ctorParameters: function () { return [{ type: Translator }]; } }); | ||
ngModule: DfxTranslateModule, | ||
providers: [{ provide: 'config', useValue: configuration },] | ||
providers: [{ provide: 'config', useValue: configuration }] | ||
}; | ||
@@ -151,0 +149,0 @@ }; |
import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||
import { TranslatePipe } from "./translate.pipe"; | ||
import { TranslatePipe } from './translate.pipe'; | ||
import { Translator } from "./translator.service"; | ||
@@ -10,3 +10,3 @@ import * as i0 from "@angular/core"; | ||
ngModule: DfxTranslateModule, | ||
providers: [{ provide: 'config', useValue: configuration },] | ||
providers: [{ provide: 'config', useValue: configuration }] | ||
}; | ||
@@ -43,2 +43,2 @@ } | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGZ4LXRyYW5zbGF0ZS5tb2R1bGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9kZngtdHJhbnNsYXRlL3NyYy9saWIvZGZ4LXRyYW5zbGF0ZS5tb2R1bGUudHMiXSwibmFt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uICAgICAgdXNlRmFjdG9yeTogc2V0dXBUcmFuc2xhdGVGYWN0b3J5LFxuICAgICAgZGVwczogW1RyYW5zbGF0b3JdLFxuICAgICAgbXVsdGk6IHRydWVcbiAgICB9LFxuICBdXG59KVxuZXhwb3J0IGNsYXNzIERmeFRyYW5zbGF0ZU1vZHVsZSB7XG4gIHN0YXRpYyBjb25maWcoY29uZmlndXJhdGlvbjogYW55KTogTW9kdWxlV2l0aFByb3ZpZGVyczxEZnhUcmFuc2xhdGVNb2R1bGU+IHtcbiAgICBjb25zb2xlLmxvZyhjb25maWd1cmF0aW9uKTtcbiAgICByZXR1cm4ge1xuICAgICAgbmdNb2R1bGU6IERmeFRyYW5zbGF0ZU1vZHVsZSxcbiAgICAgIHByb3ZpZGVyczogW3twcm92aWRlOiAnY29uZmlnJywgdXNlVmFsdWU6IGNvbmZpZ3VyYXRpb259XVxuICAgIH07XG4gIH1cbn1cblxuZXhwb3J0IGZ1bmN0aW9uIHNldHVwVHJhbnNsYXRlRmFjdG9yeShzZXJ2aWNlOiBUcmFuc2xhdG9yKTogRnVuY3Rpb24ge1xuICByZXR1cm4gKCkgPT4gc2VydmljZS51c2UoJ0RFRkFVTFQnKTtcbn1cbiJdfQ== |
@@ -1,14 +0,14 @@ | ||
import { Injectable, Pipe } from '@angular/core'; | ||
import { Pipe } from '@angular/core'; | ||
import * as i0 from "@angular/core"; | ||
import * as i1 from "./translator.service"; | ||
export class TranslatePipe { | ||
constructor(translator) { | ||
this.translator = translator; | ||
constructor(translate) { | ||
this.translate = translate; | ||
} | ||
transform(key) { | ||
if (this.translator.translation[key]) { | ||
return this.translator.translation[key]; | ||
if (this.translate.translations[key]) { | ||
return this.translate.translations[key]; | ||
} | ||
else if (this.translator.autoGeneratedTranslation[key]) { | ||
return this.translator.autoGeneratedTranslation[key]; | ||
else if (this.translate.autoGeneratedTranslations[key]) { | ||
return this.translate.autoGeneratedTranslations[key]; | ||
} | ||
@@ -22,12 +22,9 @@ else { | ||
TranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe, name: "tr", pure: false }); | ||
TranslatePipe.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe }); | ||
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe, decorators: [{ | ||
type: Injectable | ||
}, { | ||
type: Pipe, | ||
args: [{ | ||
name: 'tr', | ||
pure: false | ||
pure: false, | ||
}] | ||
}], ctorParameters: function () { return [{ type: i1.Translator }]; } }); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNsYXRlLnBpcGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9kZngtdHJhbnNsYXRlL3NyYy9saWIvdHJhbnNsYXRlLnBpcGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFDLFVBQVUsRUFBRSxJQUFJLEVBQWdCLE1BQU0sZUFBZSxDQUFDOzs7QUFROUQsTUFBTSxPQUFPLGFBQWE7SUFDeEIsWUFBb0IsVUFBc0I7UUFBdEIsZUFBVSxHQUFWLFVBQVUsQ0FBWTtJQUFHLENBQUM7SUFFOUMsU0FBUyxDQUFDLEdBQVE7UUFDaEIsSUFBSSxJQUFJLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsRUFBRTtZQUNwQyxPQUFPLElBQUksQ0FBQyxVQUFVLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxDQUFDO1NBQ3pDO2FBQU0sSUFBSSxJQUFJLENBQUMsVUFBVSxDQUFDLHdCQUF3QixDQUFDLEdBQUcsQ0FBQyxFQUFFO1lBQ3hELE9BQU8sSUFBSSxDQUFDLFVBQVUsQ0FBQyx3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uc2VydmljZSc7XG5cbkBQaXBlKHtcbiAgbmFtZTogJ3RyJyxcbiAgcHVyZTogZmFsc2UsXG59KVxuZXhwb3J0IGNsYXNzIFRyYW5zbGF0ZVBpcGUgaW1wbGVtZW50cyBQaXBlVHJhbnNmb3JtIHtcbiAgY29uc3RydWN0b3IocHJpdmF0ZSB0cmFuc2xhdGU6IFRyYW5zbGF0b3IpIHt9XG5cbiAgdHJhbnNmb3JtKGtleTogYW55KTogYW55IHtcbiAgICBpZiAodGhpcy50cmFuc2xhdGUudHJhbnNsYXRpb25zW2tleV0pIHtcbiAgICAgIHJldHVybiB0aGlzLnRyYW5zbGF0ZS50cmFuc2xhdGlvbnNba2V5XTtcbiAgICB9IGVsc2UgaWYgKHRoaXMudHJhbnNsYXRlLmF1dG9HZW5lcmF0ZWRUcmFuc2xhdGlvbnNba2V5XSkge1xuICAgICAgcmV0dXJuIHRoaXMudHJhbnNsYXRlLmF1dG9HZW5lcmF0ZWRUcmFuc2xhdGlvbnNba2V5XTtcbiAgICB9IGVsc2Uge1xuICAgICAgcmV0dXJuIGtleTtcbiAgICB9XG4gIH1cbn1cbiJdfQ== |
import { Inject, Injectable } from '@angular/core'; | ||
import * as i0 from "@angular/core"; | ||
import * as i1 from "@angular/common/http"; | ||
// noinspection JSUnusedLocalSymbols | ||
export class Translator { | ||
constructor(config, http) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b; | ||
this.config = config; | ||
this.http = http; | ||
this.translation = {}; | ||
this.autoGeneratedTranslation = {}; | ||
this.translations = {}; | ||
this.autoGeneratedTranslations = {}; | ||
this.defaultLanguage = 'de'; | ||
this.autoGeneratedDefaultLanguage = 'en'; | ||
this.defaultLanguage = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.defaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 2 ? (_c = this.config) === null || _c === void 0 ? void 0 : _c.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.autoGeneratedDefaultLanguage) === null || _e === void 0 ? void 0 : _e.length) > 2 ? (_f = this.config) === null || _f === void 0 ? void 0 : _f.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
this.defaultLanguage = ((_a = config === null || config === void 0 ? void 0 : config.defaultLanguage) === null || _a === void 0 ? void 0 : _a.length) > 0 ? config.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_b = config === null || config === void 0 ? void 0 : config.autoGeneratedDefaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 0 ? config.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
} | ||
translate(key) { | ||
if (this.translation[key]) { | ||
return this.translation[key]; | ||
if (this.translations[key]) { | ||
return this.translations[key]; | ||
} | ||
else if (this.autoGeneratedTranslation[key]) { | ||
return this.autoGeneratedTranslation[key]; | ||
else if (this.autoGeneratedTranslations[key]) { | ||
return this.autoGeneratedTranslations[key]; | ||
} | ||
@@ -30,11 +29,11 @@ else { | ||
if (lang === 'DEFAULT') { | ||
const langCookie = localStorage.getItem('language'); | ||
if (langCookie == null) { | ||
const language = localStorage.getItem('language'); | ||
if (language != null) { | ||
lang = language; | ||
console.log('Language cookie found! Using ' + lang); | ||
} | ||
else { | ||
lang = this.defaultLanguage; | ||
console.log('No language cookie found! Using de as default'); | ||
} | ||
else { | ||
console.log('Language cookie found! Using ' + lang); | ||
lang = langCookie; | ||
} | ||
} | ||
@@ -47,16 +46,18 @@ else { | ||
const langPath = `assets/i18n/${lang || this.defaultLanguage}.json`; | ||
// noinspection JSUnusedLocalSymbols | ||
this.http.get(langPath).subscribe((translation) => { | ||
this.translation = Object.assign({}, translation || {}); | ||
resolve(this.translation); | ||
this.translations = Object.assign({}, translation || {}); | ||
resolve(this.translations); | ||
}, (error) => { | ||
this.translation = {}; | ||
resolve(this.translation); | ||
this.translations = {}; | ||
resolve(this.translations); | ||
}); | ||
const autoLangPath = `assets/i18n/${lang || this.autoGeneratedDefaultLanguage}_auto.json`; | ||
// noinspection JSUnusedLocalSymbols | ||
this.http.get(autoLangPath).subscribe((translation) => { | ||
this.autoGeneratedTranslation = Object.assign({}, translation || {}); | ||
resolve(this.autoGeneratedTranslation); | ||
this.autoGeneratedTranslations = Object.assign({}, translation || {}); | ||
resolve(this.autoGeneratedTranslations); | ||
}, (error) => { | ||
this.autoGeneratedTranslation = {}; | ||
resolve(this.autoGeneratedTranslation); | ||
this.autoGeneratedTranslations = {}; | ||
resolve(this.autoGeneratedTranslations); | ||
}); | ||
@@ -77,2 +78,2 @@ }); | ||
}] }, { type: i1.HttpClient }]; } }); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNsYXRvci5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvZGZ4LXRyYW5zbGF0ZS9zcmMvbGliL3RyYW5zbGF0b3Iuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUMsTUFBTSxFQUFFLFVBQVUsRUFBQyxNQUFNLGVBQWUsQ0FBQzs7O0FBRWpELG9DQUFvQztBQUlwQyxNQUFNLE9BQU8sVUFBVTtJQU9yQixZQUFzQyxNQUFXLEVBQVUsSUFBZ0I7O1FBQXJDLFdBQU0sR0FBTixNQUFNLENBQUs7UUFBVSxTQUFJLEdBQUosSUFBSSxDQUFZO1FBTjNFLGdCQUFXLEdBQVEsRUFBRSxDQUFDO1FBQ3RCLDZCQUF3QixHQUFRLEVBQUUsQ0FBQztRQUVuQyxvQkFBZSxHQUFHLElBQUksQ0FBQztRQUN2QixpQ0FBNEIsR0FBRyxJQUFJLENBQUM7UUFHbEMsSUFBSSxDQUFDLGVBQWUsR0FBRyxDQUFBLE1BQUEsTUFBQSxJQUFJLENBQUMsTUFBTSwwQ0FBRSxlQUFl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ICAgIHRoaXMudHJhbnNsYXRpb25zID0ge307XG4gICAgICAgICAgcmVzb2x2ZSh0aGlzLnRyYW5zbGF0aW9ucyk7XG4gICAgICAgIH1cbiAgICAgICk7XG5cbiAgICAgIGNvbnN0IGF1dG9MYW5nUGF0aCA9IGBhc3NldHMvaTE4bi8ke2xhbmcgfHwgdGhpcy5hdXRvR2VuZXJhdGVkRGVmYXVsdExhbmd1YWdlfV9hdXRvLmpzb25gO1xuICAgICAgLy8gbm9pbnNwZWN0aW9uIEpTVW51c2VkTG9jYWxTeW1ib2xzXG4gICAgICB0aGlzLmh0dHAuZ2V0PHt9PihhdXRvTGFuZ1BhdGgpLnN1YnNjcmliZShcbiAgICAgICAgKHRyYW5zbGF0aW9uKSA9PiB7XG4gICAgICAgICAgdGhpcy5hdXRvR2VuZXJhdGVkVHJhbnNsYXRpb25zID0gT2JqZWN0LmFzc2lnbih7fSwgdHJhbnNsYXRpb24gfHwge30pO1xuICAgICAgICAgIHJlc29sdmUodGhpcy5hdXRvR2VuZXJhdGVkVHJhbnNsYXRpb25zKTtcbiAgICAgICAgfSxcbiAgICAgICAgKGVycm9yKSA9PiB7XG4gICAgICAgICAgdGhpcy5hdXRvR2VuZXJhdGVkVHJhbnNsYXRpb25zID0ge307XG4gICAgICAgICAgcmVzb2x2ZSh0aGlzLmF1dG9HZW5lcmF0ZWRUcmFuc2xhdGlvbnMpO1xuICAgICAgICB9XG4gICAgICApO1xuICAgIH0pO1xuICB9XG59XG4iXX0= |
@@ -5,21 +5,20 @@ import * as i0 from '@angular/core'; | ||
// noinspection JSUnusedLocalSymbols | ||
class Translator { | ||
constructor(config, http) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b; | ||
this.config = config; | ||
this.http = http; | ||
this.translation = {}; | ||
this.autoGeneratedTranslation = {}; | ||
this.translations = {}; | ||
this.autoGeneratedTranslations = {}; | ||
this.defaultLanguage = 'de'; | ||
this.autoGeneratedDefaultLanguage = 'en'; | ||
this.defaultLanguage = ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.defaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 2 ? (_c = this.config) === null || _c === void 0 ? void 0 : _c.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.autoGeneratedDefaultLanguage) === null || _e === void 0 ? void 0 : _e.length) > 2 ? (_f = this.config) === null || _f === void 0 ? void 0 : _f.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
this.defaultLanguage = ((_a = config === null || config === void 0 ? void 0 : config.defaultLanguage) === null || _a === void 0 ? void 0 : _a.length) > 0 ? config.defaultLanguage : this.defaultLanguage; | ||
this.autoGeneratedDefaultLanguage = ((_b = config === null || config === void 0 ? void 0 : config.autoGeneratedDefaultLanguage) === null || _b === void 0 ? void 0 : _b.length) > 0 ? config.autoGeneratedDefaultLanguage : this.autoGeneratedDefaultLanguage; | ||
} | ||
translate(key) { | ||
if (this.translation[key]) { | ||
return this.translation[key]; | ||
if (this.translations[key]) { | ||
return this.translations[key]; | ||
} | ||
else if (this.autoGeneratedTranslation[key]) { | ||
return this.autoGeneratedTranslation[key]; | ||
else if (this.autoGeneratedTranslations[key]) { | ||
return this.autoGeneratedTranslations[key]; | ||
} | ||
@@ -32,11 +31,11 @@ else { | ||
if (lang === 'DEFAULT') { | ||
const langCookie = localStorage.getItem('language'); | ||
if (langCookie == null) { | ||
const language = localStorage.getItem('language'); | ||
if (language != null) { | ||
lang = language; | ||
console.log('Language cookie found! Using ' + lang); | ||
} | ||
else { | ||
lang = this.defaultLanguage; | ||
console.log('No language cookie found! Using de as default'); | ||
} | ||
else { | ||
console.log('Language cookie found! Using ' + lang); | ||
lang = langCookie; | ||
} | ||
} | ||
@@ -49,16 +48,18 @@ else { | ||
const langPath = `assets/i18n/${lang || this.defaultLanguage}.json`; | ||
// noinspection JSUnusedLocalSymbols | ||
this.http.get(langPath).subscribe((translation) => { | ||
this.translation = Object.assign({}, translation || {}); | ||
resolve(this.translation); | ||
this.translations = Object.assign({}, translation || {}); | ||
resolve(this.translations); | ||
}, (error) => { | ||
this.translation = {}; | ||
resolve(this.translation); | ||
this.translations = {}; | ||
resolve(this.translations); | ||
}); | ||
const autoLangPath = `assets/i18n/${lang || this.autoGeneratedDefaultLanguage}_auto.json`; | ||
// noinspection JSUnusedLocalSymbols | ||
this.http.get(autoLangPath).subscribe((translation) => { | ||
this.autoGeneratedTranslation = Object.assign({}, translation || {}); | ||
resolve(this.autoGeneratedTranslation); | ||
this.autoGeneratedTranslations = Object.assign({}, translation || {}); | ||
resolve(this.autoGeneratedTranslations); | ||
}, (error) => { | ||
this.autoGeneratedTranslation = {}; | ||
resolve(this.autoGeneratedTranslation); | ||
this.autoGeneratedTranslations = {}; | ||
resolve(this.autoGeneratedTranslations); | ||
}); | ||
@@ -81,11 +82,11 @@ }); | ||
class TranslatePipe { | ||
constructor(translator) { | ||
this.translator = translator; | ||
constructor(translate) { | ||
this.translate = translate; | ||
} | ||
transform(key) { | ||
if (this.translator.translation[key]) { | ||
return this.translator.translation[key]; | ||
if (this.translate.translations[key]) { | ||
return this.translate.translations[key]; | ||
} | ||
else if (this.translator.autoGeneratedTranslation[key]) { | ||
return this.translator.autoGeneratedTranslation[key]; | ||
else if (this.translate.autoGeneratedTranslations[key]) { | ||
return this.translate.autoGeneratedTranslations[key]; | ||
} | ||
@@ -99,10 +100,7 @@ else { | ||
TranslatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe, name: "tr", pure: false }); | ||
TranslatePipe.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe }); | ||
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.0", ngImport: i0, type: TranslatePipe, decorators: [{ | ||
type: Injectable | ||
}, { | ||
type: Pipe, | ||
args: [{ | ||
name: 'tr', | ||
pure: false | ||
pure: false, | ||
}] | ||
@@ -116,3 +114,3 @@ }], ctorParameters: function () { return [{ type: Translator }]; } }); | ||
ngModule: DfxTranslateModule, | ||
providers: [{ provide: 'config', useValue: configuration },] | ||
providers: [{ provide: 'config', useValue: configuration }] | ||
}; | ||
@@ -119,0 +117,0 @@ } |
import { PipeTransform } from '@angular/core'; | ||
import { Translator } from "./translator.service"; | ||
import { Translator } from './translator.service'; | ||
import * as i0 from "@angular/core"; | ||
export declare class TranslatePipe implements PipeTransform { | ||
private translator; | ||
constructor(translator: Translator); | ||
private translate; | ||
constructor(translate: Translator); | ||
transform(key: any): any; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<TranslatePipe, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<TranslatePipe, "tr">; | ||
static ɵprov: i0.ɵɵInjectableDeclaration<TranslatePipe>; | ||
} |
@@ -6,8 +6,8 @@ import { HttpClient } from '@angular/common/http'; | ||
private http; | ||
translation: any; | ||
autoGeneratedTranslation: any; | ||
translations: any; | ||
autoGeneratedTranslations: any; | ||
defaultLanguage: string; | ||
autoGeneratedDefaultLanguage: string; | ||
constructor(config: any, http: HttpClient); | ||
translate(key: string): string; | ||
translate(key: string): any; | ||
use(lang: string): Promise<{}>; | ||
@@ -14,0 +14,0 @@ static ɵfac: i0.ɵɵFactoryDeclaration<Translator, never>; |
{ | ||
"name": "dfx-translate", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"private": false, | ||
"description": "Translation package for Angular", | ||
"main": "bundles/dfx-translate.umd.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://gitlab.com/DatePoll/common/dfx-translate.git" | ||
}, | ||
"license": "MIT", | ||
"homepage": "https://datepoll.org", | ||
"keywords": [ | ||
@@ -20,10 +16,12 @@ "angular2", | ||
"author": "Dafnik", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://gitlab.com/DatePoll/common/dfx-translate/issues" | ||
}, | ||
"homepage": "https://datepoll.org", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://gitlab.com/DatePoll/common/dfx-translate.git" | ||
}, | ||
"peerDependencies": { | ||
"@angular/common": "^12|^11|^10|^9|^8|^7|^6", | ||
"@angular/core": "^12|^11|^10|^9|^8|^7|^6", | ||
"@angular/common": "^12.1.0", | ||
"@angular/core": "^12.1.0", | ||
"node-fetch": "^2.6.1" | ||
@@ -34,2 +32,3 @@ }, | ||
}, | ||
"main": "bundles/dfx-translate.umd.js", | ||
"module": "fesm2015/dfx-translate.js", | ||
@@ -36,0 +35,0 @@ "es2015": "fesm2015/dfx-translate.js", |
@@ -1,24 +0,3 @@ | ||
# DfxTranslate | ||
# dfx-translate | ||
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.1.0. | ||
## Code scaffolding | ||
Run `ng generate component component-name --project dfx-translate` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project dfx-translate`. | ||
> Note: Don't forget to add `--project dfx-translate` or else it will be added to the default project in your `angular.json` file. | ||
## Build | ||
Run `ng build dfx-translate` to build the project. The build artifacts will be stored in the `dist/` directory. | ||
## Publishing | ||
After building your library with `ng build dfx-translate`, go to the dist folder `cd dist/dfx-translate` and run `npm publish`. | ||
## Running unit tests | ||
Run `ng test dfx-translate` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
## Further help | ||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
61443
746
4
2