russian localization for month names

This commit is contained in:
Oleksii Voznosymenko 2018-08-08 23:15:43 +03:00
parent 4995e9ed0e
commit 1b36ec9464
5 changed files with 129 additions and 66 deletions

95
dist/frappe-gantt.js vendored
View File

@ -9,20 +9,50 @@ const MINUTE = 'minute';
const SECOND = 'second'; const SECOND = 'second';
const MILLISECOND = 'millisecond'; const MILLISECOND = 'millisecond';
const month_names = [ const month_names = {
'January', en: [
'February', 'January',
'March', 'February',
'April', 'March',
'May', 'April',
'June', 'May',
'July', 'June',
'August', 'July',
'September', 'August',
'October', 'September',
'November', 'October',
'December' 'November',
]; 'December'
],
ru: [
'Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь'
]
};
// const month_names = [
// 'January',
// 'February',
// 'March',
// 'April',
// 'May',
// 'June',
// 'July',
// 'August',
// 'September',
// 'October',
// 'November',
// 'December'
// ];
var date_utils = { var date_utils = {
parse(date, date_separator = '-', time_separator = ':') { parse(date, date_separator = '-', time_separator = ':') {
@ -69,7 +99,7 @@ var date_utils = {
return date_string + (with_time ? ' ' + time_string : ''); return date_string + (with_time ? ' ' + time_string : '');
}, },
format(date, format_string = 'YYYY-MM-DD HH:mm:ss') { format(date, format_string = 'YYYY-MM-DD HH:mm:ss', lang = 'en') {
const values = this.get_date_values(date).map(d => padStart(d, 2, 0)); 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],
@ -79,8 +109,8 @@ var date_utils = {
mm: values[4], mm: values[4],
ss: values[5], ss: values[5],
D: values[2], D: values[2],
MMMM: month_names[+values[1]], MMMM: month_names[lang][+values[1]],
MMM: month_names[+values[1]] MMM: month_names[lang][+values[1]]
}; };
let str = format_string; let str = format_string;
@ -999,7 +1029,8 @@ class Gantt {
view_mode: 'Day', view_mode: 'Day',
date_format: 'YYYY-MM-DD', date_format: 'YYYY-MM-DD',
popup_trigger: 'click', popup_trigger: 'click',
custom_popup_html: null custom_popup_html: null,
language: 'en'
}; };
this.options = Object.assign({}, default_options, options); this.options = Object.assign({}, default_options, options);
} }
@ -1392,43 +1423,43 @@ class Gantt {
last_date = date_utils.add(date, 1, 'year'); last_date = date_utils.add(date, 1, 'year');
} }
const date_text = { const date_text = {
'Quarter Day_lower': date_utils.format(date, 'HH'), 'Quarter Day_lower': date_utils.format(date, 'HH', this.options.language),
'Half Day_lower': date_utils.format(date, 'HH'), 'Half Day_lower': date_utils.format(date, 'HH', this.options.language),
Day_lower: Day_lower:
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date_utils.format(date, 'D') ? date_utils.format(date, 'D', this.options.language)
: '', : '',
Week_lower: Week_lower:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: date_utils.format(date, 'D'), : date_utils.format(date, 'D', this.options.language),
Month_lower: date_utils.format(date, 'MMMM'), Month_lower: date_utils.format(date, 'MMMM', this.options.language),
Year_lower: date_utils.format(date, 'YYYY'), Year_lower: date_utils.format(date, 'YYYY', this.options.language),
'Quarter Day_upper': 'Quarter Day_upper':
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: '', : '',
'Half Day_upper': 'Half Day_upper':
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date.getMonth() !== last_date.getMonth() ? date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: date_utils.format(date, 'D') : date_utils.format(date, 'D', this.options.language)
: '', : '',
Day_upper: Day_upper:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'MMMM') ? date_utils.format(date, 'MMMM', this.options.language)
: '', : '',
Week_upper: Week_upper:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'MMMM') ? date_utils.format(date, 'MMMM', this.options.language)
: '', : '',
Month_upper: Month_upper:
date.getFullYear() !== last_date.getFullYear() date.getFullYear() !== last_date.getFullYear()
? date_utils.format(date, 'YYYY') ? date_utils.format(date, 'YYYY', this.options.language)
: '', : '',
Year_upper: Year_upper:
date.getFullYear() !== last_date.getFullYear() date.getFullYear() !== last_date.getFullYear()
? date_utils.format(date, 'YYYY') ? date_utils.format(date, 'YYYY', this.options.language)
: '' : ''
}; };

File diff suppressed because one or more lines are too long

View File

