Skip to content

Instantly share code, notes, and snippets.

@abdel-ships-it
Created December 4, 2019 22:58
Show Gist options
  • Save abdel-ships-it/4e1f66e551f47549cd0306ad2e1fb0ef to your computer and use it in GitHub Desktop.
Save abdel-ships-it/4e1f66e551f47549cd0306ad2e1fb0ef to your computer and use it in GitHub Desktop.
import { NgModule, LOCALE_ID} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { LocaleService } from './locale.service';
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [
LocaleService,
{
provide: LOCALE_ID,
deps: [LocaleService],
useFactory: ($locale: LocaleService) => $locale.get()
}]
})
export class AppModule { }
import { Injectable } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localeNl from '@angular/common/locales/nl';
import locale_nl_BE from '@angular/common/locales/nl-BE';
import locale_ar_EG from '@angular/common/locales/ar-EG';
import locale_he from '@angular/common/locales/he';
import locale_zh from '@angular/common/locales/zh';
registerLocaleData(localeNl);
registerLocaleData(locale_nl_BE);
registerLocaleData(locale_ar_EG);
registerLocaleData(locale_he);
registerLocaleData(locale_zh);
@Injectable()
export class LocaleService {
private LOCALE_KEY = 'locale';
set(locale: string) {
localStorage.setItem(this.LOCALE_KEY, locale);
}
get(): string {
return localStorage.getItem(this.LOCALE_KEY) || 'en-us';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment