From: Marcin Koziej Date: Wed, 1 Feb 2012 13:48:56 +0000 (+0100) Subject: scripts to make localization pack. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/6e295f0db470467f3a3bf9ff46a4ed5e8f052229?ds=sidebyside scripts to make localization pack. --- diff --git a/scripts/make-locale-pack b/scripts/make-locale-pack new file mode 100755 index 000000000..a5bb7d36a --- /dev/null +++ b/scripts/make-locale-pack @@ -0,0 +1,53 @@ +#!/bin/bash + +ME=$0 +ROOT=$(git rev-parse --show-toplevel) +DST=`mktemp -d`/wl-lokalizacja +mkdir -p $DST +MANAGE=$ROOT/wolnelektury/manage.py + + +export_po() +{ + for langdir in $ROOT/wolnelektury/locale/*; do + lang=`basename $langdir` + mkdir -p $DST/$lang + cp -v ${ROOT}/wolnelektury/locale/${lang}/LC_MESSAGES/django.po $DST/${lang}/wolnelektury.po + done + + for appdir in $ROOT/apps/*; do + app=`basename $appdir` + if [ -d $ROOT/apps/$app/locale ]; then + for langdir in $ROOT/apps/$app/locale/*; do + lang=`basename $langdir` + mkdir -p $DST/$lang + cp -v ${ROOT}/apps/${app}/locale/${lang}/LC_MESSAGES/django.po $DST/${lang}/${app}.po + done + fi + done + + cp -v ${ROOT}/wolnelektury/static/js/locale.js $DST/locale.js.txt + cp -v ${ROOT}/apps/infopages/fixtures/infopages.json $DST/infopages.json + + ${0}-json.py $DST/infopages.json +} + + +cd $ROOT/wolnelektury +echo "Generate po for WL" +$MANAGE makemessages --all + +cd $ROOT/apps +for i in *; do + echo "Generate po for app $i" + ( cd $i; $MANAGE makemessages --all; + ) +done + +export_po + +PACK=`pwd`/wl-lokalizacja.zip +( cd $DST; cd ..; zip -r $PACK wl-lokalizacja; ) + +rm -r $DST + diff --git a/scripts/make-locale-pack-json.py b/scripts/make-locale-pack-json.py new file mode 100755 index 000000000..5bd30504a --- /dev/null +++ b/scripts/make-locale-pack-json.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import json +import sys +import os +import shutil + +fname = sys.argv[1] +def mkdir(n): + if not os.path.exists(n): os.mkdir(n) + +dst = os.path.dirname(fname) +name = os.path.basename(fname).split('.')[0] + +dst2 = os.path.join(dst, name) +mkdir(dst2) + +data = json.load(open(fname)) +for ip in data: + dst3 = os.path.join(dst2, ip['fields']['slug']) + mkdir(dst3) + for fld, val in ip['fields'].items(): + if filter(lambda x: fld.startswith(x), + ['title', 'left_column', 'right_column']): + o = open(os.path.join(dst3, fld+".txt"),'w') + try: + o.write(val.encode('utf-8')) + finally: + o.close() +