Skip to content

Commit 644aef6

Browse files
Adding cache for translation calls
Signed-off-by: Jacki <[email protected]>
1 parent f107c63 commit 644aef6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

manuskript/functions/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@
2323
MW = None
2424

2525

26+
translationCache = dict()
27+
28+
def resetTranslation():
29+
translationCache.clear()
30+
2631
def safeTranslate(qApp, group, text):
32+
if text in translationCache:
33+
return translationCache[text]
34+
2735
try:
28-
return qApp.translate(group, text)
36+
_text = qApp.translate(group, text)
37+
translationCache[text] = _text
38+
return _text
2939
except:
3040
return text
3141

42+
3243
def wordCount(text):
3344
return len(re.findall(r"\S+", re.sub(r"(<!--).+?(-->)", "", text, flags=re.DOTALL)))
3445

manuskript/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from PyQt5.QtGui import QIcon, QColor, QPalette
1212
from PyQt5.QtWidgets import QApplication, qApp, QStyleFactory
1313

14-
from manuskript.functions import appPath, writablePath
14+
from manuskript.functions import appPath, writablePath, resetTranslation
1515
from manuskript.version import getVersion
1616

1717
try:
@@ -86,6 +86,7 @@ def tryLoadTranslation(translation, source):
8686
def activateTranslation(translation, source):
8787
"""Loads the most suitable translation based on the available information."""
8888
using_builtin_translation = True
89+
resetTranslation()
8990

9091
if (translation != ""): # empty string == 'no translation, use builtin'
9192
if isinstance(translation, str):

0 commit comments

Comments
 (0)