|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
| 3 | +import argparse |
3 | 4 | import json
|
4 | 5 | import os
|
5 | 6 | from pathlib import Path
|
6 | 7 |
|
7 | 8 |
|
| 9 | +def parse_langs(langs, include_beta): |
| 10 | + for line in langs.readlines(): |
| 11 | + description = line[3:-7] |
| 12 | + code = line[-5:-3] |
| 13 | + |
| 14 | + if include_beta or 'beta' not in description: |
| 15 | + yield code, description |
| 16 | + |
8 | 17 | def main():
|
9 |
| - directory = Path(__file__).absolute().parent.parent |
10 |
| - languages = sorted(x.name for x in directory.iterdir() |
11 |
| - if x.is_dir() and len(x.name) == 2 and x.name != 'en') |
| 18 | + parser = argparse.ArgumentParser() |
| 19 | + parser.add_argument('--include-beta', help='Include beta languages', default='false', |
| 20 | + choices=('true', 'false')) |
| 21 | + parser.add_argument('--langs-file', help='LANGS.md to use', |
| 22 | + type=argparse.FileType('r', encoding='UTF-8'), |
| 23 | + default=(Path(__file__).absolute().parent.parent / 'LANGS.md').as_posix()) |
| 24 | + args = parser.parse_args() |
| 25 | + |
| 26 | + languages = dict(parse_langs(args.langs_file, args.include_beta == 'true')) |
12 | 27 |
|
13 | 28 | if 'GITHUB_ACTION' in os.environ:
|
14 |
| - print(f'::set-output name=languages::{json.dumps(languages)}') |
15 |
| - for language in languages: |
16 |
| - print(language) |
| 29 | + print(f'::set-output name=languages::{json.dumps(list(languages.keys()))}') |
| 30 | + for code, language in languages.items(): |
| 31 | + print(f'{language} ({code})') |
17 | 32 |
|
18 | 33 |
|
19 | 34 | if __name__ == '__main__':
|
|
0 commit comments