scripts to make localization pack.
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Wed, 1 Feb 2012 13:48:56 +0000 (14:48 +0100)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Wed, 1 Feb 2012 13:48:56 +0000 (14:48 +0100)
scripts/make-locale-pack [new file with mode: 0755]
scripts/make-locale-pack-json.py [new file with mode: 0755]

diff --git a/scripts/make-locale-pack b/scripts/make-locale-pack
new file mode 100755 (executable)
index 0000000..a5bb7d3
--- /dev/null
@@ -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 (executable)
index 0000000..5bd3050
--- /dev/null
@@ -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()
+