[Kstars-devel] [kstars] kstars: Adding python script to extract city name, province, and country from the city.sqlite database. Modifying Messages.sh to process this data and also using xi18n instead of i18n. I had to pass some arguments to xgettext to get it working properly and now it produces the

Jasem Mutlaq mutlaqja at ikarustech.com
Mon Jan 26 07:30:08 UTC 2015


Git commit da137980937f70261328fea82fee1635e6926404 by Jasem Mutlaq.
Committed on 26/01/2015 at 07:11.
Pushed by mutlaqja into branch 'master'.

Adding python script to extract city name, province, and country from the city.sqlite database. Modifying Messages.sh to process this data and also using xi18n instead of i18n. I had to pass some arguments to xgettext to get it working properly and now it produces the
expected .pot file. Needs more testing.

CCMAIL:kstars-devel at kde.org
CCMAIL:aacid at kde.org
CCMAIL:yurchor at ukr.net

M  +12   -27   kstars/Messages.sh
A  +29   -0    kstars/data/scripts/extract_geo_data.py

http://commits.kde.org/kstars/da137980937f70261328fea82fee1635e6926404

diff --git a/kstars/Messages.sh b/kstars/Messages.sh
index 08df004..c872b2a 100644
--- a/kstars/Messages.sh
+++ b/kstars/Messages.sh
@@ -13,39 +13,26 @@ echo "#if 0" >> kstars_i18n.cpp
 
 # extract constellations
 sed -e "s/\([0-9].*[a-z]\)//" < data/cnames.dat | sed 's/^[A-B] //' | \
-   sed 's/\([A-Z].*\)/i18nc("Constellation name (optional)", "\1");/' | sed 's/\ "/"/g' >> "kstars_i18n.cpp"
+   sed 's/\([A-Z].*\)/xi18nc("Constellation name (optional)", "\1");/' | sed 's/\ "/"/g' >> "kstars_i18n.cpp"
 
 # extract sky cultures
-grep ^C data/cnames.dat | awk '{ print "i18nc( \"Sky Culture\", \"" $2 "\" );" }' >> "kstars_i18n.cpp"
+grep ^C data/cnames.dat | awk '{ print "xi18nc( \"Sky Culture\", \"" $2 "\" );" }' >> "kstars_i18n.cpp"
 
-# extract cities
-awk 'BEGIN {FS=":"}; {print "\"" $2 ":" $3 ":" $1 "\""; }' < data/Cities.dat | \
-   sed 's/ *:/:/g' | \
-   sed 's/ *\"$/\");/g' | sed 's/^\" */i18nc(\"City in /' | sed 's/ *: */ /' | sed 's/ *: */\",\"/' | sed 's/i18nc(.*,"");//' >> "cities.tmp"
-sort --unique cities.tmp >> kstars_i18n.cpp
-
-# extract regions
-awk 'BEGIN {FS=":"}; {print "\"" $3 ":" $2 "\""; }' < data/Cities.dat | \
-   sed 's/ *\"$/\");/g' | sed 's/^\" */i18nc(\"Region\/state in /' | sed 's/ *: */\",\"/g' | sed 's/i18nc(.*,"");//' >> "regions.tmp";
-sort --unique regions.tmp >> kstars_i18n.cpp
-
-# extract countries
-awk 'BEGIN {FS=":"}; {print "\"" $3 "\""; }' < data/Cities.dat | \
-   sed 's/ *\"$/\");/g' | sed 's/^\" */i18nc(\"Country name\",\"/g' | sed 's/i18nc(.*,"");//' >> "countries.tmp"
-sort --unique countries.tmp >> kstars_i18n.cpp
+# City data (name, province, country)
+python data/scripts/extract_geo_data.py >> "kstars_i18n.cpp"
 
 # extract image/info menu items
-awk 'BEGIN {FS=":"}; (NF==4 && $3~"http") {gsub(/\"/, "\\\""); print "i18nc(\"Image/info menu item (should be translated)\",\"" $2 "\");"; }' < data/image_url.dat | sed 's/i18nc(.*,"");//' >> "image_url.tmp"
+awk 'BEGIN {FS=":"}; (NF==4 && $3~"http") {gsub(/\"/, "\\\""); print "xi18nc(\"Image/info menu item (should be translated)\",\"" $2 "\");"; }' < data/image_url.dat | sed 's/xi18nc(.*,"");//' >> "image_url.tmp"
 sort --unique image_url.tmp >> kstars_i18n.cpp
