chore: use Intl.DateTimeFormat to translate month names

This commit is contained in:
Stephan Vierkant 2022-01-25 10:25:53 +01:00 committed by s-aga-r
parent 0381503301
commit ddb35724cb
5 changed files with 26 additions and 257 deletions

121
dist/frappe-gantt.js vendored
View File

@ -9,107 +9,6 @@ var Gantt = (function () {
const SECOND = 'second'; const SECOND = 'second';
const MILLISECOND = 'millisecond'; const MILLISECOND = 'millisecond';
const month_names = {
en: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
es: [
'Enero',
'Febrero',
'Marzo',
'Abril',
'Mayo',
'Junio',
'Julio',
'Agosto',
'Septiembre',
'Octubre',
'Noviembre',
'Diciembre',
],
ru: [
'Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь',
],
ptBr: [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro',
],
fr: [
'Janvier',
'Février',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Août',
'Septembre',
'Octobre',
'Novembre',
'Décembre',
],
tr: [
'Ocak',
'Şubat',
'Mart',
'Nisan',
'Mayıs',
'Haziran',
'Temmuz',
'Ağustos',
'Eylül',
'Ekim',
'Kasım',
'Aralık',
],
zh: [
'一月',
'二月',
'三月',
'四月',
'五月',
'六月',
'七月',
'八月',
'九月',
'十月',
'十一月',
'十二月',
],
};
var date_utils = { var date_utils = {
parse(date, date_separator = '-', time_separator = /[.:]/) { parse(date, date_separator = '-', time_separator = /[.:]/) {
if (date instanceof Date) { if (date instanceof Date) {
@ -164,7 +63,14 @@ var Gantt = (function () {
}, },
format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') { format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') {
const values = this.get_date_values(date).map((d) => padStart(d, 2, 0)); const dateTimeFormat = new Intl.DateTimeFormat(lang, {
month: 'long'
});
const month_name = dateTimeFormat.format(date);
const month_name_capitalized =
month_name.charAt(0).toUpperCase() + month_name.slice(1);
const values = this.get_date_values(date).map(d => padStart(d, 2, 0));
const format_map = { const format_map = {
YYYY: values[0], YYYY: values[0],
MM: padStart(+values[1] + 1, 2, 0), MM: padStart(+values[1] + 1, 2, 0),
@ -174,8 +80,8 @@ var Gantt = (function () {
ss: values[5], ss: values[5],
SSS: values[6], SSS: values[6],
D: values[2], D: values[2],
MMMM: month_names[lang][+values[1]], MMMM: month_name_capitalized,
MMM: month_names[lang][+values[1]], MMM: month_name_capitalized,
}; };
let str = format_string; let str = format_string;
@ -828,6 +734,7 @@ var Gantt = (function () {
} }
update_progressbar_position() { update_progressbar_position() {
if (this.invalid) return;
this.$bar_progress.setAttribute('x', this.$bar.getX()); this.$bar_progress.setAttribute('x', this.$bar.getX());
this.$bar_progress.setAttribute( this.$bar_progress.setAttribute(
'width', 'width',
@ -849,6 +756,7 @@ var Gantt = (function () {
} }
update_handle_position() { update_handle_position() {
if (this.invalid) return;
const bar = this.$bar; const bar = this.$bar;
this.handle_group this.handle_group
.querySelector('.handle.left') .querySelector('.handle.left')
@ -1419,10 +1327,7 @@ var Gantt = (function () {
tick_class += ' thick'; tick_class += ' thick';
} }
// thick ticks for quarters // thick ticks for quarters
if ( if (this.view_is(VIEW_MODE.MONTH) && date.getMonth() % 3 === 0) {
this.view_is(VIEW_MODE.MONTH) &&
(date.getMonth() + 1) % 3 === 0
) {
tick_class += ' thick'; tick_class += ' thick';
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,149 +6,6 @@ const MINUTE = 'minute';
const SECOND = 'second'; const SECOND = 'second';
const MILLISECOND = 'millisecond'; const MILLISECOND = 'millisecond';
const month_names = {
en: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
es: [
'Enero',
'Febrero',
'Marzo',
'Abril',
'Mayo',
'Junio',
'Julio',
'Agosto',
'Septiembre',
'Octubre',
'Noviembre',
'Diciembre',
],
it: [
'Gennaio',
'Febbraio',
'Marzo',
'Aprile',
'Maggio',
'Giugno',
'Luglio',
'Agosto',
'Settembre',
'Ottobre',
'Novembre',
'Dicembre',
],
ru: [
'Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь',
],
ptBr: [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro',
],
fr: [
'Janvier',
'Février',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Août',
'Septembre',
'Octobre',
'Novembre',
'Décembre',
],
tr: [
'Ocak',
'Şubat',
'Mart',
'Nisan',
'Mayıs',
'Haziran',
'Temmuz',
'Ağustos',
'Eylül',
'Ekim',
'Kasım',
'Aralık',
],
zh: [
'一月',
'二月',
'三月',
'四月',
'五月',
'六月',
'七月',
'八月',
'九月',
'十月',
'十一月',
'十二月',
],
de: [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember',
],
hu: [
'Január',
'Február',
'Március',
'Április',
'Május',
'Június',
'Július',
'Augusztus',
'Szeptember',
'Október',
'November',
'December',
],
};
export default { export default {
parse(date, date_separator = '-', time_separator = /[.:]/) { parse(date, date_separator = '-', time_separator = /[.:]/) {
if (date instanceof Date) { if (date instanceof Date) {
@ -203,7 +60,14 @@ export default {
}, },
format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') { format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') {
const values = this.get_date_values(date).map((d) => padStart(d, 2, 0)); const dateTimeFormat = new Intl.DateTimeFormat(lang, {
month: 'long'
});
const month_name = dateTimeFormat.format(date);
const month_name_capitalized =
month_name.charAt(0).toUpperCase() + month_name.slice(1);
const values = this.get_date_values(date).map(d => padStart(d, 2, 0));
const format_map = { const format_map = {
YYYY: values[0], YYYY: values[0],
MM: padStart(+values[1] + 1, 2, 0), MM: padStart(+values[1] + 1, 2, 0),
@ -213,8 +77,8 @@ export default {
ss: values[5], ss: values[5],
SSS: values[6], SSS: values[6],
D: values[2], D: values[2],
MMMM: month_names[lang][+values[1]], MMMM: month_name_capitalized,
MMM: month_names[lang][+values[1]], MMM: month_name_capitalized,
}; };
let str = format_string; let str = format_string;