8000 GitHub - LearnXplor/core: The internationalization (i18n) library for Angular
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

LearnXplor/core

 
 

Repository files navigation

ngx-translate/core Readme Introduction Welcome to the readme file for the @ngx-translate/core library. This library is a part of the Angular ecosystem and provides internationalization (i18n) and localization (l10n) support for Angular applications.

Installation To get started with @ngx-translate/core, you need to install it in your Angular project. You can do this using npm or yarn:

bash Copy code npm install @ngx-translate/core --save

or

yarn add @ngx-translate/core Usage Once you have installed the @ngx-translate/core library, you can use it in your Angular application to add internationalization and localization support.

Import the necessary modules in your Angular app module (e.g., app.module.ts):

typescript Copy code import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { HttpClientModule, HttpClient } from '@angular/common/http'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslateHttpLoader } from '@ngx-translate/http-loader';

// Create a loader for translations export function createTranslateLoader(http: HttpClient) { return new TranslateHttpLoader(http, './assets/i18n/', '.json'); }

@NgModule({ declarations: [ // ... ], imports: [ BrowserModule, HttpClientModule, TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: createTranslateLoader, deps: [HttpClient], }, }), ], bootstrap: [AppComponent], }) export class AppModule {} Create translation JSON files for different languages in the assets/i18n/ folder of your project. For example, you can have files like en.json, fr.json, de.json, etc., with translations for each language.

In your components or templates, you can use the translate pipe to display translated text:

html Copy code

{{ 'HELLO_WORLD' | translate }}

In your TypeScript code, you can use the TranslateService to change the current language and manage translations programmatically:

typescript Copy code import { Component } from '@angular/core'; import { TranslateService } from '@ngx-translate/core';

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent { constructor(private translate: TranslateService) {}

switchLanguage(language: string) { this.translate.use(language); } } Configuration You can configure various aspects of @ngx-translate/core using the TranslateModule.forRoot() method in your app module. This includes specifying the default language, using a custom loader, and more.

For detailed configuration options, please refer to the official documentation: ngx-translate/core Documentation

Contributing We welcome contributions to the @ngx-translate/core library. If you have bug reports, feature requests, or would like to submit a pull request, please visit the GitHub repository: ngx-translate/core GitHub Repository

License This library is open-source and distributed under the MIT License. Please refer to the LICENSE file for more details.

Author This library is actively maintained by the Angular community and various contributors. For more information, please check the GitHub repository.

Thank you for using @ngx-translate/core for your Angular project! We hope it helps make your application accessible to a global audience.

About

The internationalization (i18n) library for Angular

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.2%
  • JavaScript 0.8%
0