| 1 | import os |
|---|
| 2 | import io |
|---|
| 3 | import sys |
|---|
| 4 | |
|---|
| 5 | from buildtools.localeTools import toJSON |
|---|
| 6 | |
|---|
| 7 | EXTENSIONS = {'dtd', 'properties'} |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | def convert_all_translations(path): |
|---|
| 11 | trans_files = [] |
|---|
| 12 | for root, folder, files in os.walk(path): |
|---|
| 13 | t_files = [f for f in files |
|---|
| 14 | if any(f.endswith(ext) for ext in EXTENSIONS)] |
|---|
| 15 | for f in t_files: |
|---|
| 16 | trans_files.append(os.path.join(root, f)) |
|---|
| 17 | |
|---|
| 18 | for file_path in trans_files: |
|---|
| 19 | new_name = '.'.join(file_path.split('.')[:-1] + ['json']) |
|---|
| 20 | print 'converting {} -> {}'.format( |
|---|
| 21 | file_path, new_name |
|---|
| 22 | ) |
|---|
| 23 | with io.open(new_name, 'w', encoding='utf-8') as fp: |
|---|
| 24 | fp.write(toJSON(file_path)) |
|---|
| 25 | |
|---|
| 26 | if __name__ == '__main__': |
|---|
| 27 | if len(sys.argv) > 1: |
|---|
| 28 | convert_all_translations(sys.argv[1]) |
|---|
| 29 | else: |
|---|
| 30 | print 'Please provide a translation path.' |
|---|