question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker: Usage of locales

See original GitHub issue

Bug description or feature request:

After the update to 2.0.3 (and Angular 5.2) I have some problems with the locale in the datepicker component. I see the sample code but cannot figure out what is the appropriate syntax/approach. I have:

bsConfig: Partial<BsDatepickerConfig> = new BsDatepickerConfig();
..
constructor(private bsLocaleService: BsLocaleService) {
...
}
  ngOnInit() {
    const tmp = listLocales();
    this.bsConfig.containerClass = 'theme-dark-blue';
    //this.bsConfig.dateInputFormat = 'YYYY-MM-DD';
    //    this.bsLocaleService.use('de');
    const tmp = defineLocale('localeKey', deLocale);
    defineLocale('de', deLocale); 
    //    //    this.bsLocale.use('de');
    this.dateFormat = tmp.formatLongDate('L');

The above code raises the exception:

locales.js:84 Khronos locale error: please load locale “localekey” before using it

  1. When I inspect tmp I just see en nothing else ==> how to initialize it properly?

  2. I would have expected to change the dateInputFormat - but the changes are not applied 😕 How to make it properly?

Sorry, but I couldn’t figure it out by the given samples:-/

Bootstrap4, ngx-bootstrap 2.0.3 and Angular 5.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

14reactions
Keki91commented, Apr 3, 2018

We’ve just had this same problem and came up with this fix (albeit for enGb).

Our former code was working fine with enGb - it seems to break with Angular 5 and/or 2.0.3.

app.module.ts

import { defineLocale } from 'ngx-bootstrap/chronos';

import { enGbLocale } from 'ngx-bootstrap/locale';

// The string MUST be lower case - even though the examples give it as enGb
defineLocale('engb', enGbLocale);

calendar.component.ts

import { BsLocaleService } from 'ngx-bootstrap/datepicker';
constructor(private _localeService: BsLocaleService) {
  this._localeService.use('engb');
}

6reactions
eneajahocommented, Dec 17, 2019

So I wanted the language to be in italian and I changed the language with this code:

I imported:

import { BsLocaleService, defineLocale, itLocale } from 'ngx-bootstrap';

Code in example.component.ts

  // set language of datepicker
  setDatepickerLanguage() {
    defineLocale('it', itLocale);
    this.localeService.use('it');
  }

and called the function on the constructor() and it worked.

Screenshot:

screenshot

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set locale format from datepicker? - jquery
Use the dateFormat option to change to a custom format $(function() { $(".datefield2").datepicker($.datepicker.regional['de']); ...
Read more >
datepicker locale - Gijgo.com
The language that needs to be in use. ... locale : stringDefault: 'en-us'. The language that needs to be in use. Examples. German....
Read more >
Date and Time Pickers - Localization - MUI X
If you want to use other locales, follow the instructions below. This page focuses on translating the text inside the Date and Time...
Read more >
Locale support(DatePicker) needs better locale support #7709
Summary There needs to be more supported locales, and better logic in determining which locale to use. This is a development request.
Read more >
I18N — bootstrap-datepicker documentation - Read the Docs
I18N¶. The plugin supports i18n for the month and weekday names and the weekStart option. The default is English (“en”); other available translations...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found