![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@larscom/ngx-translate-module-loader
Advanced tools
Highly configurable and flexible translations loader for ngx-translate. Fetch multiple translations, each translation file gets it's own namespace by default
Highly configurable and flexible translations loader for @ngx-translate/core.
Fetch multiple translations (http only) and configure them to your needs.
Each translation file has it's own namespace out of the box so the key/value pairs do not conflict with each other. You can disable namespaces or provide your own value as well.
You can play arround on StackBlitz: https://stackblitz.com/edit/ngx-translate-module-loader
@larscom/ngx-translate-module-loader
depends on @ngx-translate/core and Angular.
npm i --save @larscom/ngx-translate-module-loader
1. create an exported moduleHttpLoaderFactory
function
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { ModuleTranslateLoader, IModuleTranslationOptions } from '@larscom/ngx-translate-module-loader';
import { AppComponent } from './app';
export function moduleHttpLoaderFactory(http: HttpClient) {
const baseTranslateUrl = './assets/i18n';
const options: IModuleTranslationOptions = {
modules: [
// final url: ./assets/i18n/en.json
{ baseTranslateUrl },
// final url: ./assets/i18n/feature1/en.json
{ moduleName: 'feature1', baseTranslateUrl },
// final url: ./assets/i18n/feature2/en.json
{ moduleName: 'feature2', baseTranslateUrl }
]
};
return new ModuleTranslateLoader(http, options);
}
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: moduleHttpLoaderFactory,
deps: [HttpClient]
}
})
],
bootstrap: [AppComponent]
})
export class AppModule {}
By default, each translation file gets it's own namespace based on the moduleName
, what does it mean?
For example with these options:
export function moduleHttpLoaderFactory(http: HttpClient) {
const baseTranslateUrl = './assets/i18n';
const options: IModuleTranslationOptions = {
modules: [
// no moduleName/namespace
{ baseTranslateUrl },
// namespace: FEATURE1
{ moduleName: 'feature1', baseTranslateUrl },
// namespace: FEATURE2
{ moduleName: 'feature2', baseTranslateUrl }
]
};
return new ModuleTranslateLoader(http, options);
}
Lets say each module in the above example resolves to the following translation:
{
"KEY: "VALUE"
}
The final result would then be:
{
"KEY: "VALUE",
"FEATURE1" : {
"KEY: "VALUE"
},
"FEATURE2" : {
"KEY: "VALUE"
}
}
If you don't want uppercase keys, set lowercaseNamespace
to true in the options because it's uppercase by default.
If you don't want namespaces at all, set disableNamespace
to true.
You can override the default name space by setting the namespace
property in the options.
export interface IModuleTranslationOptions {
/**
* The translation module configurations
*/
modules: IModuleTranslation[];
/**
* By default, each module gets its own namespace so it doesn't conflict with other modules
*/
disableNamespace?: boolean;
/**
* By default, namespaces are uppercase
*/
lowercaseNamespace?: boolean;
/**
* By default, it'll perform a deepmerge when merging translation files
*/
deepMerge?: boolean;
/**
* Function that gets executed if an error occurred while retrieving a translation file
* @param error the error that occurred
* @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;
/**
* Custom module path template for fetching translations
* @example
* '{baseTranslateUrl}/{moduleName}/{language}'
*/
modulePathTemplate?: string;
/**
* Custom path template for fetching translations
* @example
* '{baseTranslateUrl}/{language}'
*/
pathTemplate?: string;
}
export interface IModuleTranslation {
/**
* The module name
*
* For example: shared
* @description omit moduleName if you have a translate file at baseTranslateUrl level
* @see baseTranslateUrl
*/
moduleName?: string;
/**
* The base translate URL
*
* For example: ./assets/i18n
* @description the final url will then be: ./assets/i18n/shared if the moduleName is shared
* @see moduleName
*/
baseTranslateUrl: string;
/**
* By default, it uses the moduleName as namespace
* @see moduleName
*
* Use this property if you want to override the default nameSpace
*/
namespace?: string;
/**
* Custom translation map function after retrieving a translation file
* @param translation the resolved translation file
*/
translateMap?: (translation: Translation) => Translation;
}
By default, module translations gets fetched by using the following template:
'{baseTranslateUrl}/{moduleName}/{language}'
e.g.: ./assets/feature1/en.json
You can override this option if you wish to do so:
const options: IModuleTranslationOptions = {
...
// translates to: ./assets/en/feature1.json
modulePathTemplate: '{baseTranslateUrl}/{language}/{moduleName}'
};
FAQs
Highly configurable and flexible translations loader for ngx-translate. Fetch multiple translations, each translation file gets it's own namespace by default
The npm package @larscom/ngx-translate-module-loader receives a total of 4,019 weekly downloads. As such, @larscom/ngx-translate-module-loader popularity was classified as popular.
We found that @larscom/ngx-translate-module-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.