From c602e245bb19317314793114dec49c5f4994e265 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Mon, 19 Jan 2009 16:34:11 -0500 Subject: Add new genpopo and translation_tool that work with new system. Signed-off-by: Loui Chang --- web/lang/genpopo | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100755 web/lang/genpopo (limited to 'web/lang/genpopo') diff --git a/web/lang/genpopo b/web/lang/genpopo new file mode 100755 index 0000000..66bf9a1 --- /dev/null +++ b/web/lang/genpopo @@ -0,0 +1,170 @@ +#! /usr/bin/python -O +# -*- coding: iso-8859-1 -*- + +# This script iterates through the script directories +# looking for php scripts that contain __() functions. +# It creates/appends to the corresponding +# "xxx.po" file in the 'lang' subdirectory and places the +# i18n strings into the file in the proper format. +# +# usage: genpopo [-v] [-f] +# -v: verbose, print duplicate terms that could be moved to common_po +# -f: force, overwrite existing translated files, otherwise append +# + +import re +import os +import sys + +INC_HEADER = """\ +", "?>\n", "\n?>"]: + del contents[-1] + + f = open(pofile,'w') + f.write("".join(contents)) + f.write("\n"); + f.close() + else: + f = open(pofile,'w') + f.write(INC_HEADER) + f.write('\n') + f.close() + + # Read file contents so we can hash what already exists + try: + f = open(pofile, 'r') + new_file = 0 + except: + new_file = 1 + + existing_terms = [] + if not new_file: + contents = f.readlines() + f.close() + + # Strip beginning/ending empty lines + while contents[0] == '': + del contents[0] + while contents[-1] in ['', "\n", "?>", "?>\n", "\n?>"]: + del contents[-1] + + # Collect existing terms + for line in contents: + match = mapre.search(line) + if match: + existing_terms.append(match.group(1)) + + # Append any new terms to EOF + f = open(pofile, 'w') + if not new_file: + f.write("".join(contents)) + else: + f.write(INC_HEADER) + + for term in lang.keys(): + if term not in existing_terms: + f.write("\n"); + f.write('$_t["%s"]\n = "%s";\n' % (term, term)) + f.write("\n"); + f.close() + -- cgit v1.2.3-70-g09d2