mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-10-09 06:56:37 +00:00
fix(i18n): translate texts with line breaks; drop the experimental label of OCI stacks
This commit is contained in:
@@ -51,7 +51,7 @@ FIXTURE={shlex.quote(str(directory))}
|
||||
BACKEND={backend}
|
||||
HB_UI_MENU_H=20 HB_UI_MENU_W=84 HB_UI_MENU_LIST=10
|
||||
command_not_found_handle() {{ printf 'FORBIDDEN:%s\\n' "$*" >> "$FIXTURE/errors"; return 99; }}
|
||||
jq() {{ [[ "$#" == 6 && "$1" == -r && "$2" == --arg && "$3" == text && "$5" == '.[$text] // empty' && "$6" == "$FIXTURE/xx.json" ]] || {{ printf 'bad jq' >> "$FIXTURE/errors"; return 99; }}; command jq "$@"; }}
|
||||
jq() {{ [[ "$#" == 6 && "$1" == -r && "$2" == --arg && "$3" == text && "$5" == '.[$text] // .[($text | gsub("\\\\\\\\n"; "\\n"))] // empty' && "$6" == "$FIXTURE/xx.json" ]] || {{ printf 'bad jq' >> "$FIXTURE/errors"; return 99; }}; command jq "$@"; }}
|
||||
head() {{ [[ "$*" == '-1' ]] || return 99; local first; IFS= read -r first; printf '%s\\n' "$first"; while IFS= read -r first; do :; done; }}
|
||||
hb_pve_list_vzdump_jobs() {{
|
||||
local file="$FIXTURE/rows" line
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""A script writes a line break as \\n inside the text it translates; the
|
||||
language files store that text with a real line break."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
|
||||
|
||||
def function(text, name):
|
||||
start = text.index(name + '() {')
|
||||
return text[start:text.index('\n}\n', start) + 3]
|
||||
|
||||
|
||||
class TranslateLineBreaks(TestCase):
|
||||
def translate(self, text, catalog):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
(Path(folder) / 'xx.json').write_text(json.dumps(catalog))
|
||||
script = (f'LANGUAGE=xx LANG_DIR={folder}\n' + function((ROOT / 'scripts/utils.sh').read_text(), 'translate')
|
||||
+ 'translate "$1"\n')
|
||||
result = subprocess.run(['/bin/bash', '--noprofile', '--norc', '-c', script, 'bash', text],
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual((result.returncode, result.stderr), (0, ''))
|
||||
return result.stdout.rstrip('\n')
|
||||
|
||||
def test_a_text_stored_with_a_real_line_break_is_found(self):
|
||||
catalog = {'Restore this backup?\nThe configuration is overwritten.': '¿Restaurar?\nSe sobrescribe.'}
|
||||
self.assertEqual(self.translate('Restore this backup?\\nThe configuration is overwritten.', catalog),
|
||||
'¿Restaurar?\nSe sobrescribe.')
|
||||
|
||||
def test_the_exact_text_is_preferred_and_a_missing_one_comes_back_unchanged(self):
|
||||
catalog = {'one\\ntwo': 'LITERAL', 'one\ntwo': 'REAL', 'plain': 'simple'}
|
||||
self.assertEqual(self.translate('one\\ntwo', catalog), 'LITERAL')
|
||||
self.assertEqual(self.translate('plain', catalog), 'simple')
|
||||
self.assertEqual(self.translate('not\\nthere', catalog), 'not\\nthere')
|
||||
|
||||
def test_the_shipped_texts_with_a_line_break_reach_the_spanish_file(self):
|
||||
spanish = json.loads((ROOT / 'lang/es.json').read_text())
|
||||
text = 'Are you sure you want to restore this backup?\\nCurrent configuration will be overwritten.'
|
||||
self.assertEqual(self.translate(text, spanish), spanish[text.replace('\\n', '\n')])
|
||||
Reference in New Issue
Block a user