[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Splitting D-I translation in "sublevels": ready infrastructure



On Wednesday 09 January 2008, Christian Perrier wrote:
> Quoting Frans Pop (elendil@planet.nl):
> > I have done some first testing with the new script and committed some
> > changes. Please check them (preferably before the next l10n-sync run
> > :-).
>
> I won't have time for this. So if you have some doubts, better
> de-activate the l10n-sync runs....

Nah, we'll just let things crash [1] ;-)

> > For example, I have doubts that an existing translation would in all
> > cases survive a change in the sublevel of a string.
> > The solution could be to:
> > 1) merge all sublevel PO files into a temporary master PO file
>
> That's already done in the script, IIRC.

Yes, but only after the updates have already been done.

> > 2) update that against the grand master POT file
> > 3) merge that against the sublevel POT files to split it
>
> That seems an interesting idea, yes.

OK. Attached a "proof of concept" patch that roughly implements this. It's 
missing some debug logging support and some other minor details, but I've 
tested with it and it should work.
For now I'm mostly interested in discussion of the issues I mention in the 
comments in the big new section (which basically replaces the old section 
that follows it).

The main problems I see ATM (but these exist in your code too) is:
- keeping correct PO-Revision-Date headers
- attributing updates done in sublevels to the correct translator in
  changelogs

The way I have tested this is:
   cd packages/po
   svn revert -R
   for i in 3 4 5; do mkdir sublevel$i; done
   rm sublevel*/*.po
   cp *.po sublevel1/
And then, for the first run only, comment out the "if" statement as 
indicated in the comment in the new section (only the if and fi statements, 
not the code between them). This will magically create PO files for all 
translations for all levels.

> > General question. Should the ATOMIC_COMMITS option maybe just be
> > dropped? I'm not sure why you'd want to use it and dropping it would
> > significantly improve the readability of the code.
>
> So, I agree that it can be dropped, yes.

Done and committed.

Cheers,
FJP

[1] Translates to: I don't expect problems, but will check the commits.

Index: l10n-sync
===================================================================
--- l10n-sync	(revision 50809)
+++ l10n-sync	(working copy)
@@ -449,6 +449,83 @@
 	sed -i 's/charset=UTF-8/charset=CHARSET/g' ${DI_COPY}/packages/po/template.pot
 fi
 
+# Update PO files for sublevels:
+# 3a) Synchronize with D-I SVN
+# 3b) Merge the sublevel PO files into a master PO file
+# 3c) Update the master PO file from the master POT file as it will be used
+#     to update package PO files
+# 3d) Update the sublevel PO files from this master PO file and the sublevel POT file
+# 3e) commit back the changed file
+if [ "$WITHLEVELS" = "Y" ] ; then
+	cd $DI_COPY/packages/po
+	languages=""
+	for po in sublevel1/*.po ; do
+		lang=$(basename $po .po)
+		#[ $lang = nl ] || continue
+		if [ "$DEBUG" = "Y" ] ; then
+			echo "   $lang:"
+		fi
+		if ([ -r PROSPECTIVE ] && \
+		    ! grep -q "^$lang[[:space:]]*$" PROSPECTIVE) || \
+		   [ ! -r PROSPECTIVE ]; then
+			languages="${languages:+$languages $lang}"
+		fi
+
+		echo "     - Merge sublevel PO files into master PO file and update:"
+		list=""
+		# FJP: Why was this being done in reverse order?
+		for i in `seq 1 $NUMLEVELS`; do
+			if [ -f sublevel${i}/${lang}.po ]; then
+				list="$list sublevel${i}/${lang}.po"
+			fi
+		done
+		# We need the date of the last update of a sublevel PO file
+		# Preferably we should also determine the name of the person who
+		# did the last update to a sublevel (for changelogs)
+		LASTDATE="$(
+			for j in ${list}; do
+				date -ud "$(grep "PO-Revision-Date:" $j | \
+				sed 's/^.*: \(.*\)\\n.*$/\1/')" "+%F %R%z"
+			done | sort | tail -n 1)"
+		msgcat --use-first $list | \
+			sed "s/^.*PO-Revision-Date:.*$/\"PO-Revision-Date: $LASTDATE\\\n\"/" \
+			>${lang}.po
+		# Update the master PO file (as it's used to update package PO files)
+		if ! msgmerge --previous ${lang}.po template.pot >${lang}.po.new ; then
+			gettexterr
+		fi
+		msgattrib --width=79 --no-obsolete ${lang}.po.new >${lang}.po
+		rm ${lang}.po.new
+
+		# When updating a sublevel PO file, we should really retain
+		# all the old headers and only update the POT-Creation-Date...
+		for i in `seq 1 $NUMLEVELS`; do
+			# For the initial conversion from no sublevels:
+			# 'cp *.po sublevel1/' and comment out this if statement
+			if [ -f sublevel${i}/${lang}.po ]; then
+				echo "     - Merge with template.pot for sublevel $i:"
+				if ! msgmerge --previous ${lang}.po sublevel${i}/template.pot >sublevel${i}/${lang}.po.new ; then
+					gettexterr
+				fi
+				# Do we really want to loose obsolete strings?
+				# Shouldn't that be up to the translator?
+				msgattrib --width=79 --no-obsolete sublevel${i}/${lang}.po.new >sublevel${i}/${lang}.po
+				rm sublevel${i}/${lang}.po.new
+			fi
+		done
+	done
+
+	if [ "$COMMIT" = "Y" ] ; then
+		if [ "$DEBUG" = "Y" ] ; then
+			echo -n "Commit all general PO/POT files to SVN..."
+		fi
+		$svn commit -m"${COMMIT_MARKER} Updated packages/po/* against package templates" || svnerr
+		if [ "$DEBUG" = "Y" ] ; then
+			echo Done.
+		fi
+	fi
+fi
+
 # For each PO file in packages/po/sublevel* or packages/po:
 # 3a) Synchronize with D-I SVN
 # 3b) Update with template.pot
@@ -456,6 +533,8 @@
 # 3d) commit back the changed file
 for i in $LEVELS; do
 	if [ "$WITHLEVELS" = "Y" ] ; then
+		# Bail out; work has already been done in previous section
+		break
 		dir=po/sublevel$i
 		level="level $i "
 	else
@@ -582,23 +661,6 @@
 	fi
 done
 
-# If we use levels, create a temporary general file
-# (which we won't commit) to make merging in individual packages
-# much faster
-if [ "$WITHLEVELS" = "Y" ] ; then
-	cd $DI_COPY/packages/po
-	for po in sublevel1/*.po ; do
-		lang=$(basename $po .po)
-		list=""
-		for i in `seq $NUMLEVELS -1 1`; do
-			if [ -f sublevel${i}/${lang}.po ]; then
-				list="$list sublevel${i}/${lang}.po"
-			fi
-		done
-		msgcat --use-first $list >${lang}.po
-	done
-fi
-
 # Loop over D-I packages:
 # 4a) synchronize the local copy with the D-I SVN 
 # 4b) update debian/po/*.po files with files in packages/po/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: