Skip to content

Commit 8c45dd5

Browse files
committed
Use abbrWithVariant attribute.
1 parent 5c47098 commit 8c45dd5

3 files changed

Lines changed: 2 additions & 263 deletions

File tree

‎language_tool/__init__.py‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
from xml.etree import ElementTree
4343

4444
from .backports import subprocess
45-
from .country_codes import get_country_code
4645
from .which import which
4746

4847

@@ -303,19 +302,8 @@ def _get_languages(cls) -> set:
303302
url = urllib.parse.urljoin(cls._url, "Languages")
304303
languages = set()
305304
for e in cls._get_root(url, num_tries=1):
306-
language = e.get("abbr")
307-
if len(re.split(r"[_-]", language)) < 2:
308-
match = re.search(r"\((.*?)\)", e.get("name"))
309-
if match:
310-
country_name = match.group(1)
311-
try:
312-
country_code = get_country_code(country_name)
313-
except KeyError:
314-
warnings.warn(
315-
"unknown language: {!r}".format(e.get("name")))
316-
else:
317-
language += "-" + country_code
318-
languages.add(language)
305+
languages.add(e.get("abbr"))
306+
languages.add(e.get("abbrWithVariant"))
319307
return languages
320308

321309
@classmethod

‎language_tool/country_codes.py‎

Lines changed: 0 additions & 218 deletions
This file was deleted.

‎test.py‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from collections import namedtuple
88

99
import language_tool
10-
from language_tool.country_codes import get_country_code
1110

1211

1312
class TestLanguageTool(unittest.TestCase):
@@ -111,35 +110,5 @@ def test_version(self):
111110
self.assertTrue(version)
112111

113112

114-
class TestCountryCodes(unittest.TestCase):
115-
tests = {
116-
"Australian": "AU",
117-
"Canadian": "CA",
118-
"GB": "GB",
119-
"New Zealand": "NZ",
120-
"South African": "ZA",
121-
"US": "US",
122-
"Austria": "AT",
123-
"Germany": "DE",
124-
"Swiss": "CH",
125-
"Brazil": "BR",
126-
"Portugal": "PT",
127-
128-
"Australia": "AU",
129-
"Canada": "CA",
130-
"United Kingdom": "GB",
131-
"South Africa": "ZA",
132-
"United States": "US",
133-
"Switzerland": "CH",
134-
135-
"Austrian": "AT",
136-
"Brazilian": "BR",
137-
}
138-
139-
def test_country_codes(self):
140-
for country, code in self.tests.items():
141-
self.assertEqual(get_country_code(country), code)
142-
143-
144113
if __name__ == "__main__":
145114
unittest.main()

0 commit comments

Comments
 (0)