1

My problem is this: I cannot translate the date into another language in the html file.

I use ionic 3. This is my code:

{{(valeur | date:‘fullDate’) | translate }}

The result is this:

Monday, October, 30,2017

Presently I use the language fr-FR and I would like the result to appear like

Lundi, 30 octobre 2017
Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66

1 Answers1

3

This Question and Answer appear to cover the issue.

corrola's Answer

As of Angular2 RC6, you can set default locale in your app module, by adding a provider:

@NgModule({
    providers: [
        { provide: LOCALE_ID, useValue: "fr-FR" }, //replace "en-US" with your locale
        //otherProviders...
    ]
})

The Currency/Date/Number pipes should pick up the locale. LOCALE_ID is an OpaqueToken, to be imported from angular/core.

import { LOCALE_ID } from '@angular/core';

For a more advanced use case, you may want to pick up locale from a service. Locale will be resolved (once) when component using date pipe is created:

{
    provide: LOCALE_ID,
    deps: [SettingsService],      //some service handling global settings
    useFactory: (settingsService) => settingsService.getLanguage()  
    //returns locale string
}
Steven Scott
  • 10,234
  • 9
  • 69
  • 117