Skip to content

Commit

Permalink
Add fallback language name for unknown locales by Babel
Browse files Browse the repository at this point in the history
Babel uses Common Locale Data Repository (https://unicode.org/cldr/) and
its current version does not know the "ie" locale.
  • Loading branch information
eht16 committed Aug 17, 2020
1 parent 2be1277 commit a359e7e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions static_docs/generate_i18n_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
from time import time
import re

from babel import Locale
from babel import Locale, UnknownLocaleError


STATISTICS_REGEXP = re.compile(
r'(?P<translated>\d+) translated messages?(, (?P<fuzzy>\d+) fuzzy translations?)?(, (?P<untranslated>\d+) untranslated messages?)?') # noqa: E501 pylint: disable=line-too-long
LAST_TRANSLATOR_REGEXP = re.compile(r'^"Last-Translator: (?P<name>[\w -]+)\s*<?.+')

# fallback language names for locales not (yet) supported by Babel
KNOWN_LANGUAGE_NAMES = {
'ie': 'Interlingue',
}


class TranslationStatistics:

Expand Down Expand Up @@ -202,8 +207,11 @@ def _read_last_translator(self, filename):

# ----------------------------------------------------------------------
def _read_language_name(self, locale):
locale = Locale.parse(locale)
return locale.get_display_name(locale='en')
try:
locale = Locale.parse(locale)
return locale.get_display_name(locale='en')
except UnknownLocaleError:
return KNOWN_LANGUAGE_NAMES.get(locale)

# ----------------------------------------------------------------------
def _update_message_catalog(self):
Expand Down

1 comment on commit a359e7e

@codebrainz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.