Translate language and country names separately in the fetch news dialog

This commit is contained in:
Kovid Goyal 2023-07-13 19:27:52 +05:30
parent aaeeb51573
commit af5bd7ee60
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 6 deletions

View File

@ -377,8 +377,6 @@ _extra_lang_codes = {
'de_AT' : _('German (Austria)'), 'de_AT' : _('German (Austria)'),
'fr_BE' : _('French (Belgium)'), 'fr_BE' : _('French (Belgium)'),
'fr_CA' : _('French (Canadian)'), 'fr_CA' : _('French (Canadian)'),
'nl' : _('Dutch (Netherlands)'),
'nl_BE' : _('Dutch (Belgium)'),
'und' : _('Unknown') 'und' : _('Unknown')
} }
@ -411,6 +409,7 @@ if False:
_('Step &down') _('Step &down')
_('Close without Saving') _('Close without Saving')
_('Close Tab') _('Close Tab')
_('Ukraine')
_lcase_map = {} _lcase_map = {}
for k in _extra_lang_codes: for k in _extra_lang_codes:
@ -478,6 +477,9 @@ def countrycode_to_name(cc, localize=True):
try: try:
name = iso3166['names'][q] name = iso3166['names'][q]
except Exception: except Exception:
if q == 'UK':
name = 'Ukraine'
else:
return cc return cc
translate = _ if localize else lambda x: x translate = _ if localize else lambda x: x
try: try:

View File

@ -11,7 +11,7 @@ from qt.core import (
from calibre import force_unicode from calibre import force_unicode
from calibre.utils.icu import primary_sort_key from calibre.utils.icu import primary_sort_key
from calibre.utils.localization import _, get_language from calibre.utils.localization import _, get_language, countrycode_to_name
from calibre.utils.resources import get_path as P from calibre.utils.resources import get_path as P
from calibre.utils.search_query_parser import ParseException, SearchQueryParser from calibre.utils.search_query_parser import ParseException, SearchQueryParser
from calibre.web.feeds.recipes.collection import ( from calibre.web.feeds.recipes.collection import (
@ -60,18 +60,28 @@ class NewsTreeItem:
child.parent = None child.parent = None
def parse_lang_code(x: str) -> str:
lang, sep, country = x.partition('_')
country = country.upper()
ans = get_language(lang)
if country:
ans = _('{language} ({country})').format(language=ans, country=countrycode_to_name(country))
return ans
@total_ordering @total_ordering
class NewsCategory(NewsTreeItem): class NewsCategory(NewsTreeItem):
def __init__(self, category, builtin, custom, scheduler_config, parent): def __init__(self, category, builtin, custom, scheduler_config, parent):
NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent) NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent)
self.category = category self.category = self.cdata = category
self.cdata = get_language(self.category) self.cdata = self.category
if self.category == _('Scheduled'): if self.category == _('Scheduled'):
self.sortq = 0, '' self.sortq = 0, ''
elif self.category == _('Custom'): elif self.category == _('Custom'):
self.sortq = 1, '' self.sortq = 1, ''
else: else:
self.cdata = parse_lang_code(self.cdata)
self.sortq = 2, self.cdata self.sortq = 2, self.cdata
self.bold_font = QFont() self.bold_font = QFont()
self.bold_font.setBold(True) self.bold_font.setBold(True)