Created
August 6, 2020 04:58
-
-
Save nhancv/e067c774113efbca4caa232df220a4ad to your computer and use it in GitHub Desktop.
convert arb to csv for flutter intl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
import os | |
cmd_path = os.path.dirname(__file__) | |
# Init file | |
intl_name = 'intl_vi' | |
arb_file_path = cmd_path + '/' + 'lib/l10n/' + intl_name + '.arb' | |
csv_file_path = cmd_path + '/' + 'lib/l10n/' + intl_name + '.csv' | |
# Read arb | |
with open(arb_file_path, 'r', encoding='utf8') as f: | |
intl_dict = json.load(f) | |
for key in list(intl_dict): | |
if key.startswith('@') and key != '@@locale': | |
del intl_dict[key] | |
# Write to csv | |
with open(csv_file_path, mode='w', encoding='utf8') as csv_file: | |
fieldnames = ['key', 'string'] | |
writer = csv.DictWriter(csv_file, fieldnames=fieldnames) | |
for key in list(intl_dict): | |
writer.writerow({'key': key, 'string': intl_dict[key]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment