Code

Applied patches
[gosa.git] / gosa-core / update-locale
index b388bb106435192797651e51cb440db1096b9997..65f4ec9d93a50636d03ece3b7498486dda29bf82 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 generate_po() {
   ORIG=`pwd`
@@ -23,6 +23,12 @@ generate_po() {
     mv $template.new $template
   done
 
+  for template in $(find . -name '*.xml'); do
+    echo "* converting .xml files: $(basename $template)"
+    sed -e 's/<label>/<?php $t= _("/g;s!</label>!");?>!g' $template > $template.new
+    mv $template.new $template
+  done
+
   for class in $(find . -name 'class_*.inc'); do
     echo "* converting class_*.inc files: $(basename $class)"
     sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new
@@ -30,19 +36,31 @@ generate_po() {
   done
 
   echo "Extracting languages..."
-  [ -f locale/messages.po ] && rm locale/messages.po
-  find . -name '*.[ctpi][ophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/messages.po
+  [ -f locale/${l_path}messages.po ] && rm locale/${l_path}messages.po
+  find . -name '*.[ctpix][mophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/${l_path}messages.po
 
   echo "Merging po files with existing ones"
   error=0
-  for f in locale/??/LC_MESSAGES; do
-    [[ "$f" == "locale/??/LC_MESSAGES" ]] && break
+  for f in locale/${l_path}*/LC_MESSAGES; do
+    [[ "$f" == "locale/${l_path}/LC_MESSAGES" ]] && break
     echo -n "* merging $f/messages.po: "
-    [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null
+    [ ! -f $f/messages.po ] && touch $f/messages.po
+
+    # If we're in a plugin of a trunk checkout, we can use the gosa-all messages.po as a dictionary
+    DICT_FILE_ALL="$ORIG/../../gosa-all/gosa/${f/locale/locale/core}/messages.po"
+    DICT_FILE_CORE="$ORIG/../../gosa-core/${f/locale/locale/core}/messages.po"
+    DICT=""
+    [ -r $DICT_FILE_ALL ] && DICT="-C $DICT_FILE_ALL"
+    [ ${#DICT} -eq 0 ] && [ -r $DICT_FILE_CORE ] && DICT="-C $DICT_FILE_CORE"
+    msgmerge $DICT $f/messages.po locale/${l_path}messages.po --output-file=$f/messages.po.tmp &> /dev/null
+
+    # Filter out duplicates
+    msguniq $f/messages.po.tmp --output-file=$f/messages.po.new &> /dev/null
+    rm $f/messages.po.tmp
 
     # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
     if [ $? -ne 0 ]; then
-      [ "$f" == "locale/en/LC_MESSAGES" ] && $TRUE
+      [ "$f" == "locale/${l_path}en/LC_MESSAGES" ] && $TRUE
     fi
 
     if [ $? -eq 0 ]; then
@@ -55,13 +73,13 @@ generate_po() {
   done
 
   echo "Copying new po files, making backups..."
-  find . -name messages.po | while read f; do
+  find locale/${l_path} -name messages.po | while read f; do
 
     if [ -f $ORIG/$f ]; then
       mv $ORIG/$f $ORIG/$f.orig
     fi
 
-    echo $f | grep -q "locale/messages.po"
+    echo $f | grep -q "locale/${l_path}messages.po"
     if [ $? -ne 0 ]; then
       echo "* replaced $ORIG/$f"
       cp $f.new $ORIG/$f
@@ -114,7 +132,6 @@ EOF
 # MAIN
 #
 GENERATE=0
-COMPILE=0
 ASSUME_Y=0
 while getopts ":gyh" opt
 do
@@ -133,8 +150,15 @@ do
 done
 shift $(($OPTIND - 1))
 
+# If there's a plugin.dsc in ., then assume "plugin"
+if [ -f plugin.dsc ]; then
+       l_path=""
+else
+       l_path="core/"
+fi
+
 # Default to generate
-if [ $GENERATE -eq 0 -a $COMPILE -eq 0 ]; then
+if [ $GENERATE -eq 0 ]; then
   GENERATE=1
 fi