Skip to content

Commit

Permalink
translation: remove old translations
Browse files Browse the repository at this point in the history
Remove translated files when the source file get removed. This includes
also renaming files.
  • Loading branch information
marmarek committed Jun 23, 2021
1 parent d423768 commit d7017ca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _utils/_translation_utils/post_transifex_pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ echo "============================ post processing step 1 ======================
#read b
bash _utils/_translation_utils/prepare_tx_config_postprocess.sh .tx/config /tmp/tx-mapping

echo "============================ remove obsolete files ======================================="
python3 _utils/_translation_utils/remove_obsolete_files.py "$1" "$2" /tmp/tx-mapping

echo "============================ post processing step 2 ======================================"
#read b
Expand Down
40 changes: 40 additions & 0 deletions _utils/_translation_utils/remove_obsolete_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python3

import argparse
import os
import sys

parser = argparse.ArgumentParser()
parser.add_argument('lang')
parser.add_argument('translation_dir')
parser.add_argument('tx_mapping')

def main():
args = parser.parse_args()

valid_files = set()
with open(args.tx_mapping) as f_mapping:
for line in f_mapping.readlines():
if line.startswith('file_filter = '):
valid_files.add(line.strip().split(' = ')[1].replace('<lang>', args.lang))

if not valid_files:
print('No files found in {}, aborting!'.format(args.tx_mapping))
return 1

existing_files = set()
for dirpath, dirs, files in os.walk(args.translation_dir):
existing_files.update(os.path.join(dirpath, name) for name in files)

if not existing_files:
print('No files found in {}, aborting!'.format(args.translation_dir))
return 1

for obsolete in existing_files.difference(valid_files):
print('Removing {}'.format(obsolete))
os.unlink(obsolete)


if __name__ == '__main__':
sys.exit(main())

0 comments on commit d7017ca

Please sign in to comment.