Script to find unused translations
This commit is contained in:
parent
1caf8b8d21
commit
9f274a7d1c
@ -27,6 +27,22 @@ def _translations_file():
|
|||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def all_keys():
|
||||||
|
translations = _translations_file()
|
||||||
|
keys = []
|
||||||
|
|
||||||
|
def _recursive_key_lookup(chain):
|
||||||
|
results = getattr_path(translations, chain)
|
||||||
|
if isinstance(results, str):
|
||||||
|
keys.append(chain)
|
||||||
|
else:
|
||||||
|
[_recursive_key_lookup(".".join([chain, result])) for result in results]
|
||||||
|
|
||||||
|
[_recursive_key_lookup(key) for key in translations]
|
||||||
|
|
||||||
|
return keys
|
||||||
|
|
||||||
|
|
||||||
def translate(key, variables=None):
|
def translate(key, variables=None):
|
||||||
translations = _translations_file()
|
translations = _translations_file()
|
||||||
value = getattr_path(translations, key)
|
value = getattr_path(translations, key)
|
||||||
|
17
script/find_unused_translations.py
Executable file
17
script/find_unused_translations.py
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#! .venv/bin/python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from subprocess import check_output
|
||||||
|
|
||||||
|
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
sys.path.append(parent_dir)
|
||||||
|
|
||||||
|
from atst.utils.localization import all_keys
|
||||||
|
|
||||||
|
for key in all_keys():
|
||||||
|
try:
|
||||||
|
check_output("git grep -q '{}'".format(key), shell=True)
|
||||||
|
except Exception:
|
||||||
|
print(key)
|
@ -1,5 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from atst.utils.localization import translate, LocalizationInvalidKeyError
|
from atst.utils.localization import all_keys, translate, LocalizationInvalidKeyError
|
||||||
|
|
||||||
|
|
||||||
def test_looking_up_existing_key():
|
def test_looking_up_existing_key():
|
||||||
@ -22,3 +22,9 @@ def test_with_variables():
|
|||||||
def test_looking_up_non_existent_key():
|
def test_looking_up_non_existent_key():
|
||||||
with pytest.raises(LocalizationInvalidKeyError):
|
with pytest.raises(LocalizationInvalidKeyError):
|
||||||
translate("testing.an.invalid_key")
|
translate("testing.an.invalid_key")
|
||||||
|
|
||||||
|
|
||||||
|
def test_all_keys():
|
||||||
|
assert "testing.example_with_variables" in all_keys()
|
||||||
|
assert "testing.nested.example" in all_keys()
|
||||||
|
assert not "testing.nested.missing" in all_keys()
|
||||||
|
@ -27,7 +27,6 @@ home:
|
|||||||
funding_descrip: is information about all approved task orders associated to your portfolio.
|
funding_descrip: is information about all approved task orders associated to your portfolio.
|
||||||
applications_descrip: ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
applications_descrip: ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
||||||
reports_descrip: enim ad minim veniam, quis nostrud exercitation ullamco
|
reports_descrip: enim ad minim veniam, quis nostrud exercitation ullamco
|
||||||
admin_descrip: aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
|
|
||||||
common:
|
common:
|
||||||
back: Back
|
back: Back
|
||||||
cancel: Cancel
|
cancel: Cancel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user