
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@xss-shared-library/translations
Advanced tools
This library provides translation support for Angular applications using `@ngx-translate`. It simplifies the process of managing multilingual support by offering tools to load, fetch, and use translation files dynamically.
This library provides translation support for Angular applications using @ngx-translate
. It simplifies the process of managing multilingual support by offering tools to load, fetch, and use translation files dynamically.
@ngx-translate
library.To install the library, run the following command:
npm install @xss-shared-library/translations
Add the XSSTranslationModule
to your Angular application's module:
import { XSSTranslationModule } from '@xss-shared-library/translations';
@NgModule({
imports: [
XSSTranslationModule
]
})
export class AppModule { }
Use the XSSTranslationService
to fetch translations dynamically in your components:
import { Component } from '@angular/core';
import { XSSTranslationService } from '@xss-shared-library/translations';
@Component({
selector: 'app-root',
template: `<h1>{{ translatedText }}</h1>`
})
export class AppComponent {
translatedText: string = '';
constructor(private translationService: XSSTranslationService) {
this.translatedText = this.translationService.getTranslatedValue('app.title');
}
}
The XSSTranslationService
provides a method to dynamically change the language at runtime:
import { Component } from '@angular/core';
import { XSSTranslationService } from '@xss-shared-library/translations';
@Component({
selector: 'app-root',
template: `
<button (click)="changeLanguage('en')">English</button>
<button (click)="changeLanguage('fr')">French</button>
`
})
export class AppComponent {
constructor(private translationService: XSSTranslationService) {}
async changeLanguage(language: string): Promise<void> {
try {
await this.translationService.changeLanguage(language);
console.log(`Language changed to ${language}`);
} catch (error) {
console.error('Failed to change language:', error.message);
}
}
}
Place your translation files in the assets/i18n/
directory. For example:
assets/i18n/en.json
:
{
"app": {
"title": "Welcome to the Application"
}
}
assets/i18n/fr.json
:
{
"app": {
"title": "Bienvenue dans l'application"
}
}
The changeLanguage
method in the XSSTranslationService
will throw an error if the specified language file is not found. Ensure that all required translation files are available in the assets/i18n/
directory.
Example:
try {
await this.translationService.changeLanguage('es'); // Switch to Spanish
} catch (error) {
console.error('Error:', error.message); // Handle missing translation file
}
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
This library is licensed under the MIT License. See the LICENSE
file for more details.
For more help with the Angular CLI, use ng help
or check out the Angular CLI Overview and Command Reference page.
FAQs
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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.