
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
@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.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.