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():
|
class Translation():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.translations_path = os.path.join(helper.root_dir, 'app', 'translations')
|
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):
|
def translate(self, page, word):
|
||||||
translated_word = None
|
translated_word = None
|
||||||
lang = helper.get_setting('language')
|
lang = helper.get_setting('language')
|
||||||
fallback_lang = 'en_EN'
|
fallback_lang = 'en_EN'
|
||||||
|
|
||||||
translated_word = \
|
lang_file_exists = helper.check_file_exists(
|
||||||
self.translate_inner(page, word, lang) or \
|
os.path.join(
|
||||||
self.translate_inner(page, word, fallback_lang)
|
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 translated_word:
|
||||||
if isinstance(translated_word, dict): return json.dumps(translated_word)
|
if isinstance(translated_word, dict): return json.dumps(translated_word)
|
||||||
@ -31,8 +38,17 @@ class Translation():
|
|||||||
lang + '.json'
|
lang + '.json'
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
with open(lang_file, 'r') as f:
|
if not self.cached_translation:
|
||||||
data = json.load(f)
|
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:
|
try:
|
||||||
translated_page = data[page]
|
translated_page = data[page]
|
||||||
|
@ -194,6 +194,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="col-md-6 col-sm-12">
|
<div class="col-md-6 col-sm-12">
|
||||||
|
<h2 id="fileError"></h2>
|
||||||
<div id="editorParent">
|
<div id="editorParent">
|
||||||
{{ translate('serverFiles', 'editingFile') }} <span id="editingFile"></span>
|
{{ translate('serverFiles', 'editingFile') }} <span id="editingFile"></span>
|
||||||
<div id="editor" onresize="editor.resize()" style="resize: both;width: 100%;">file_contents</div>
|
<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');
|
console.log('Got File Contents From Server');
|
||||||
json = JSON.parse(data)
|
json = JSON.parse(data)
|
||||||
if (json.error) {
|
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()
|
editor.blur()
|
||||||
} else {
|
} else {
|
||||||
$('#editorParent').toggle(true)
|
$('#editorParent').toggle(true) // show
|
||||||
|
$('#fileError').toggle(false) // hide
|
||||||
setFileName(event.target.innerText);
|
setFileName(event.target.innerText);
|
||||||
editor.session.setValue(json.content);
|
editor.session.setValue(json.content);
|
||||||
}
|
}
|
||||||
@ -376,7 +380,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
setFileName();
|
setFileName();
|
||||||
$('#editorParent').toggle(false)
|
$('#editorParent').toggle(false) // show
|
||||||
|
$('#fileError').toggle(false) // hide
|
||||||
editor.blur()
|
editor.blur()
|
||||||
|
|
||||||
function setMode (extension) {
|
function setMode (extension) {
|
||||||
|
@ -170,7 +170,8 @@
|
|||||||
"yesDelete": "Yes, I understand the consequences",
|
"yesDelete": "Yes, I understand the consequences",
|
||||||
"noDelete": "No",
|
"noDelete": "No",
|
||||||
"unsupportedLanguage": "Warning: This is not a supported file type",
|
"unsupportedLanguage": "Warning: This is not a supported file type",
|
||||||
"keybindings": "Keybindings"
|
"keybindings": "Keybindings",
|
||||||
|
"fileReadError": "File read error"
|
||||||
},
|
},
|
||||||
"serverConfig": {
|
"serverConfig": {
|
||||||
"serverName": "Server Name",
|
"serverName": "Server Name",
|
||||||
|
@ -166,11 +166,12 @@
|
|||||||
"createDirQuestion": "Minkä nimen haluat uudelle hakemistolle?",
|
"createDirQuestion": "Minkä nimen haluat uudelle hakemistolle?",
|
||||||
"renameItemQuestion": "Mikä uuden nimen pitäisi olla?",
|
"renameItemQuestion": "Mikä uuden nimen pitäisi olla?",
|
||||||
"deleteItemQuestion": "Haluatko varmasti poistaa \" + name + \"?",
|
"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",
|
"yesDelete": "Kyllä, ymmärrän seuraukset",
|
||||||
"noDelete": "En",
|
"noDelete": "En",
|
||||||
"unsupportedLanguage": "Varoitus: Tätä tiedostotyyppiä ei tueta",
|
"unsupportedLanguage": "Varoitus: Tätä tiedostotyyppiä ei tueta",
|
||||||
"keybindings": "Pikanäppäimet"
|
"keybindings": "Pikanäppäimet",
|
||||||
|
"fileReadError": "Tiedoston lukuvirhe"
|
||||||
},
|
},
|
||||||
"serverConfig": {
|
"serverConfig": {
|
||||||
"serverName": "Palvelimen nimi",
|
"serverName": "Palvelimen nimi",
|
||||||
|
Loading…
Reference in New Issue
Block a user