@larscom/ngx-translate-module-loader
Advanced tools
Comparing version 1.1.0 to 1.2.0
import { IModuleTranslation } from './module-translation'; | ||
import { Translation } from './translation'; | ||
export interface IModuleTranslationOptions { | ||
@@ -23,3 +24,3 @@ /** | ||
/** | ||
* Function that gets executed if an http error occurred | ||
* Function that gets executed if an error occurred while retrieving a translation file | ||
* @param error the error that occurred | ||
@@ -29,2 +30,7 @@ * @param path the path to the location file | ||
translateError?: (error: any, path: string) => void; | ||
/** | ||
* Custom translate merge function after retrieving all translation files | ||
* @param translations the resolved translation files | ||
*/ | ||
translateMerger?: (translations: Translation[]) => Translation; | ||
} |
import { FileType } from './file-type'; | ||
import { Translation } from './translation'; | ||
export interface IModuleTranslation { | ||
@@ -30,2 +31,7 @@ /** | ||
nameSpace?: string; | ||
/** | ||
* Custom translation map function after retrieving a translation file | ||
* @param translation the resolved translation file | ||
*/ | ||
translateMap?: (translation: Translation) => Translation; | ||
} |
export { FileType } from './file-type'; | ||
export { Translation } from './translation'; | ||
export { IModuleTranslationOptions } from './module-translation-options'; | ||
export { IModuleTranslation } from './module-translation'; |
@@ -5,5 +5,3 @@ import { HttpClient } from '@angular/common/http'; | ||
import { IModuleTranslationOptions } from './models/module-translation-options'; | ||
export declare type Translation = { | ||
[x: string]: string; | ||
}; | ||
import { Translation } from './models/translation'; | ||
export declare class ModuleTranslateLoader implements TranslateLoader { | ||
@@ -10,0 +8,0 @@ private readonly http; |
@@ -47,8 +47,8 @@ "use strict"; | ||
var _this = this; | ||
var _a = this._defaultOptions, deepMerge = _a.deepMerge, enableNamespacing = _a.enableNamespacing, nameSpaceUppercase = _a.nameSpaceUppercase, modules = _a.modules, translateError = _a.translateError; | ||
var _a = this._defaultOptions, deepMerge = _a.deepMerge, enableNamespacing = _a.enableNamespacing, nameSpaceUppercase = _a.nameSpaceUppercase, modules = _a.modules, translateError = _a.translateError, translateMerger = _a.translateMerger; | ||
var moduleRequests = modules.map(function (_a) { | ||
var baseTranslateUrl = _a.baseTranslateUrl, moduleName = _a.moduleName, fileType = _a.fileType, nameSpace = _a.nameSpace; | ||
var baseTranslateUrl = _a.baseTranslateUrl, moduleName = _a.moduleName, fileType = _a.fileType, nameSpace = _a.nameSpace, translateMap = _a.translateMap; | ||
if (!moduleName) { | ||
var path = baseTranslateUrl + "/" + language + fileType; | ||
return _this.http.get(path).pipe(_this._catchError(path, translateError)); | ||
return _this.http.get(path).pipe(operators_1.map(function (translation) { return (translateMap ? translateMap(translation) : translation); }), _this._catchError(path, translateError)); | ||
} | ||
@@ -58,2 +58,5 @@ var modulePath = baseTranslateUrl + "/" + moduleName + "/" + language + fileType; | ||
var _a; | ||
if (translateMap) { | ||
return translateMap(translation); | ||
} | ||
if (!enableNamespacing) { | ||
@@ -73,2 +76,5 @@ return translation; | ||
return rxjs_1.forkJoin(moduleRequests).pipe(operators_1.map(function (translations) { | ||
if (translateMerger) { | ||
return translateMerger(translations); | ||
} | ||
return deepMerge | ||
@@ -75,0 +81,0 @@ ? deepmerge_1.default.all(translations) |
@@ -1,2 +0,2 @@ | ||
export { ModuleTranslateLoader, Translation } from './module-translate-loader'; | ||
export { ModuleTranslateLoader } from './module-translate-loader'; | ||
export * from './models/public_api'; |
{ | ||
"name": "@larscom/ngx-translate-module-loader", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Fetch multiple translation files (http) with ngx-translate. Each translations file gets it's own namespace out of the box", | ||
@@ -5,0 +5,0 @@ "main": "./dist/public_api.js", |
@@ -14,2 +14,3 @@ # @larscom/ngx-translate-module-loader | ||
## Demo | ||
@@ -156,3 +157,3 @@ | ||
/** | ||
* Function that gets executed if an http error occurred | ||
* Function that gets executed if an error occurred while retrieving a translation file | ||
* @param error the error that occurred | ||
@@ -162,2 +163,7 @@ * @param path the path to the location file | ||
translateError?: (error: any, path: string) => void; | ||
/** | ||
* Custom translate merge function after retrieving all translation files | ||
* @param translations the resolved translation files | ||
*/ | ||
translateMerger?: (translations: Translation[]) => Translation; | ||
} | ||
@@ -195,3 +201,8 @@ ``` | ||
nameSpace?: string; | ||
/** | ||
* Custom translation map function after retrieving a translation file | ||
* @param translation the resolved translation file | ||
*/ | ||
translationMap?: (translation: Translation) => Translation; | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24469
33
256
205