Skip to content

Commit 6caf509

Browse files
minor change
1 parent e5e53e7 commit 6caf509

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

l10n_CM/run_l10n.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"bijoubrigitte",
2727
"brico",
2828
"burtsbees",
29-
"burtsbeescalvinklein",
3029
"calvinklein",
3130
"canadatire",
3231
"cdiscount",

modules/util.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ def __init__(self):
112112
"Belgium": "België",
113113
"Austria": "Österreich",
114114
}
115+
# Country code mapping for different regions
116+
self.country_codes = {
117+
"US": "1",
118+
"CA": "1",
119+
"FR": "33",
120+
"DE": "49",
121+
"GB": "44",
122+
"IT": "39",
123+
"PL": "48",
124+
"ES": "34",
125+
"BE": "32",
126+
"AT": "43",
127+
}
115128

116129
self.fake = None
117130
self.locale = None
@@ -556,22 +569,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
556569
str
557570
The normalized phone number in the format <country-code><number>.
558571
"""
559-
560-
# Country code mapping for different regions
561-
country_codes = {
562-
"US": "1",
563-
"CA": "1",
564-
"FR": "33",
565-
"DE": "49",
566-
"GB": "44",
567-
"IT": "39",
568-
"PL": "48",
569-
"ES": "34",
570-
"BE": "32",
571-
"AT": "43",
572-
}
573-
574-
# Handle leading zero in local numbers
572+
# Handle leading zero in local numbers before country code is removed
575573
if region not in ["US", "CA"] and phone.startswith("0"):
576574
# Remove the leading zero
577575
phone = phone[1:]
@@ -582,7 +580,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
582580
phone = phone.replace("4343", "43")
583581

584582
# If phone is already normalized, return as it is
585-
expected_country_code = country_codes.get(region)
583+
expected_country_code = self.country_codes.get(region)
586584
if (
587585
expected_country_code
588586
and phone.isdigit()
@@ -597,7 +595,7 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
597595
digits = re.sub(r"\D", "", phone)
598596

599597
# Determine country code
600-
country_code = country_codes.get(
598+
country_code = self.country_codes.get(
601599
region, "1"
602600
) # Default to "1" (US/CA) if the region is unknown
603601
# handle leading zeros
@@ -608,6 +606,11 @@ def normalize_regional_phone_numbers(self, phone: str, region: str) -> str:
608606
# Remove country code from the local number
609607
local_number = digits[len(country_code) :]
610608

609+
# Handle leading zero in local numbers after country code is removed
610+
if region not in ["US", "CA"] and local_number.startswith("0"):
611+
# Remove the leading zero
612+
local_number = local_number[1:]
613+
611614
# Validate local number length
612615
if len(local_number) < 6: # Too short to be valid
613616
logging.warning(f"Invalid phone number format: {phone}")

0 commit comments

Comments
 (0)