Skip to content

Commit

Permalink
preparing #1 i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
myselfhimself committed Oct 18, 2020
1 parent e8626b9 commit e8bd712
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 5,325 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
190 changes: 0 additions & 190 deletions day4/j4_noio.svg

This file was deleted.

Binary file removed day4/j4_noio3.png
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed day7/j7_senza.png
Binary file not shown.
5,135 changes: 0 additions & 5,135 deletions day7/j7_senza.svg

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
33 changes: 33 additions & 0 deletions translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import csv
import glob
import shutil
import os
import os.path

days = {}
DEFAULT_LANG = "fr"
TARGET_DIRECTORY = "dist"
os.mkdir(TARGET_DIRECTORY)

with open("translations.csv") as csvfile:
rows = csv.DictReader(csvfile, delimiter=',', quotechar='"')
for row in rows:
if row['day'] not in days:
days[row['day']] = []
days[row['day']].append({k:v for k,v in row.items() if k != 'day'})

for day_id, day in days.items():
svg_filename_pattern = "j{day_id}_{lang}.svg"
svg_filepath = os.path.join("day{day_id}".format(day_id), svg_filename_pattern.format(day_id=day_id, lang=DEFAULT_LANG))
print(svg_filepath)
print(day)
print()

for lang in day:
if lang != "fr":
svg_translated_filepath = os.path.join(TARGET_DIRECTORY, svg_filename_pattern.format(day_id=day_id, lang=lang))
with open(svg_filepath, "r") as fin:
with open(svg_translated_filepath, "w") as fout:
for line in fin:
for day_str in day:
fout.write(line.replace(day_str[DEFAULT_LANG], day_str[lang]))
4 changes: 4 additions & 0 deletions translations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
day,fr,es,it
1,"Tous naissent comme des originaux,",l1,
1,mais beaucoup meurent,l2,
1,comme des photocopies,l3,

0 comments on commit e8bd712

Please sign in to comment.