Use localized website links in the update notification

This commit is contained in:
Kovid Goyal 2017-08-24 10:52:39 +05:30
parent 09d25c21e8
commit fbdefe6bcc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 31 additions and 6 deletions

View File

@ -12,6 +12,7 @@ from calibre.constants import (__appname__, __version__, iswindows, isosx,
isportable, is64bit, numeric_version) isportable, is64bit, numeric_version)
from calibre import prints, as_unicode from calibre import prints, as_unicode
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.utils.localization import localize_website_link
from calibre.utils.https import get_https_resource_securely from calibre.utils.https import get_https_resource_securely
from calibre.gui2 import config, dynamic, open_url from calibre.gui2 import config, dynamic, open_url
from calibre.gui2.dialogs.plugin_updater import get_plugin_updates_available from calibre.gui2.dialogs.plugin_updater import get_plugin_updates_available
@ -26,7 +27,7 @@ def get_download_url():
else 'osx' if isosx else 'linux') else 'osx' if isosx else 'linux')
if which == 'windows' and is64bit: if which == 'windows' and is64bit:
which += '64' which += '64'
return 'https://calibre-ebook.com/download_' + which return localize_website_link('https://calibre-ebook.com/download_' + which)
def get_newest_version(): def get_newest_version():
@ -114,11 +115,11 @@ class UpdateNotification(QDialog):
ver = calibre_version ver = calibre_version
if ver.endswith('.0'): if ver.endswith('.0'):
ver = ver[:-2] ver = ver[:-2]
self.label = QLabel(('<p>'+ self.label = QLabel(('<p>'+ _(
_('New version <b>%(ver)s</b> of %(app)s is available for download. ' 'New version <b>{ver}</b> of {app} is available for download. '
'See the <a href="https://calibre-ebook.com/whats-new' 'See the <a href="{url}">new features</a>.').format(
'">new features</a>.'))%dict( url=localize_website_link('https://calibre-ebook.com/whats-new'),
app=__appname__, ver=ver)) app=__appname__, ver=ver)))
self.label.setOpenExternalLinks(True) self.label.setOpenExternalLinks(True)
self.label.setWordWrap(True) self.label.setWordWrap(True)
self.setWindowTitle(_('Update available!')) self.setWindowTitle(_('Update available!'))

View File

@ -485,3 +485,27 @@ def localize_user_manual_link(url):
parts = list(parts) parts = list(parts)
parts[2] = path parts[2] = path
return urlunparse(parts) return urlunparse(parts)
def website_languages():
stats = getattr(website_languages, 'stats', None)
if stats is None:
try:
stats = frozenset(P('localization/website-languages.txt', allow_user_override=False, data=True).split())
except EnvironmentError:
stats = frozenset()
website_languages.stats = stats
return stats
def localize_website_link(url):
lc = lang_as_iso639_1(get_lang())
langs = website_languages()
if lc == 'en' or lc not in langs:
return url
from urlparse import urlparse, urlunparse
parts = urlparse(url)
path = '/{}{}'.format(lc, parts.path)
parts = list(parts)
parts[2] = path
return urlunparse(parts)