Skip to content

Commit f9b61c1

Browse files
committed
translation: remove old translations
Remove translated files when the source file get removed. This includes also renaming files.
1 parent 7dc996c commit f9b61c1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

_utils/_translation_utils/post_transifex_pull.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ echo "============================ post processing step 1 ======================
1010
#read b
1111
bash _utils/_translation_utils/prepare_tx_config_postprocess.sh .tx/config /tmp/tx-mapping
1212

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

1416
echo "============================ post processing step 2 ======================================"
1517
#read b
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/python3
2+
3+
import argparse
4+
import os
5+
import sys
6+
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument('lang')
9+
parser.add_argument('translation_dir')
10+
parser.add_argument('tx_mapping')
11+
12+
def main():
13+
args = parser.parse_args()
14+
15+
valid_files = set()
16+
with open(args.tx_mapping) as f_mapping:
17+
for line in f_mapping.readlines():
18+
if line.startswith('file_filter = '):
19+
valid_files.add(line.strip().split(' = ')[1].replace('<lang>', args.lang))
20+
21+
if not valid_files:
22+
print('No files found in {}, aborting!'.format(args.tx_mapping))
23+
return 1
24+
25+
existing_files = set()
26+
for dirpath, dirs, files in os.walk(args.translation_dir):
27+
existing_files.update(os.path.join(dirpath, name) for name in files)
28+
29+
if not existing_files:
30+
print('No files found in {}, aborting!'.format(args.translation_dir))
31+
return 1
32+
33+
for obsolete in existing_files.difference(valid_files):
34+
print('Removing {}'.format(obsolete))
35+
os.unlink(obsolete)
36+
37+
38+
if __name__ == '__main__':
39+
sys.exit(main())
40+

0 commit comments

Comments
 (0)