Skip to content

Commit 08e1cfc

Browse files
committed
Added translate-msgs.config.json support, fixed location to project root
1 parent 1d432a9 commit 08e1cfc

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • translate-messages/src/translate_messages/lib

translate-messages/src/translate_messages/lib/init.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ def cli(caller_file):
77
cli = data.sns.from_dict(data.json.read(os.path.join(os.path.dirname(__file__), '../package-data.json')))
88

99
# Load from config file
10-
cli.config=sns()
11-
cli.config.filename = f'{cli.name}.config.json'
12-
cli.config.path = os.path.join(os.path.dirname(caller_file), cli.config.filename)
13-
for key, val in data.json.read(cli.config.path).items() : setattr(cli.config, key, val)
14-
10+
cli.config = sns()
11+
possible_filenames = [f'{cli.name}.config.json', f'{cli.name.replace("messages", "msgs")}.config.json']
12+
project_root = os.path.join(os.path.dirname(caller_file),
13+
f"{ '' if 'src' in os.path.dirname(caller_file) else '../../' }../../")
14+
for filename in possible_filenames:
15+
config_path = os.path.join(project_root, filename)
16+
if os.path.exists(config_path):
17+
cli.config = data.sns.from_dict(data.json.read(config_path)) ; break
18+
1519
# Parse CLI args
1620
argp = argparse.ArgumentParser(description='Translate en/messages.json to other locales')
1721
argp.add_argument('--include-langs', type=str, help='Languages to include (e.g. "en,es,fr")')

0 commit comments

Comments
 (0)