@ -96,7 +96,8 @@
on_view_change: function(mode) { on_view_change: function(mode) {
console.log(mode); console.log(mode);
}, },
view_mode: 'Year' view_mode: 'Month',
language: 'ru'
}); });
console.log(gantt_chart); console.log(gantt_chart);
</script> </script>

View File

@ -6,20 +6,50 @@ const MINUTE = 'minute';
const SECOND = 'second'; const SECOND = 'second';
const MILLISECOND = 'millisecond'; const MILLISECOND = 'millisecond';
const month_names = [ const month_names = {
'January', en: [
'February', 'January',
'March', 'February',
'April', 'March',
'May', 'April',
'June', 'May',
'July', 'June',
'August', 'July',
'September', 'August',
'October', 'September',
'November', 'October',
'December' 'November',
]; 'December'
],
ru: [
'Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь'
]
};
// const month_names = [
// 'January',
// 'February',
// 'March',
// 'April',
// 'May',
// 'June',
// 'July',
// 'August',
// 'September',
// 'October',
// 'November',
// 'December'
// ];
export default { export default {
parse(date, date_separator = '-', time_separator = ':') { parse(date, date_separator = '-', time_separator = ':') {
@ -66,7 +96,7 @@ export default {
return date_string + (with_time ? ' ' + time_string : ''); return date_string + (with_time ? ' ' + time_string : '');
}, },
format(date, format_string = 'YYYY-MM-DD HH:mm:ss') { format(date, format_string = 'YYYY-MM-DD HH:mm:ss', lang = 'en') {
const values = this.get_date_values(date).map(d => padStart(d, 2, 0)); 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],
@ -76,8 +106,8 @@ export default {
mm: values[4], mm: values[4],
ss: values[5], ss: values[5],
D: values[2], D: values[2],
MMMM: month_names[+values[1]], MMMM: month_names[lang][+values[1]],
MMM: month_names[+values[1]] MMM: month_names[lang][+values[1]]
}; };
let str = format_string; let str = format_string;

View File

@ -76,7 +76,8 @@ export default class Gantt {
view_mode: 'Day', view_mode: 'Day',
date_format: 'YYYY-MM-DD', date_format: 'YYYY-MM-DD',
popup_trigger: 'click', popup_trigger: 'click',
custom_popup_html: null custom_popup_html: null,
language: 'en'
}; };
this.options = Object.assign({}, default_options, options); this.options = Object.assign({}, default_options, options);
} }
@ -469,43 +470,43 @@ export default class Gantt {
last_date = date_utils.add(date, 1, 'year'); last_date = date_utils.add(date, 1, 'year');
} }
const date_text = { const date_text = {
'Quarter Day_lower': date_utils.format(date, 'HH'), 'Quarter Day_lower': date_utils.format(date, 'HH', this.options.language),
'Half Day_lower': date_utils.format(date, 'HH'), 'Half Day_lower': date_utils.format(date, 'HH', this.options.language),
Day_lower: Day_lower:
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date_utils.format(date, 'D') ? date_utils.format(date, 'D', this.options.language)
: '', : '',
Week_lower: Week_lower:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: date_utils.format(date, 'D'), : date_utils.format(date, 'D', this.options.language),
Month_lower: date_utils.format(date, 'MMMM'), Month_lower: date_utils.format(date, 'MMMM', this.options.language),
Year_lower: date_utils.format(date, 'YYYY'), Year_lower: date_utils.format(date, 'YYYY', this.options.language),
'Quarter Day_upper': 'Quarter Day_upper':
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: '', : '',
'Half Day_upper': 'Half Day_upper':
date.getDate() !== last_date.getDate() date.getDate() !== last_date.getDate()
? date.getMonth() !== last_date.getMonth() ? date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'D MMM') ? date_utils.format(date, 'D MMM', this.options.language)
: date_utils.format(date, 'D') : date_utils.format(date, 'D', this.options.language)
: '', : '',
Day_upper: Day_upper:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'MMMM') ? date_utils.format(date, 'MMMM', this.options.language)
: '', : '',
Week_upper: Week_upper:
date.getMonth() !== last_date.getMonth() date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'MMMM') ? date_utils.format(date, 'MMMM', this.options.language)
: '', : '',
Month_upper: Month_upper:
date.getFullYear() !== last_date.getFullYear() date.getFullYear() !== last_date.getFullYear()
? date_utils.format(date, 'YYYY') ? date_utils.format(date, 'YYYY', this.options.language)
: '', : '',
Year_upper: Year_upper:
date.getFullYear() !== last_date.getFullYear() date.getFullYear() !== last_date.getFullYear()
? date_utils.format(date, 'YYYY') ? date_utils.format(date, 'YYYY', this.options.language)
: '' : ''
}; };