moved code of scripts/revert_unchanged_po_files.py to scripts/update_po_files.py

minor improvements of po file handling
This commit is contained in:
lars 2007-03-21 18:31:19 +00:00
parent f237d0c565
commit 136d8a8bf3
4 changed files with 59 additions and 24 deletions

View file

@ -1,15 +0,0 @@
#!/bin/sh
#
# run this script whenever you used update_po_files.sh to remove all changes of files.
# It reverts all po-files where just the POT-Creation-Date header line was changed (not new translations)
#
BASE_DIR=$(cd $(dirname "$0")/..; pwd)
cd "$BASE_DIR"
svn stat intl plugins | grep "\.po$" | cut -d " " -f 2- | while read po_file
do test -z "$(svn diff $po_file)" && continue
diff=$(svn diff "$po_file" | grep "^\+" | grep -v "^\+\{3\}" | grep -v "POT-Creation-Date")
test -z "$diff" && svn revert "$po_file"
done

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2006 sense.lab e.V.
# Copyright 2006-2007 sense.lab e.V. <info@senselab.org>
#
# This file is part of the CryptoBox.
#
@ -10,6 +10,9 @@
# respective msgid.
# All resulting po files are chmod'ed to 0666 - this is useful if you locally use
# services like pootle.
# If there were no changes besides the "POT-Creation-Date" header, then the file
# is reverted via svn to avoid unnecessary commits.
#
#
# The CryptoBox is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -43,6 +46,14 @@ except ImportError, errMsg:
sys.stderr.write("Please install the appropriate files - for debian just do 'apt-get install python-clearsilver'.\n")
sys.stderr.write("\tOriginal error message: %s\n\n" % errMsg)
sys.exit(1)
try:
import subprocess
except ImportError, errMsg:
sys.stderr.write("Failed to import the python module 'subprocess'!\n")
sys.stderr.write("Please install python v2.4 or higher.\n")
sys.stderr.write("\tOriginal error message: %s\n\n" % errMsg)
sys.exit(1)
LANGUAGE_FILE = 'language.hdf'
## name of the main domain and prefix for all plugin domains
@ -56,9 +67,38 @@ MAIL_ADDRESS = 'info@cryptobox.org'
#ALL_LANGUAGES = "af aka am ar bn ca cs da de el en es et eu fa fi fr fur gl he hi hr hu hy is it ja ka kg ko ku lt lv mr ms mt nb ne nl nn ns pa pl pt ru sl sr st sv tr uk ve vi xh".split(" ")
ALL_LANGUAGES = "cs da de en es fi fr hu it ja nl pl pt ru sl sv ur".split(" ")
# --------------=-=-=- functions -=-=-=--------------------
def revert_if_unchanged(po_file):
try:
proc = subprocess.Popen(
shell = False,
stdout = subprocess.PIPE,
args = [ "svn", "diff", po_file ] )
except OSError, err_msg:
sys.stderr.write("Failed to execute subversion's diff: %s\n" % err_msg)
return
(stdout, stderr) = proc.communicate()
if proc.returncode != 0:
sys.stderr.write("Subversion returned an error: %d\n" % proc.returncode)
return
## no changes at all?
if not stdout:
return
lines = [ l for l in stdout.splitlines()
if ((l.find("POT-Creation-Date:") < 0 ) and \
((l.startswith("+") and (not l.startswith("+++"))) or \
(l.startswith("-") and (not l.startswith("---"))))) ]
## are there relevant changes? then we should not revert ...
if lines:
return
## revert to previous state
proc = subprocess.Popen(
shell = False,
args = [ "svn", "revert", po_file ] )
proc.wait()
def process_language_file(hdf_file, po_dir, textDomain):
## prepare hdf
if not os.path.isfile(hdf_file) or not os.access(hdf_file, os.R_OK):
@ -74,7 +114,7 @@ def process_language_file(hdf_file, po_dir, textDomain):
sys.stdout.write("Creating: %s\n" % pot_file)
pot = translate.storage.po.pofile(encoding="utf-8")
pot.makeheader(pot_creation_date=True)
pot.updateheader(add=True, Project_Id_Version='CryptoBox-Server 0.3', pot_creation_date=True, language_team='sense.lab <devel@senselab.org>', Report_Msgid_Bugs_To=MAIL_ADDRESS, encoding='utf-8', Plural_Forms=['nplurals=2','plural=(n != 1)'])
pot.updateheader(add=True, Project_Id_Version='CryptoBox-Server 0.3', pot_creation_date=True, language_team='sense.lab <%s>' % MAIL_ADDRESS, Report_Msgid_Bugs_To=MAIL_ADDRESS, encoding='utf-8', Plural_Forms=['nplurals=2','plural=(n != 1)'])
#TODO: somehow we need 'updateheaderplural'
else:
sys.stdout.write("Loading: %s\n" % pot_file)
@ -115,7 +155,8 @@ def process_language_file(hdf_file, po_dir, textDomain):
pot.savefile(pot_file)
p = translate.storage.po.pofile(pot_file)
for ld in ALL_LANGUAGES:
if not os.path.isdir(os.path.join(po_dir,ld)): os.mkdir(os.path.join(po_dir, ld))
if not os.path.isdir(os.path.join(po_dir,ld)):
os.mkdir(os.path.join(po_dir, ld))
po_file = os.path.join(po_dir, ld, "%s.po" % textDomain)
if not os.path.isfile(po_file):
translate.convert.pot2po.convertpot(file(pot_file), file(po_file,'w'), None)
@ -128,12 +169,15 @@ def process_language_file(hdf_file, po_dir, textDomain):
po_data = translate.storage.po.pofile.parsefile(po_file)
for po_unit in po_data.units:
po_unit.settarget(po_unit.getsource())
po_data.removeduplicates()
po_data.removeblanks()
po_data.savefile(po_file)
else:
po_content = translate.storage.po.pofile.parsefile(po_file)
po_content.removeduplicates()
po_content.removeblanks()
po_content.savefile(po_file)
revert_if_unchanged(po_file)
## make it writeable for pootle
os.chmod(po_file, 0666)
## compile po file
@ -151,9 +195,15 @@ if __name__ == "__main__":
## the project directory is the parent of the directory of this script
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),os.path.pardir))
process_language_file(os.path.join(PROJECT_DIR,'templates',LANGUAGE_FILE), os.path.join(PROJECT_DIR,LANG_DIR), GETTEXT_DOMAIN)
process_language_file(
os.path.join(PROJECT_DIR, 'templates', LANGUAGE_FILE),
os.path.join(PROJECT_DIR, LANG_DIR),
GETTEXT_DOMAIN)
for root,dirs,files in os.walk(os.path.join(PROJECT_DIR,'plugins')):
for root, dirs, files in os.walk(os.path.join(PROJECT_DIR, 'plugins')):
if LANGUAGE_FILE in files:
process_language_file(os.path.join(root,LANGUAGE_FILE), os.path.join(root,LANG_DIR), "%s-feature-%s" % (GETTEXT_DOMAIN,os.path.basename(root)))
process_language_file(
os.path.join(root,LANGUAGE_FILE),
os.path.join(root,LANG_DIR),
"%s-feature-%s" % (GETTEXT_DOMAIN,os.path.basename(root)))

View file

@ -25,7 +25,7 @@ Attributes:
2) adding a new language
- add the language code (e.g. "de") to the ALL_LANGUAGES setting in
scripts/update_po_files.py
- run "scripts/update_po_files.py && scripts/revert_unchanged_po_files.sh"
- run "scripts/update_po_files.py"
- svn add plugins/*/intl/NEW_LANG_CODE intl/NEW_LANG_CODE
- svn revert plugins/*/intl/NEW_LANG_CODE/*.mo intl/NEW_LANG_CODE/*.mo
- svn propset svn:ignore "*.mo" plugins/*/intl/NEW_LANG_CODE intl/NEW_LANG_CODE

View file

@ -4,7 +4,7 @@ new version.
1) day-to-day commits:
The usual steps before commit:
- scripts/update_po_files.py && scripts/revert_unchanged_po_files.sh
- scripts/update_po_files.py
- run unittests:
- bin/uml-setup.py
- log into uml