~widelands-dev/widelands/mines-worldsavior

« back to all changes in this revision

Viewing changes to utils/buildlocale.py

  • Committer: bedouin
  • Date: 2007-04-06 20:47:45 UTC
  • Revision ID: git-v1:d501938bea38e7cb83c50468b1f3897a61295b97
- patch by Antonio Trueba: improve locale handling for coders and translators
  alike:
  * reorganize: translations are in directory ./po
                compiled locales are in directory ./locale
  * locales now use two scripts: buildlocale and buildcat
  * let the code look in the right places again
- automatically build the locales after release builds and before scons install,
  but not with debug builds
- correctly handle the new locations in scons install and scons dist
- reenable tags to be built after every compile


git-svn-id: https://widelands.svn.sourceforge.net/svnroot/widelands/trunk@2201 37b2a8de-5219-0410-9f54-a31bc463ab9c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -tt
 
2
 
 
3
##############################################################################
 
4
#
 
5
# This script compiles all .po files available for the languages specified
 
6
# in the command line, or all available if none is specified.
 
7
#
 
8
# Usage: assumes to be called from base directory, and that every argument 
 
9
# passed is a language code to compile. If no argument is passed, will compile
 
10
# every .po file found in po/ directories looking like ISO-639 language codes
 
11
#
 
12
##############################################################################
 
13
 
 
14
import buildcat
 
15
import os
 
16
import sys
 
17
import string
 
18
 
 
19
 
 
20
##############################################################################
 
21
#
 
22
# Merge & compile every .po file found in 'po/lang' directory
 
23
#
 
24
##############################################################################
 
25
def do_compile(lang):
 
26
                sys.stdout.write("\t%s:\t" % lang)
 
27
 
 
28
                for f in buildcat.do_find_files(("po/%s" % lang), ".*\.po$"):
 
29
                                # File names and paths to use
 
30
                                po = ("po/%s%s" % (lang, f))
 
31
                                pot = ("po/pot%st" % f)
 
32
                                mo = ("locale/%s/LC_MESSAGES%s" % (lang,
 
33
                                                string.replace(f, ".po", ".mo")))
 
34
                                
 
35
                                if not buildcat.do_buildpo(po, pot, "tmp.po"):
 
36
                                                buildcat.do_makedirs(os.path.dirname(mo))
 
37
                                                if not (os.system("msgfmt -o %s tmp.po" % mo)):
 
38
                                                                os.remove("tmp.po")
 
39
                                                                sys.stdout.write(".")
 
40
                                                                sys.stdout.flush()
 
41
 
 
42
                sys.stdout.write("\n")
 
43
 
 
44
 
 
45
##############################################################################
 
46
#
 
47
# Compile new translations from existing translations and freshly created .pot
 
48
# catalogs.
 
49
#
 
50
##############################################################################
 
51
if __name__ == "__main__":
 
52
                # Sanity checks
 
53
                buildcat.do_check_root()
 
54
 
 
55
                # Make sure .pot files are up to date.
 
56
                buildcat.do_update_potfiles()
 
57
 
 
58
                sys.stdout.write("Compiling translations: ")
 
59
 
 
60
                if len(sys.argv) > 1:
 
61
                                # Assume all parameters are language codes to compile
 
62
                                lang = sys.argv[1:]
 
63
                                print lang
 
64
                else:
 
65
                                # Find every directory that looks like ISO-639 
 
66
                                lang = buildcat.do_find_dirs("po", buildcat.RE_ISO639)
 
67
                                print "all available."
 
68
 
 
69
                for l in lang:
 
70
                                do_compile(l)
 
71
 
 
72
                print("")