Skip to content

Commit

Permalink
feat(Holiday List): display localized country name
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Jul 14, 2023
1 parent fd23bd0 commit 4888d75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 7 additions & 3 deletions erpnext/setup/doctype/holiday_list/holiday_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ frappe.ui.form.on("Holiday List", {
}

frm.call("get_supported_countries").then(r => {
frm.subdivisions_by_country = r.message;
frm.set_df_property("country", "options", Object.keys(r.message));
frm.subdivisions_by_country = r.message.subdivisions_by_country;
frm.set_df_property(
"country",
"options",
r.message.countries.sort((a, b) => a.label.localeCompare(b.label))
);

if (frm.doc.country) {
frm.trigger("set_subdivisions");
Expand All @@ -31,7 +35,7 @@ frappe.ui.form.on("Holiday List", {
},
set_subdivisions: function(frm) {
const subdivisions = frm.subdivisions_by_country[frm.doc.country];
if (subdivisions.length > 0) {
if (subdivisions && subdivisions.length > 0) {
frm.set_df_property("subdivision", "options", frm.subdivisions_by_country[frm.doc.country]);
frm.set_df_property("subdivision", "hidden", 0);
} else {
Expand Down
2 changes: 1 addition & 1 deletion erpnext/setup/doctype/holiday_list/holiday_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"icon": "fa fa-calendar",
"idx": 1,
"links": [],
"modified": "2023-07-13 13:12:32.082690",
"modified": "2023-07-14 11:29:12.537263",
"modified_by": "Administrator",
"module": "Setup",
"name": "Holiday List",
Expand Down
16 changes: 15 additions & 1 deletion erpnext/setup/doctype/holiday_list/holiday_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import date

import frappe
from babel import Locale
from frappe import _, throw
from frappe.model.document import Document
from frappe.utils import formatdate, getdate, today
Expand Down Expand Up @@ -39,7 +40,15 @@ def get_weekly_off_dates(self):

@frappe.whitelist()
def get_supported_countries(self):
return list_supported_countries()
subdivisions_by_country = list_supported_countries()
countries = [
{"value": country, "label": local_country_name(country)}
for country in subdivisions_by_country.keys()
]
return {
"countries": countries,
"subdivisions_by_country": subdivisions_by_country,
}

@frappe.whitelist()
def get_local_holidays(self):
Expand Down Expand Up @@ -157,3 +166,8 @@ def is_holiday(holiday_list, date=None):
)
else:
return False


def local_country_name(country_code: str) -> str:
"""Return the localized country name for the given country code."""
return Locale.parse(frappe.local.lang).territories.get(country_code, country_code)

0 comments on commit 4888d75

Please sign in to comment.