Skip to content

Instantly share code, notes, and snippets.

@nhancv
Created August 6, 2020 04:58
Show Gist options
  • Save nhancv/e067c774113efbca4caa232df220a4ad to your computer and use it in GitHub Desktop.
Save nhancv/e067c774113efbca4caa232df220a4ad to your computer and use it in GitHub Desktop.
convert arb to csv for flutter intl
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