I am currently reading about internationalization of the ng-bootstrap
components. Their documentation says for the datepicker:
Since the 2.0.0 release datepicker will use the application locale if it is present to get translations of weekdays and month names. The internal service that does translation is called NgbDatepickerI18n and you could provide your own implementation if necessary.
(ng-bootstrap website)
Looking at the Angular i18n documentation, it states:
If you want to import locale data for other languages, you can do it manually:
src/app/app.module.ts
import { registerLocaleData } from '@angular/common'; import localeFr from '@angular/common/locales/fr'; // the second parameter 'fr' is optional registerLocaleData(localeFr, 'fr');
(Angular website)
But why is it not working for me? Do I still have to make a custom implementation of NgbDatepickerI18n
, or am I missing something?
Here is an example playground:
https://stackblitz.com/edit/angular-mezpyn?file=app%2Fdatepicker-popup.module.ts
Now we open ANGULARDATEPICKER project inside VS Code. Select OpenFolder option to open the folder files in VISUAL STUDIO CODE. Expand folder SRC and double click on app.component.ts file. Now switch to app.component.html file where we write html code. As you can see the below screenshot title has been changed successfully. Welcome to { { title }}!
To set value for ngbDatepicker you need set with format object as below: var setDate = { year: 2020, month: 10, day: 10 }; In your case, you can do as below :
With ngx-translate it's easy to create a multilingual version of your Angular app. Use ngx-translate-extract to keep your translation files up-to-date. Finally BabelEdit helps you to mange and edit your translations. The source code is available on GitHub .
You can use the translate pipe much like you’d use any other pipe in Angular. The input into the pipe is the key of the translation you need. The optional parameter is an object which defines any interpolation strings that the translation is expecting. In the example below, the component has a user object, with a property of firstName:
I had the same problem and becuase there's no answer, this is the solution:
After importing and registering the locale data as you did, in app.module.ts you need to add
providers: [
{ provide: LOCALE_ID, useValue: 'fr-FR' },
... other providers
],
The documentation doesn't make it clear in my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With