From 0218ca538f8dd4342d1c9a989607441dc89fed22 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 7 Aug 2023 09:55:46 +0530 Subject: [PATCH 1/2] fix: use correct lang separator for frappe --- erpnext/setup/doctype/holiday_list/holiday_list.py | 2 +- .../setup/doctype/holiday_list/test_holiday_list.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/holiday_list/holiday_list.py b/erpnext/setup/doctype/holiday_list/holiday_list.py index 2ef4e655b2..acf421536d 100644 --- a/erpnext/setup/doctype/holiday_list/holiday_list.py +++ b/erpnext/setup/doctype/holiday_list/holiday_list.py @@ -169,4 +169,4 @@ def is_holiday(holiday_list, date=None): 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) + return Locale.parse(frappe.local.lang, sep="-").territories.get(country_code, country_code) diff --git a/erpnext/setup/doctype/holiday_list/test_holiday_list.py b/erpnext/setup/doctype/holiday_list/test_holiday_list.py index 23b08fd117..7eeb27d864 100644 --- a/erpnext/setup/doctype/holiday_list/test_holiday_list.py +++ b/erpnext/setup/doctype/holiday_list/test_holiday_list.py @@ -8,6 +8,8 @@ from datetime import date, timedelta import frappe from frappe.utils import getdate +from erpnext.setup.doctype.holiday_list.holiday_list import local_country_name + class TestHolidayList(unittest.TestCase): def test_holiday_list(self): @@ -58,6 +60,16 @@ class TestHolidayList(unittest.TestCase): self.assertIn(date(2023, 4, 10), holidays) self.assertNotIn(date(2023, 5, 1), holidays) + def test_localized_country_names(self): + lang = frappe.local.lang + frappe.local.lang = "en-gb" + self.assertEqual(local_country_name("IN"), "India") + self.assertEqual(local_country_name("DE"), "Germany") + + frappe.local.lang = "de" + self.assertEqual(local_country_name("DE"), "Deutschland") + frappe.local.lang = lang + def make_holiday_list( name, from_date=getdate() - timedelta(days=10), to_date=getdate(), holiday_dates=None From f574ac11ea8ee2f7f46916d93c6f5877350bc069 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 7 Aug 2023 10:03:40 +0530 Subject: [PATCH 2/2] perf: defer babel import Only required when configuring but will get loaded everywhere --- erpnext/setup/doctype/holiday_list/holiday_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/holiday_list/holiday_list.py b/erpnext/setup/doctype/holiday_list/holiday_list.py index acf421536d..6b6c8ba5be 100644 --- a/erpnext/setup/doctype/holiday_list/holiday_list.py +++ b/erpnext/setup/doctype/holiday_list/holiday_list.py @@ -6,7 +6,6 @@ import json 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 @@ -169,4 +168,6 @@ def is_holiday(holiday_list, date=None): def local_country_name(country_code: str) -> str: """Return the localized country name for the given country code.""" + from babel import Locale + return Locale.parse(frappe.local.lang, sep="-").territories.get(country_code, country_code)