From 61a8af356bca3b0ea5fd6cd04925866685e82de5 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Mon, 4 Feb 2019 22:29:32 +0000 Subject: [PATCH] Get locale names from libgnomedesktop --- gitlab-changelog.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/gitlab-changelog.py b/gitlab-changelog.py index f52f174..c43f367 100755 --- a/gitlab-changelog.py +++ b/gitlab-changelog.py @@ -36,6 +36,10 @@ from git import Repo import gitlab import xdg.BaseDirectory +import gi +gi.require_version('GnomeDesktop', '3.0') +from gi.repository import GnomeDesktop # noqa: E402 + def get_commit_translations(commit): """Return a potentially empty set of locale codes changed by this @@ -106,24 +110,6 @@ def get_issues_and_merge_requests(commit): return (issues, merge_requests) -ALL_LOCALE_NAMES = { - 'cs': 'Czech', - 'da': 'Danish', - 'el': 'Greek', - 'es': 'Spanish', - 'gl': 'Galician', - 'hu': 'Hungarian', - 'lt': 'Lithuanian', - 'nb': 'Norwegian bokmål', - 'pl': 'Polish', - 'pt_BR': 'Brazilian Portuguese', - 'sk': 'Slovak', - 'sl': 'Slovenian', - 'sv': 'Swedish', - 'tr': 'Turkish', -} - - def main(): # Load our GitLab authentication details. config = configparser.ConfigParser() @@ -219,8 +205,23 @@ def main(): merged_gl_merge_requests[merge_request] = gl_merge_request # Map the locale names. - locale_names = {l: ALL_LOCALE_NAMES[l] for l in locales if l in ALL_LOCALE_NAMES} - unmapped_locale_names = set([l for l in locales if l not in ALL_LOCALE_NAMES]) + locale_names = set() + unmapped_locale_names = set() + for l in locales: + # Get the name of 'l' in US English. This data actually comes from the + # iso-codes package, in the iso_639 and iso_3166 gettext domains, with + # extra logic to suppress the country name if the language is "unique". + locale_name = GnomeDesktop.get_language_from_locale(l, "en_US") + if locale_name: + # Unfortunately, there is also extra logic to add the codeset name. + # Replace "English (United Kingdom) [ISO-8859-1]" with "English + # (United Kingdom)". Inspired by similar code in + # https://github.com/endlessm/eos-installer accompanied by the + # comment "TODO: what is this stupid grumblegrumble...". + locale_name, *rest = locale_name.split(" [") + locale_names.add(locale_name) + else: + unmapped_locale_names.add(locale_name) # Print it all print('{} commits, referencing {} issues and {} ' @@ -267,7 +268,7 @@ def main(): if locale_names: print('') print('* Translation updates:') - for locale, locale_name in sorted(locale_names.items(), key=lambda pair: pair[1]): + for locale_name in sorted(locale_names): print(' - {}'.format(locale_name)) -- GitLab