-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datepicker localization issue for Asian languages #3863
Milestone
Comments
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Mar 2, 2021
- introduces a new `getMonthLabel(date: NgbDateStruct): string` method to datepicker i18n - makes default i18n datepicker implementation accessible publicly Fixes ng-bootstrap#3863
There is no simple date format to do what you want to do, but the way datepicker displays this labels (splitting it into 2 parts) is wrong. // ex. custom datepicker i18n service that overrides the label
@Injectable()
class CustomI18n extends NgbDatepickerI18nDefault {
getMonthLabel(date: NgbDateStruct): string { return `${date.month}-${date.year}`; }
} In your case for asian languages it would be a bit more tricky, something along these lines: import {Inject, Injectable, LOCALE_ID} from '@angular/core';
import {NgbDateNativeAdapter, NgbDatepickerI18nDefault, NgbDateStruct} from '@ng-bootstrap/ng-bootstrap';
import {formatDate} from '@angular/common';
@Injectable()
class CustomI18N extends NgbDatepickerI18nDefault {
constructor(@Inject(LOCALE_ID) private locale: string, private dateAdapter: NgbDateNativeAdapter) {
super(locale);
}
// overriding labels for some locales
getMonthLabel(date: NgbDateStruct): string {
if (this.locale === 'zh-CN') {
return `${date.year}年 ${formatDate(this.dateAdapter.toModel(date) !, 'MMM', this.locale)}`;
} else {
return super.getMonthLabel(date);
}
}
} Will be released as part of |
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Mar 3, 2021
- introduces a new `getMonthLabel(date: NgbDateStruct): string` method to datepicker i18n - makes default i18n datepicker implementation accessible publicly Fixes ng-bootstrap#3863
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Mar 3, 2021
- introduces a new `getMonthLabel(date: NgbDateStruct): string` method to datepicker i18n - makes default i18n datepicker implementation accessible publicly Fixes ng-bootstrap#3863
maxokorokov
added a commit
to maxokorokov/ng-bootstrap
that referenced
this issue
Mar 3, 2021
- introduces a new `getMonthLabel(date: NgbDateStruct): string` method to datepicker i18n - makes default i18n datepicker implementation accessible publicly Fixes ng-bootstrap#3863
maxokorokov
added a commit
that referenced
this issue
Mar 3, 2021
- introduces a new `getMonthLabel(date: NgbDateStruct): string` method to datepicker i18n - makes default i18n datepicker implementation accessible publicly Fixes #3863
fbasso
added a commit
to fbasso/ng-bootstrap
that referenced
this issue
Jun 4, 2021
fbasso
added a commit
to fbasso/ng-bootstrap
that referenced
this issue
Jun 4, 2021
fbasso
added a commit
that referenced
this issue
Jun 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug description:
For Asian languages (Japanese, Chinese, etc), the year is positioned at the beginning when formatting a date. However, it is not the case when using the ng-bootstrap datepicker with navigation equals to arrows mode (in Chinese for example: 十月 2020 whereas a proper localization should be 2020年 10月). Furthermore, it is not even possible to correct it using the NgbDatepickerI18n as the order is "hardcoded":
https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/datepicker/datepicker-navigation.ts#L27-L33
The only way that we have currently it is to use https://ng-bootstrap.github.io/#/components/datepicker/overview#content-template and redoing on our own a part of the datepicker.
Link to minimally-working StackBlitz that reproduces the issue:
https://stackblitz.com/edit/angular-faf5dt?file=src%2Fapp%2Fdatepicker-basic.ts
Versions of Angular, ng-bootstrap and Bootstrap:
Angular: 10
ng-bootstrap: 7.0.0
Bootstrap: 4.5.0
The text was updated successfully, but these errors were encountered: