Hi Nick, Enrico, Frank,

As I understand it intltool handles config files by creating a C file
with their strings that can be processed with the other code, and then
updates the config files with the translations from the .po files.

Inspired by this here is a 50 line python script to do this for build
menu entries in filetypes files.

run as:
xbuildmenu.py mkc cfile list_of_filetypes_files..

it creates the file cfile as a C file with strings containing all the
build menu labels it finds in the listed filetypes files (filetypes.*
would be good:-)
this cfile can be processed by your translation tools (tested with
xgettext) along with all the other program files to extract strings
for translation.
A good name for cfile might be buildmenutranslate.h

run as:
xbuildmenu.py upd cfile podir

it searches the po files in podir for strings taken from the cfile and
using the information in the structured comments in the cfile copies
the translation back into the filetypes files with a language marker
the same as the po file name, eg de.po gives [de] on the config file
entry.

It should be easy to call this from the waf script since you are
guaranteed that python is available :-).  We are only talking about
the standard filetypes as delivered with the system so there is no
need for users to run this, just run when translations are updated in
svn.

It uses grep to speed its file search by eliminating lots of files (hopefully)

Cheers
Lex

2009/8/26 Lex Trotman <ele...@gmail.com>:
> 2009/8/26 Nick Treleaven <nick.trelea...@btinternet.com>:
>>
>> Yes, but any default string could be added to the codebase for
>> translations, not just compile and build. Assuming it's a 'general'
>> kind of menu label, things which would be useful for several filetypes.
>>
>
> All the strings in the code that appear as labels should already be
> marked for translation, if I missed any thats a bug :-)
>
> There isn't any way of changing the default label string to a
> different default depending on filetype.  The intention is that if you
> want to change a filetype menu label it is configured in the filetypes
> file along with the command and overrides the default.
>
> Let me look at a possible solution in a few days.
>
> Cheers
> Lex
>
>> Regards,
>> Nick
>> _______________________________________________
>> Geany-devel mailing list
>> Geany-devel@uvena.de
>> http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
>>
>
#!/usr/bin/python
# build menu label translation helper

# Usage:
# xbuildmenu mkc cfile filelist...		# create cfile to match [build-menu] sections of files in filelist
# xbuildmenu upd cfile podir			# update config files named in cfile with translations in podir

import os, sys, re, ConfigParser, subprocess, fileinput

if len( sys.argv )<4 :
	print "too few arguments"
	sys.exit( os.EX_USAGE )
if sys.argv[1] == "mkc" :
	keyre = re.compile( r"(FT|NF|EX)_\d\d_LB$")
	f = open( sys.argv[2], "w" )
	f.write( "/* build-menu translations file, do not edit */\n#define _(String) String\n" );
	for ft in sys.argv[3:] :
		print ft
		cf = ConfigParser.RawConfigParser(); cf.optionxform = str
		cf.read(ft)
		print cf.options("build-menu")
		for bl in [ x for x in cf.options( "build-menu" ) if keyre.search( x ) ] :
			f.write("/*X"+ft+"*/ const char *"+bl+"= gettext (\""+cf.get("build-menu", bl)+"\");\n" )
	f.close()
elif sys.argv[1] == "upd":
	filere = re.compile( sys.argv[2]+r":(\d+)" )
	msgre = re.compile( "msgstr \"([^\"]+)\"" )
	fl = 1; ln = -1
	list = []
	for po in subprocess.Popen("grep -l \""+sys.argv[2]+"\" "+sys.argv[3]+"/*.po", stdout=subprocess.PIPE, shell=True).communicate()[0].splitlines() :
		lang = os.path.splitext( os.path.basename( po ) )[0]
		for line in fileinput.input(po) :
			mo = filere.search( line )
			if mo :	ln = int(mo.group(1))
			msg = msgre.search( line )
			if msg and ln >= 0:
				list.append( (ln, lang, msg.group(1)) )
				ln = -1
	list.sort( key=lambda x: x[0] ); list.append( (sys.maxint, "", "") )
	ln = 0; li = 0
	linere = re.compile( r"/\*X([^\*]+)\*/ const char \*([^=]+)=" )
	for line in fileinput.input(sys.argv[2]) :
		ln += 1
		while list[li][0]<ln : li += 1
		if ln == list[li][0] :
			mo = linere.match( line )
			if mo :
				cf = ConfigParser.RawConfigParser(); cf.optionxform = str
				cf.read( mo.group(1) )
				cf.set( "build-menu", mo.group(2)+"["+list[li][1]+"]", list[li][2] )
				cff = open( mo.group(1), "wb" ); cf.write( cff ); cff.close()
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to