diff --git a/setup/translations.py b/setup/translations.py index 714d4c7c90..426972dc8d 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -294,7 +294,8 @@ class Translations(POT): # {{{ base = os.path.dirname(dest) if not os.path.exists(base): os.makedirs(base) - data, current_hash = self.hash_and_data(src) + data, h = self.hash_and_data(src) + current_hash = h.digest() saved_hash, saved_data = self.read_cache(src) if current_hash == saved_hash: with open(dest, 'wb') as d: @@ -384,7 +385,7 @@ class Translations(POT): # {{{ data = s.read() h = hashlib.sha1(data) h.update(f.encode('utf-8')) - return data, h.digest() + return data, h def compile_content_server_translations(self): self.info('Compiling content-server translations') @@ -392,7 +393,8 @@ class Translations(POT): # {{{ from calibre.utils.zipfile import ZipFile, ZIP_DEFLATED, ZipInfo, ZIP_STORED with ZipFile(self.j(self.RESOURCES, 'content-server', 'locales.zip'), 'w', ZIP_DEFLATED) as zf: for src in glob.glob(os.path.join(self.TRANSLATIONS, 'content-server', '*.po')): - data, current_hash = self.hash_and_data(src) + data, h = self.hash_and_data(src) + current_hash = h.digest() saved_hash, saved_data = self.read_cache(src) if current_hash == saved_hash: raw = saved_data @@ -402,7 +404,8 @@ class Translations(POT): # {{{ po_data = data.decode('utf-8') data = json.loads(msgfmt(po_data)) translated_entries = {k:v for k, v in data['entries'].iteritems() if v and sum(map(len, v))} - data['entries'] = translated_entries + data[u'entries'] = translated_entries + data[u'hash'] = h.hexdigest() cdata = b'{}' if translated_entries: raw = json.dumps(data, ensure_ascii=False, sort_keys=True) diff --git a/src/calibre/srv/code.py b/src/calibre/srv/code.py index d4c2b024e3..1f77ebaaba 100644 --- a/src/calibre/srv/code.py +++ b/src/calibre/srv/code.py @@ -154,12 +154,16 @@ def basic_interface_data(ctx, rd): return ans -@endpoint('/interface-data/update', postprocess=json) -def update_interface_data(ctx, rd): +@endpoint('/interface-data/update/{translations_hash=None}', postprocess=json) +def update_interface_data(ctx, rd, translations_hash): ''' Return the interface data needed for the server UI ''' - return basic_interface_data(ctx, rd) + ans = basic_interface_data(ctx, rd) + t = ans['translations'] + if t and (t.get('hash') or translations_hash) and t.get('hash') == translations_hash: + del ans['translations'] + return ans def get_field_list(db): diff --git a/src/pyj/book_list/main.pyj b/src/pyj/book_list/main.pyj index 6c38801908..eaae90ae92 100644 --- a/src/pyj/book_list/main.pyj +++ b/src/pyj/book_list/main.pyj @@ -122,7 +122,12 @@ def load_interface_data(): def do_update_interface_data(): - ajax('interface-data/update', def (end_type, xhr, ev): + t = get_translations() + thash = t?.hash + url = 'interface-data/update' + if thash: + url += '/' + thash + ajax(url, def (end_type, xhr, ev): if end_type is 'load': data = JSON.parse(xhr.responseText) update_interface_data(data)