-awk 'BEGIN {FS=":"}; (NF==4 && $3~"http") {gsub(/\"/, "\\\""); print "i18nc(\"Image/info menu item (should be translated)\",\"" $2 "\");"; }' < data/info_url.dat | sed 's/i18nc(.*,"");//' >> "info_url.tmp"
+awk 'BEGIN {FS=":"}; (NF==4 && $3~"http") {gsub(/\"/, "\\\""); print "xi18nc(\"Image/info menu item (should be translated)\",\"" $2 "\");"; }' < data/info_url.dat | sed 's/xi18nc(.*,"");//' >> "info_url.tmp"
 sort --unique info_url.tmp >> kstars_i18n.cpp
 
 # star names : some might be different in other languages, or they might have to be adapted to non-Latin alphabets
 # TODO: Move this thing to starnames.dat
-cat data/stars.dat | gawk 'BEGIN { FS=", "; } ($1!~/\#/ && NF==3) { printf( "i18nc(\"star name\", \"%s\");\n", $3); }' >> kstars_i18n.cpp;
+cat data/stars.dat | gawk 'BEGIN { FS=", "; } ($1!~/\#/ && NF==3) { printf( "xi18nc(\"star name\", \"%s\");\n", $3); }' >> kstars_i18n.cpp;
 
 # extract satellite group names
-cat data/satellites.dat | gawk 'BEGIN {FS=";"} ($1!~/\#/) { printf( "i18nc(\"Satellite group name\", \"%s\");\n", $1); }' >> kstars_i18n.cpp;
+cat data/satellites.dat | gawk 'BEGIN {FS=";"} ($1!~/\#/) { printf( "xi18nc(\"Satellite group name\", \"%s\");\n", $1); }' >> kstars_i18n.cpp;
 
 # extract deep-sky object names (sorry, I don't know perl-fu ;( ...using AWK )
 cat data/ngcic.dat | grep -v '^#' | gawk '{ split(substr( $0, 77 ), name, " "); \
@@ -53,26 +40,24 @@ if ( name[1]!="" ) { \
 printf( "%s", name[1] ); i=2; \
 while( name[i]!="" ) { printf( " %s", name[i] ); i++; } \
 printf( "\n" ); } }' | sort --unique | gawk '{ \
-printf( "i18nc(\"object name (optional)\", \"%s\");\n", $0 ); }' >> kstars_i18n.cpp
+printf( "xi18nc(\"object name (optional)\", \"%s\");\n", $0 ); }' >> kstars_i18n.cpp
 
 # extract strings from file containing advanced URLs:
 cat data/advinterface.dat | gawk '( match( $0, "KSLABEL" ) ) { \
 name=substr($0,10); \
-printf( "i18nc(\"Advanced URLs: description or category\", \"%s\")\n", name ); }' >> kstars_i18n.cpp
+printf( "xi18nc(\"Advanced URLs: description or category\", \"%s\")\n", name ); }' >> kstars_i18n.cpp
 
 # finish file
 echo "#endif" >> kstars_i18n.cpp
 # cleanup temporary files
-rm -f cities.tmp
-rm -f regions.tmp
-rm -f countries.tmp
 rm -f image_url.tmp
 rm -f info_url.tmp
 rm -f tips.cpp
 
 $EXTRACTRC `find . -name '*.ui' -o -name '*.rc' -o -name '*.kcfg' | sort` >> rc.cpp || exit 11
 (cd data && $PREPARETIPS > ../tips.cpp)
-$XGETTEXT `find . -name '*.cpp' -o -name '*.h' -o -name '*.qml' | sort` -o $podir/kstars.pot
+$XGETTEXT -C --qt --from-code=UTF-8 --keyword=xi18n --keyword=xi18nc:1c,2 `find . -name '*.cpp' -o -name '*.h' -o -name '*.qml' | sort` -o $podir/kstars.pot
 rm -f tips.cpp
 rm -f kstars_i18n.cpp
 rm -f rc.cpp
+
diff --git a/kstars/data/scripts/extract_geo_data.py b/kstars/data/scripts/extract_geo_data.py
new file mode 100644
index 0000000..69cf5a4
--- /dev/null
+++ b/kstars/data/scripts/extract_geo_data.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sqlite3
+
+db = sqlite3.connect("data/citydb.sqlite")
+db.text_factory = str
+
+cursor = db.cursor()
+
+cursor.execute('''SELECT DISTINCT Name from city''')
+all_rows = cursor.fetchall()
+all_rows.sort()
+for row in all_rows:  
+  print('xi18nc("City name (optional, probably does not need a translation)", "{0}")'.format(row[0]))
+
+cursor.execute('''SELECT DISTINCT Province from city''')
+all_rows = cursor.fetchall()
+all_rows.sort()
+for row in all_rows:  
+  print('xi18nc("Province name (optional, rarely needs a translation)", "{0}")'.format(row[0]))
+
+cursor.execute('''SELECT DISTINCT Country from city''')
+all_rows = cursor.fetchall()
+all_rows.sort()
+for row in all_rows:  
+  print('xi18nc("Country name (optional, but should be translated)", "{0}")'.format(row[0]))
+
+db.close()
\ No newline at end of file


More information about the Kstars-devel mailing list