Skip to content

Commit f5d447c

Browse files
committed
Add support for ISO 639-3 part 3 standard language code
The commit adds pycountry as an extra optional dependency. Fixes #12772.
1 parent 47245a9 commit f5d447c

File tree

3 files changed

+28
-188
lines changed

3 files changed

+28
-188
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ The following packages are optional:
120120
Python bindings of fontconfig are required for displaying
121121
genealogical symbols
122122

123+
* [**pycountry**](https://pypi.org/project/pycountry/)
124+
125+
Used to validate ISO language codes.
126+
123127

124128
Optional packages required by Third-party Addons
125129
------------------------------------------------

aio/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pacman -S --needed --noconfirm \
3333
mingw-w64-x86_64-python-pillow \
3434
mingw-w64-x86_64-python-pip \
3535
mingw-w64-x86_64-python-psycopg2 \
36+
mingw-w64-x86_64-python-pycountry \
3637
mingw-w64-x86_64-python-requests \
3738
mingw-w64-x86_64-python-wheel \
3839
perl-XML-Parser \

gramps/gui/editors/editplacename.py

+23-188
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@
4141
_ = glocale.translation.sgettext
4242
from gramps.gen.const import URL_MANUAL_SECT2
4343

44+
try:
45+
import pycountry
46+
47+
def validate_iso(text):
48+
"""
49+
Validate 2 and 3 digit ISO language codes.
50+
"""
51+
if pycountry.languages.get(alpha_2=text):
52+
return True
53+
if pycountry.languages.get(alpha_3=text):
54+
return True
55+
return False
56+
57+
except ModuleNotFoundError:
58+
59+
def validate_iso(_):
60+
"""
61+
Dummy ISO language code validation. Always return True.
62+
"""
63+
return True
64+
65+
4466
# -------------------------------------------------------------------------
4567
#
4668
# Constants
@@ -49,193 +71,6 @@
4971
WIKI_HELP_PAGE = URL_MANUAL_SECT2
5072
WIKI_HELP_SEC = _("Place_Name_Editor_dialog", "manual")
5173

52-
ISO_CODES = (
53-
"aa",
54-
"ab",
55-
"ae",
56-
"af",
57-
"ak",
58-
"am",
59-
"an",
60-
"ar",
61-
"as",
62-
"av",
63-
"ay",
64-
"az",
65-
"ba",
66-
"be",
67-
"bg",
68-
"bh",
69-
"bi",
70-
"bm",
71-
"bn",
72-
"bo",
73-
"br",
74-
"bs",
75-
"ca",
76-
"ce",
77-
"ch",
78-
"co",
79-
"cr",
80-
"cs",
81-
"cu",
82-
"cv",
83-
"cy",
84-
"da",
85-
"de",
86-
"dv",
87-
"dz",
88-
"ee",
89-
"el",
90-
"en",
91-
"eo",
92-
"es",
93-
"et",
94-
"eu",
95-
"fa",
96-
"ff",
97-
"fi",
98-
"fj",
99-
"fo",
100-
"fr",
101-
"fy",
102-
"ga",
103-
"gd",
104-
"gl",
105-
"gn",
106-
"gu",
107-
"gv",
108-
"ha",
109-
"he",
110-
"hi",
111-
"ho",
112-
"hr",
113-
"ht",
114-
"hu",
115-
"hy",
116-
"hz",
117-
"ia",
118-
"id",
119-
"ie",
120-
"ig",
121-
"ii",
122-
"ik",
123-
"io",
124-
"is",
125-
"it",
126-
"iu",
127-
"ja",
128-
"jv",
129-
"ka",
130-
"kg",
131-
"ki",
132-
"kj",
133-
"kk",
134-
"kl",
135-
"km",
136-
"kn",
137-
"ko",
138-
"kr",
139-
"ks",
140-
"ku",
141-
"kv",
142-
"kw",
143-
"ky",
144-
"la",
145-
"lb",
146-
"lg",
147-
"li",
148-
"ln",
149-
"lo",
150-
"lt",
151-
"lu",
152-
"lv",
153-
"mg",
154-
"mh",
155-
"mi",
156-
"mk",
157-
"ml",
158-
"mn",
159-
"mr",
160-
"ms",
161-
"mt",
162-
"my",
163-
"na",
164-
"nb",
165-
"nd",
166-
"ne",
167-
"ng",
168-
"nl",
169-
"nn",
170-
"no",
171-
"nr",
172-
"nv",
173-
"ny",
174-
"oc",
175-
"oj",
176-
"om",
177-
"or",
178-
"os",
179-
"pa",
180-
"pi",
181-
"pl",
182-
"ps",
183-
"pt",
184-
"qu",
185-
"rm",
186-
"rn",
187-
"ro",
188-
"ru",
189-
"rw",
190-
"sa",
191-
"sc",
192-
"sd",
193-
"se",
194-
"sg",
195-
"si",
196-
"sk",
197-
"sl",
198-
"sm",
199-
"sn",
200-
"so",
201-
"sq",
202-
"sr",
203-
"ss",
204-
"st",
205-
"su",
206-
"sv",
207-
"sw",
208-
"ta",
209-
"te",
210-
"tg",
211-
"th",
212-
"ti",
213-
"tk",
214-
"tl",
215-
"tn",
216-
"to",
217-
"tr",
218-
"ts",
219-
"tt",
220-
"tw",
221-
"ty",
222-
"ug",
223-
"uk",
224-
"ur",
225-
"uz",
226-
"ve",
227-
"vi",
228-
"vo",
229-
"wa",
230-
"wo",
231-
"xh",
232-
"yi",
233-
"yo",
234-
"za",
235-
"zh",
236-
"zu",
237-
)
238-
23974

24075
# -------------------------------------------------------------------------
24176
#
@@ -287,7 +122,7 @@ def _setup_fields(self):
287122
self.top.get_object("language").validate(force=True)
288123

289124
def _validate_iso_code(self, widget, text):
290-
if text not in ISO_CODES:
125+
if not validate_iso(text):
291126
return ValidationError(_("Invalid ISO code"))
292127

293128
def _connect_signals(self):

0 commit comments

Comments
 (0)