mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Function to localize links to the user manual
This commit is contained in:
parent
1c6ddefbf9
commit
cc908ac22e
@ -380,4 +380,21 @@ def get_udc():
|
|||||||
_udc = Unihandecoder(lang=get_lang())
|
_udc = Unihandecoder(lang=get_lang())
|
||||||
return _udc
|
return _udc
|
||||||
|
|
||||||
|
def localize_user_manual_link(url):
|
||||||
|
lc = lang_as_iso639_1(get_lang())
|
||||||
|
if lc == 'en':
|
||||||
|
return url
|
||||||
|
import json
|
||||||
|
try:
|
||||||
|
stats = json.loads(P('user-manual-translation-stats.json', allow_user_override=False, data=True))
|
||||||
|
except EnvironmentError:
|
||||||
|
return url
|
||||||
|
if stats.get(lc, 0) < 0.3:
|
||||||
|
return url
|
||||||
|
from urlparse import urlparse, urlunparse
|
||||||
|
parts = urlparse(url)
|
||||||
|
path = re.sub(r'/generated/[a-z]+/', '/generated/%s/' % lc, parts.path or '')
|
||||||
|
path = '/%s%s' % (lc, path)
|
||||||
|
parts = list(parts)
|
||||||
|
parts[2] = path
|
||||||
|
return urlunparse(parts)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user