From 793ba8fc06ac5fec09b5c7a52cb73bd44b3f903b Mon Sep 17 00:00:00 2001 From: 0Pranav Date: Thu, 14 Nov 2019 11:25:49 +0530 Subject: [PATCH] pretty timezone names --- erpnext/www/book-appointment/index.js | 13 +++++++++---- erpnext/www/book-appointment/index.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/erpnext/www/book-appointment/index.js b/erpnext/www/book-appointment/index.js index 457c6cf1a4..b91e3b08eb 100644 --- a/erpnext/www/book-appointment/index.js +++ b/erpnext/www/book-appointment/index.js @@ -13,26 +13,31 @@ async function initialise_select_date() { } async function get_global_variables() { - // Using await + // Using await through this file instead of then. window.appointment_settings = (await frappe.call({ method: 'erpnext.www.book-appointment.index.get_appointment_settings' })).message; window.timezones = (await frappe.call({ - method: 'erpnext.www.book-appointment.index.get_timezones' + method:'erpnext.www.book-appointment.index.get_timezones' })).message; window.holiday_list = window.appointment_settings.holiday_list; } function setup_timezone_selector() { + /** + * window.timezones is a dictionary with the following structure + * { IANA name: Pretty name} + * For example : { Asia/Kolkata : "India Time - Asia/Kolkata"} + */ let timezones_element = document.getElementById('appointment-timezone'); let offset = new Date().getTimezoneOffset(); - window.timezones.forEach(timezone => { + Object.keys(window.timezones).forEach((timezone) => { let opt = document.createElement('option'); opt.value = timezone; if (timezone == moment.tz.guess()) { opt.selected = true; } - opt.innerHTML = timezone; + opt.innerHTML = window.timezones[timezone] timezones_element.appendChild(opt) }); } diff --git a/erpnext/www/book-appointment/index.py b/erpnext/www/book-appointment/index.py index a8ab22956d..163fdc0132 100644 --- a/erpnext/www/book-appointment/index.py +++ b/erpnext/www/book-appointment/index.py @@ -25,7 +25,18 @@ def get_appointment_settings(): @frappe.whitelist(allow_guest=True) def get_timezones(): - return pytz.all_timezones + from babel.dates import get_timezone, get_timezone_name, Locale + from frappe.utils.momentjs import get_all_timezones + + translated_dict = {} + locale = Locale.parse(frappe.local.lang, sep="-") + + for tz in get_all_timezones(): + timezone_name = get_timezone_name(get_timezone(tz), locale=locale, width='short') + if timezone_name: + translated_dict[tz] = timezone_name + ' - ' + tz + + return translated_dict @frappe.whitelist(allow_guest=True) def get_appointment_slots(date, timezone):