multilanguage site angular

$npm install ngx-i18nsupport -s

4.33
3
Yoonsi 80 points

                                    //Install ngx-translate
$ npm install @ngx-translate/core @ngx-translate/http-loader rxjs --save

//In your app.module.ts:
// import ngx-translate and the http loader
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {HttpClient, HttpClientModule} from '@angular/common/http';

@NgModule({
  ...
  imports: [
        ...
        // ngx-translate and the loader module
        HttpClientModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [HttpClient]
            }
        })
    ],
  ...
})
export class AppModule { }
// required for AOT compilation
export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http);
}

//In the app.component.ts
import {Component} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent {
    constructor(private translate: TranslateService) {
        translate.setDefaultLang('en');
    }
  useLanguage(language: string) {
    this.translate.use(language);
	}
}

//create the JSON file for the English translation: assets/i18n/en.json.
{
    "demo": {
        "title": "Translation demo",
        "text": "This is a simple demonstration app for ngx-translate"
    }
}
//do the same with another language (for example german)

//In the app.component.html
<p [translate]="'demo.text'"></p>

<button (click)="useLanguage('en')">en</button>
<button (click)="useLanguage('de')">de</button>

4.33 (3 Votes)
0
3.56
9

                                    //Installing:
//Terminal
$ npm install --save-dev angular-translate
//Embed in the html doc
<script src="path/to/angular-translate.js"></script>
//In the component.ts
var app = angular.module('myApp', ['pascalprecht.translate']);

app.config(['$translateProvider', function ($translateProvider) {
  $translateProvider.translations('en', {
    'TITLE': 'Hello',
    'FOO': 'This is a paragraph'
  });
 
  $translateProvider.translations('de', {
    'TITLE': 'Hallo',
    'FOO': 'Dies ist ein Absatz'
  });
 
  $translateProvider.preferredLanguage('en');
}]);
//In the component.html
<h1>{{ 'TITLE' | translate }}</h1>
<p>{{ 'FOO' | translate }}</p>

3.56 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
angular multi language example 10 multi language in angular 8 multi language angular project angular multi language angular 11 multi language support in angular multilanguage site mit angular how to use multiple language in angular website how to create multi language website in angular multi-language Angular applications how to implement multi language in angular angular multi language app multi language in angular multi language support angular multi language website angular multi language support for angular how to make multi language project in angular multi language application in angular 11 angular multi language site angular i18n change language different language pages angular change language angular app Angular Switch languages as per browser locale internationalization angular 9 example angular 11 muli lang angular 11 i18n translate service angular 11 i18n multi language angular 11 angular site language angular app translate is there any way to translate website content in other languages angular how to add language translator in angular 5 translate angular app how to create language converter from english to french in angular how to convert a string into multiple languages using angular angular.io internationalisation how to convert a statment into multiple languages in angular angular-translate using english on a different langauge angular 9 auto translations for other languages angular 11 translate i18n as service angular 11 translate langue angular angular i18n not generating angular i18n tutorial angular add i18n multiple create introduction page angular 7 with multiple languages angular language spanish global localisation in angular 2 multi language support in angular hindi and english i18 angular global localisation in angular 7 multi language website in Angular 11 how to use multi language in angular display three languages in one page as an option in angular 10 i18n navigation angular i18n with variables angular i18n angular 9 angular multilingual angular multi language using data binding angular locales routes set up routes for your locales angular angular internationalization angular i18n define local file angular localize type another language in angular 8 angular translate example angular multi language support demo set i18n angular handle 2 language in angular i18n locales object angular localize html string i18n build angular 10 angular internationalization select language component angular internationalization build angular multi country set default country with angular i18n angular 7 change languages angular 11 internationalization angular mult lingual | tranlate in angular angular language change localService setup translations angular get browser region angular 7 i18n angular para angular i18n build i8s angular language loadTranslations(translations) angular10 multilanguage site angular angular json set lib translations location go to change language angular change languague select angular change languague select angular 9 angular change languegue with i18n how to add colon to a localize string angular angular multiple locales angular json lib load locales l18n example en-Us angular change language in angular 8 angular i18n switch locale ng xi18n how to set language angular application localization language angular add translation config translate angular language of filed angular language change in angular 6 translation files angular 10 LanguageService angular for internalization can angular UI be written in some other language angular language id developing angular with other languages dual language setup in angular 11 angular change language component how to set two languages angular translate angular using lang code handle multiple languages angular 8 angular multi language routes angular language selection angular 10 build multi language ngx-i18nsupport angular 10 build multi language MultilangDirective angular angular support language creating interface for i18n multi language in anuglar international language angular angular 7 multi language multi language angular application without json file how to manage diffrent language support with angular angular multilanguage angular page multiple languages multi language support angular 10 multi language angular angular 10 multi language angular language switcher angular select multiple languages angular multiple languages angular multi language angular multi language support multi language support in angular 7 angular multi language example multi language website angular 6
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source