Skip to content

Commit ca36183

Browse files
committed
Created/used data.json.write() ↞ [auto-sync from https://github.com/adamlui/python-utils/tree/main/translate-messages]
1 parent a3eb1d1 commit ca36183

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from . import csv
2+
from . import json
23

3-
__all__ = ['csv']
4+
__all__ = ['csv', 'json']
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import json, os
2+
3+
def write(srcData, targetPath):
4+
os.makedirs(os.path.dirname(targetPath), exist_ok=True)
5+
with open(targetPath, 'w', encoding='utf-8') as file:
6+
json.dump(srcData, file, indent=2)

translate-messages/lib/init.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ def config_file(cli):
6666
cli.config_data = resp.json()
6767
except (requests.RequestException, ValueError):
6868
cli.config_data = {}
69-
70-
with open(cli.config_path, 'w', encoding='utf-8') as config_file:
71-
json.dump(cli.config_data, config_file, indent=2)
72-
69+
70+
data.json.write(cli.config_data, cli.config_path)
7371
print(f'Default config created at {cli.config_path}')
7472

7573
def locales_dir(locales_dir):

0 commit comments

Comments
 (0)