mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add translation file caching, show file read error (if any) and fix a typo in the Finnish translation.
This commit is contained in:
parent
13d8259869
commit
55d63c1f7a
@ -11,14 +11,21 @@ logger = logging.getLogger(__name__)
|
||||
class Translation():
|
||||
def __init__(self):
|
||||
self.translations_path = os.path.join(helper.root_dir, 'app', 'translations')
|
||||
self.cached_translation = None
|
||||
self.cached_translation_lang = None
|
||||
def translate(self, page, word):
|
||||
translated_word = None
|
||||
lang = helper.get_setting('language')
|
||||
fallback_lang = 'en_EN'
|
||||
|
||||
translated_word = \
|
||||
self.translate_inner(page, word, lang) or \
|
||||
self.translate_inner(page, word, fallback_lang)
|
||||
lang_file_exists = helper.check_file_exists(
|
||||
os.path.join(
|
||||
self.translations_path, lang + '.json'
|
||||
)
|
||||
)
|
||||
|
||||
translated_word = self.translate_inner(page, word, lang) \
|
||||
if lang_file_exists else self.translate_inner(page, word, fallback_lang)
|
||||
|
||||
if translated_word:
|
||||
if isinstance(translated_word, dict): return json.dumps(translated_word)
|
||||
@ -31,8 +38,17 @@ class Translation():
|
||||
lang + '.json'
|
||||
)
|
||||
try:
|
||||
with open(lang_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
if not self.cached_translation:
|
||||
with open(lang_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
self.cached_translation = data
|
||||
elif self.cached_translation_lang != lang:
|
||||
with open(lang_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
self.cached_translation = data
|
||||
self.cached_translation_lang = lang
|
||||
else:
|
||||
data = self.cached_translation
|
||||
|
||||
try:
|
||||
translated_page = data[page]
|
||||
|
@ -194,6 +194,7 @@
|
||||
}
|
||||
</style>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<h2 id="fileError"></h2>
|
||||
<div id="editorParent">
|
||||
{{ translate('serverFiles', 'editingFile') }} <span id="editingFile"></span>
|
||||
<div id="editor" onresize="editor.resize()" style="resize: both;width: 100%;">file_contents</div>
|
||||
@ -344,10 +345,13 @@
|
||||
console.log('Got File Contents From Server');
|
||||
json = JSON.parse(data)
|
||||
if (json.error) {
|
||||
$('#editorParent').toggle(false)
|
||||
$('#editorParent').toggle(false) // hide
|
||||
$('#fileError').toggle(true) // show
|
||||
$('#fileError').text("{{ translate('serverFiles', 'fileReadError') }}: " + json.error) // show error
|
||||
editor.blur()
|
||||
} else {
|
||||
$('#editorParent').toggle(true)
|
||||
$('#editorParent').toggle(true) // show
|
||||
$('#fileError').toggle(false) // hide
|
||||
setFileName(event.target.innerText);
|
||||
editor.session.setValue(json.content);
|
||||
}
|
||||
@ -376,7 +380,8 @@
|
||||
}
|
||||
|
||||
setFileName();
|
||||
$('#editorParent').toggle(false)
|
||||
$('#editorParent').toggle(false) // show
|
||||
$('#fileError').toggle(false) // hide
|
||||
editor.blur()
|
||||
|
||||
function setMode (extension) {
|
||||
|
@ -170,7 +170,8 @@
|
||||
"yesDelete": "Yes, I understand the consequences",
|
||||
"noDelete": "No",
|
||||
"unsupportedLanguage": "Warning: This is not a supported file type",
|
||||
"keybindings": "Keybindings"
|
||||
"keybindings": "Keybindings",
|
||||
"fileReadError": "File read error"
|
||||
},
|
||||
"serverConfig": {
|
||||
"serverName": "Server Name",
|
||||
|
@ -166,11 +166,12 @@
|
||||
"createDirQuestion": "Minkä nimen haluat uudelle hakemistolle?",
|
||||
"renameItemQuestion": "Mikä uuden nimen pitäisi olla?",
|
||||
"deleteItemQuestion": "Haluatko varmasti poistaa \" + name + \"?",
|
||||
"deleteItemQuestionMessage": "Olet poistamassa \\\"\" + path + \"\\\"!<br/><br/>Tämä toiminta on peruuttamaton ja se menetetään ikuisesti!",
|
||||
"deleteItemQuestionMessage": "Olet poistamassa \\\"\" + path + \"\\\"!<br/><br/>Tämä toiminto on peruuttamaton ja se menetetään ikuisesti!",
|
||||
"yesDelete": "Kyllä, ymmärrän seuraukset",
|
||||
"noDelete": "En",
|
||||
"unsupportedLanguage": "Varoitus: Tätä tiedostotyyppiä ei tueta",
|
||||
"keybindings": "Pikanäppäimet"
|
||||
"keybindings": "Pikanäppäimet",
|
||||
"fileReadError": "Tiedoston lukuvirhe"
|
||||
},
|
||||
"serverConfig": {
|
||||
"serverName": "Palvelimen nimi",
|
||||
|
Loading…
Reference in New Issue
Block a user