aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/README12
-rw-r--r--tools/translated_converter.py104
2 files changed, 113 insertions, 3 deletions
diff --git a/tools/README b/tools/README
index 453913ddb..9b10f0a8b 100644
--- a/tools/README
+++ b/tools/README
@@ -1,11 +1,17 @@
REBUILDING A GETTEXT DICTIONARIES
-To rebuild a gettext dictionaries you need to run rebuild_gettext_catalogs.sh script in the root of main web server:
+To rebuild a gettext dictionaries and refresing the po files you need to run rebuild_gettext_catalogs.sh script in the root of main web server:
It cals extract2gettext.php for every translatable resource. It picks the database for that from web_projects.dat file.
+Python script translated_converter.py is used in conversion of lang files to gettext po files.
+It comes from http://gitweb.mageia.org/software/i18n/tools/tree/websites where you can find it's license and some other informations.
-LEGACY UTILITY
-There is also useful script lookup_for_second_argument.sh used as a preparation for transition.
+LEGACY UTILITIES
+1. There is also useful script lookup_for_second_argument.sh used as a preparation for transition.
It cals lookup_for_second_argument.php for every translatable resource. It picks the database for that from web_projects.dat file.
+
+2. File extract2lang.php is used for old lang l10n system.
+
+3. In the transition from php arrays to lang l10n system file pa2lang.php was used.
diff --git a/tools/translated_converter.py b/tools/translated_converter.py
new file mode 100644
index 000000000..219781636
--- /dev/null
+++ b/tools/translated_converter.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import errno, glob, polib, re, os, getopt, sys
+from time import strftime
+
+def usage():
+ print '\nUsage: python %s [OPTION]' %os.path.basename(sys.argv[0])
+ print ' generates po file for existing lang translations'
+ print 'Options: -h, --help : usage'
+ print ' -l lang_code, --language lang_code : code of the translation language'
+ sys.exit(2)
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "hl:", ["help", "language="])
+except getopt.GetoptError:
+ usage() # print help information and exit
+
+language=''
+for o,a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ if o in ("-l", "--language"):
+ lang_code=a
+
+if lang_code == '':
+ sys.exit('Empty language code')
+
+file_extension = '.' + lang_code + '.lang'
+file_mask = '*' + file_extension
+for langfile in glob.glob(file_mask):
+ langfilename = langfile.replace(file_extension, '')
+ # Create localization directories if needed
+ podir = langfilename + '/po'
+ try:
+ os.makedirs(podir)
+ except OSError, e:
+ if e.errno != errno.EEXIST:
+ raise
+ #open lang file
+ text = open(langfile,"r").read()
+ #Remove trailing spaces from lines
+ spaces=' {1,}\n'
+ spattern=re.compile(spaces,re.DOTALL)
+ for emptyline in spattern.findall(text):
+ text = text.replace(emptyline,'\n')
+ text = text.replace('\n\n','\n\n\n\n')+'\n'
+
+ # Write PO file
+ po = polib.POFile()
+ pocreationtime = strftime('%Y-%m-%d %H:%M%z')
+ po.metadata = {
+ 'Project-Id-Version': langfile,
+ 'Report-Msgid-Bugs-To': 'mageia-i18n@mageia.org',
+ 'POT-Creation-Date': pocreationtime,
+ 'PO-Revision-Date': pocreationtime,
+ 'Last-Translator': 'Duffy Duck <d_duck@nowhere.net>',
+ 'Language-Team': lang_code + ' <mageia-' + lang_code + '@mageia.org>',
+ 'MIME-Version': '1.0',
+ 'Content-Type': 'text/plain; charset=UTF-8',
+ 'Content-Transfer-Encoding': '8bit',
+ }
+
+ # Parse contents and add them to PO
+ messagetemplate='\n\n#\ .*?\n\n'
+ mpattern=re.compile(messagetemplate,re.DOTALL)
+ for mblock in mpattern.findall(text):
+ mblock_stripped = mblock.strip('\n')
+ message_comment, message_text = mblock.strip('\n').split('\n;',1)
+ # Strip '# ' from comments
+ message_comment = message_comment.lstrip('# ')
+ message_id, message_str = message_text.split('\n',1)
+ # Strip ';' from msgid
+ message_id = message_id.lstrip(';')
+ potentry = polib.POEntry(
+ msgctxt = message_comment,
+ msgid = message_id.decode('utf-8'),
+ msgstr = message_str.decode('utf-8'),
+ occurrences=[(langfile,'')]
+ )
+ po.append(potentry)
+ messagetemplate='\n\n;.*?\n\n'
+ mpattern=re.compile(messagetemplate,re.DOTALL)
+ for mblock in mpattern.findall(text):
+ message_id, message_str = mblock.strip('\n').split('\n',1)
+ # Strip ';' from msgid
+ message_id = message_id.lstrip(';')
+ potentry = polib.POEntry(
+ msgid = message_id.decode('utf-8'),
+ msgstr = message_str.decode('utf-8'),
+ occurrences=[(langfile,'')]
+ )
+ po.append(potentry)
+ if text[0] == ';':
+ message_id, message_str = text.partition('\n\n')[0].strip('\n').split('\n',1)
+ # Strip ';' from msgid
+ message_id = message_id.lstrip(';')
+ potentry = polib.POEntry(
+ msgid = message_id.decode('utf-8'),
+ msgstr = message_str.decode('utf-8'),
+ occurrences=[(langfile,'')]
+ )
+ po.append(potentry)
+ pofilename = langfilename + '/po/' + lang_code + '.po'
+ po.save(pofilename)