mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 00:12:09 +03:00
Re-format arb files on commit.
This commit is contained in:
parent
243d65fb4d
commit
f07633630f
@ -8,6 +8,14 @@ repos:
|
|||||||
require_serial: true
|
require_serial: true
|
||||||
- id: flutter-analyze
|
- id: flutter-analyze
|
||||||
require_serial: true
|
require_serial: true
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: arb-reformatter
|
||||||
|
name: reformat-strings
|
||||||
|
files: \.arb$
|
||||||
|
language: script
|
||||||
|
entry: arb_reformatter.py
|
||||||
|
require_serial: true
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
- repo: local
|
- repo: local
|
||||||
@ -22,12 +30,10 @@ repos:
|
|||||||
rev: 6.1.0
|
rev: 6.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
files: helper/
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.11.0
|
rev: 23.11.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
files: helper/
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.7.5
|
rev: 1.7.5
|
||||||
hooks:
|
hooks:
|
||||||
|
@ -5,24 +5,33 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
def read_file_lines(file_path):
|
def read_file_lines(file_path):
|
||||||
with open(file_path, 'r', encoding='utf-8') as file:
|
with open(file_path, "r", encoding="utf-8") as file:
|
||||||
return file.readlines()
|
return file.readlines()
|
||||||
|
|
||||||
|
|
||||||
def read_file_json(file_path):
|
def read_file_json(file_path):
|
||||||
with open(file_path, 'r', encoding='utf-8') as file:
|
with open(file_path, "r", encoding="utf-8") as file:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
|
|
||||||
|
|
||||||
def write_to_file(file_path, text):
|
def write_to_file(file_path, text):
|
||||||
with open(file_path, 'w', encoding='utf-8') as file:
|
with open(file_path, "r", encoding="utf-8") as file:
|
||||||
|
if file.read() == text:
|
||||||
|
return False
|
||||||
|
|
||||||
|
with open(file_path, "w", encoding="utf-8") as file:
|
||||||
file.write(text)
|
file.write(text)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Translation table for unicode characters we want to keep in escaped form.
|
# Translation table for unicode characters we want to keep in escaped form.
|
||||||
trans = str.maketrans({
|
trans = str.maketrans(
|
||||||
'\u00a0': r"\u00a0", # No-Break Space (NBSP)
|
{
|
||||||
'\u2026': r"\u2026" # Horizontal Ellipsis
|
"\u00a0": r"\u00a0", # No-Break Space (NBSP)
|
||||||
})
|
"\u2026": r"\u2026", # Horizontal Ellipsis
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Move keys in target into same order as in source.
|
# Move keys in target into same order as in source.
|
||||||
# Keys not present in source are removed from target.
|
# Keys not present in source are removed from target.
|
||||||
@ -68,16 +77,16 @@ def update_arb_file(source_path, target_path, language_code):
|
|||||||
if line.strip() == "":
|
if line.strip() == "":
|
||||||
target_lines.insert(i, "")
|
target_lines.insert(i, "")
|
||||||
|
|
||||||
write_to_file(target_path, "\n".join(target_lines).strip() + "\n")
|
return write_to_file(target_path, "\n".join(target_lines).strip() + "\n")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
source_file_path = 'lib/l10n/app_en.arb'
|
source_file_path = "lib/l10n/app_en.arb"
|
||||||
target_directory = 'lib/l10n'
|
target_directory = "lib/l10n"
|
||||||
|
|
||||||
for file_name in os.listdir(target_directory):
|
for file_name in os.listdir(target_directory):
|
||||||
if file_name.startswith('app_') and file_name.endswith('.arb'):
|
if file_name.startswith("app_") and file_name.endswith(".arb"):
|
||||||
target_file_path = os.path.join(target_directory, file_name)
|
target_file_path = os.path.join(target_directory, file_name)
|
||||||
language_code = file_name.split('_')[1].split('.')[0]
|
language_code = file_name.split("_")[1].split(".")[0]
|
||||||
update_arb_file(source_file_path, target_file_path, language_code)
|
if update_arb_file(source_file_path, target_file_path, language_code):
|
||||||
print(f'File updated: {file_name}')
|
print(f"File updated: {file_name}")
|
||||||
|
@ -106,7 +106,7 @@ if len(sys.argv) != 2:
|
|||||||
|
|
||||||
|
|
||||||
target = sys.argv[1]
|
target = sys.argv[1]
|
||||||
with open(target, encoding='utf-8') as f:
|
with open(target, encoding="utf-8") as f:
|
||||||
values = json.load(f, object_pairs_hook=check_duplicate_keys)
|
values = json.load(f, object_pairs_hook=check_duplicate_keys)
|
||||||
|
|
||||||
strings = {k: v for k, v in values.items() if not k.startswith("@")}
|
strings = {k: v for k, v in values.items() if not k.startswith("@")}
|
||||||
@ -115,7 +115,7 @@ print(target, f"- checking {len(strings)} strings")
|
|||||||
lint_strings(strings, values.get("@_lint_rules", {}))
|
lint_strings(strings, values.get("@_lint_rules", {}))
|
||||||
check_duplicate_values(strings)
|
check_duplicate_values(strings)
|
||||||
|
|
||||||
with open(os.path.join(os.path.dirname(target), 'app_en.arb'), encoding='utf-8') as f:
|
with open(os.path.join(os.path.dirname(target), "app_en.arb"), encoding="utf-8") as f:
|
||||||
reference_values = json.load(f)
|
reference_values = json.load(f)
|
||||||
errors.extend(check_keys_exist_in_reference(reference_values, values))
|
errors.extend(check_keys_exist_in_reference(reference_values, values))
|
||||||
|
|
||||||
|
@ -136,6 +136,7 @@
|
|||||||
|
|
||||||
"@_app_configuration": {},
|
"@_app_configuration": {},
|
||||||
"s_toggle_applications": "Anwendungen umschalten",
|
"s_toggle_applications": "Anwendungen umschalten",
|
||||||
|
"s_toggle_interfaces": null,
|
||||||
"l_min_one_interface": "Mindestens ein Interface muss aktiviert sein",
|
"l_min_one_interface": "Mindestens ein Interface muss aktiviert sein",
|
||||||
"s_reconfiguring_yk": "YubiKey wird neu konfiguriert\u2026",
|
"s_reconfiguring_yk": "YubiKey wird neu konfiguriert\u2026",
|
||||||
"s_config_updated": "Konfiguration aktualisiert",
|
"s_config_updated": "Konfiguration aktualisiert",
|
||||||
|
@ -136,6 +136,7 @@
|
|||||||
|
|
||||||
"@_app_configuration": {},
|
"@_app_configuration": {},
|
||||||
"s_toggle_applications": "Changer les applications",
|
"s_toggle_applications": "Changer les applications",
|
||||||
|
"s_toggle_interfaces": null,
|
||||||
"l_min_one_interface": "Au moins une interface doit être activée",
|
"l_min_one_interface": "Au moins une interface doit être activée",
|
||||||
"s_reconfiguring_yk": "Reconfiguration de la YubiKey\u2026",
|
"s_reconfiguring_yk": "Reconfiguration de la YubiKey\u2026",
|
||||||
"s_config_updated": "Configuration mise à jour",
|
"s_config_updated": "Configuration mise à jour",
|
||||||
|
@ -136,6 +136,7 @@
|
|||||||
|
|
||||||
"@_app_configuration": {},
|
"@_app_configuration": {},
|
||||||
"s_toggle_applications": "アプリケーションの切替え",
|
"s_toggle_applications": "アプリケーションの切替え",
|
||||||
|
"s_toggle_interfaces": null,
|
||||||
"l_min_one_interface": "少なくとも 1 つのインターフェイスを有効にする必要があります",
|
"l_min_one_interface": "少なくとも 1 つのインターフェイスを有効にする必要があります",
|
||||||
"s_reconfiguring_yk": "YubiKeyを再構成しています\u2026",
|
"s_reconfiguring_yk": "YubiKeyを再構成しています\u2026",
|
||||||
"s_config_updated": "構成が更新されました",
|
"s_config_updated": "構成が更新されました",
|
||||||
|
Loading…
Reference in New Issue
Block a user