Skip to content

OGo Docs

Sections
Personal tools
You are here: Home » Members » sasepp's Home » Bash scripts for raw OGo translation work

Bash scripts for raw OGo translation work

Document Actions
This page contains various scripts that make translating OGo quite a lot easier. See the script comments for more information.

ogo_check_untranslated


#!/bin/bash
#
# ogo_check_untranslated
#
# Compare translated strings to the comment lines that were created before. Any untranslated strings pop up.

echo 
echo "----------------------------------------------------------"
echo "TIEDOSTO:" $1
echo "----------------------------------------------------------"

cat $1 | while read line; do
	
		if [ ${#line} -ge 2 ]; then
			translated=$(echo $line |tr -s " "|cut -d "\"" -f 2)		
			untranslated=$(echo $line|tr -s " "|cut -d "\"" -f 4)
		
			if [ "$translated" == "$untranslated" ]; then
				echo "----------"			
				echo $line
				(( COUNTER = COUNTER + 1 ))
				echo $COUNTER
			fi
		fi
done

ogo_linecount

#!/bin/bash
#
# ogo_linecount
#
# This script compares the translated files with english originals. Used when for some reason
# translated files get broken. Shows the files side by side.

function countlines {
	echo "Processing directory "$2/$1
	cd $2
	for i in `ls $1/*.strings`
	do
		LINECOUNT=$(wc --lines $i)	
		echo $LINECOUNT >> /tmp/$1.tmp	
	done
}

BASEDIR=/home/falchion/usbstick/tietoteema/ogo
DIR1=Finnish.lproj
DIR2=English.lproj

countlines $DIR1 $BASEDIR
countlines $DIR2 $BASEDIR
echo 
paste /tmp/$DIR1.tmp /tmp/$DIR2.tmp
rm -f /tmp/$DIR1.tmp /tmp/$DIR2.tmp

ogo_replace

#!/bin/bash
#
# ogo_replace
#
# This is the main tool for translating OpenGroupware.org. This tool depends on GNU sed, and
# will not work if sed is broken. There are a couple of safeguards that make it harder to break
# things unintentionally.
#
# This script expects to find lines like the one below:
#
# archive = "arkistoitu"; //  "archived";
#         --------------
#
# It will match the underlined part of the line, and will not modify anything except the translated
# string.
#
# In order to use this script, change the WORKDIR variable to your language project's dir and do a
#
# ogo-replace "english_string" "translated_string"
#
# If you want to see how you have usually translated something, do a
#
# ogo-replace "search_string"
#

WORKDIR="/home/falchion/usbstick/tietoteema/ogo/Finnish.lproj"
cd $WORKDIR

# Parse command line arguments

if test -z "$1" && test -z "$2"; then
	echo "Usage: ogo-replace english_string translated_string"
	exit
elif test -z "$2"; then
	echo "Searching for: "\"$1\"
	grep -i "$1" *.strings
	exit
else
	echo "Replacing: "\"$1\"
	echo "with: "\"$2\"
	echo
fi

for i in *.strings;
do
	echo "----------------------"
	echo "Checking file "$i
	export i

# Check if we find the string from this file

grep " = \"$1\"" $i >/dev/null 2>&1
	if [ $? -eq 0 ]; then
			# If the string is found, sed it and ask what to do

			sed s/" = \"$1\""/" = \"$2\""/1 $i > $i.new
			echo
			echo "OLD, LINES "$(wc --lines $i|cut -d " " -f 1)
			grep " = \"$1\"" $i
			echo	
			echo "NEW, LINES "$(wc --lines $i.new|cut -d " " -f 1)
			grep " = \"$2\"" $i.new		
			echo

			echo "Apply modification? (y/n)"
			read ke
			
			
			if [ "$ke" = "y" ]; then
				cp $i $i~
				cp -v $i.new $i
				rm $i.new		
				echo
			else			
				rm $i.new
			fi
	fi
done
echo
echo "Done"

ogo_run

#!/bin/bash
#
# ogo_run
#
# Skripti käy OGO:n lproj -hakemiston tiedostot yksi kerrallaan lävitse
# ogo-strings -ohjelmalla
#
# This script runs the "ogo-strings" script on all translation project files. After running
# this you'll end up with new translation files which have the original english strings
# after each line in comments. This in turn makes consistent translations so much easier to
# achieve.

DIR1=Finnish.lproj
DIR2=English.lproj
RESULTDIR=/tmp/ogo


for i in `ls $DIR1/*.strings`
do
	BASENAME=$(echo $i|cut -d "/" -f 2)
	./ogo-strings $DIR1/$BASENAME $DIR2/$BASENAME $RESULTDIR/$BASENAME

done

ogo-strings

#!/bin/bash
#
# ogo-strings
#
# This script will parse the english translation files and add the original strings to each line in comments.
# This means that it is _much_ easier to know what the term is that you are currently translating.
#
# The reason why this script looks overly complex is that I had to start working on a partially translated *.lproj
# files. That's why this script requires two language project files as arguments: one is the (already) translated file
# and the other is the file with the original english strings.
#
# Use "ogo-run" to run this script on all translation files at once.
# 
# Usage
#
# First parameter = $1 (the file with translations)
# Second parameter = $2 (the file with english originals)
# Tallennustiedosto = $3 (the file with the combined files)
#
# For example: ./ogo-strings "Finnish.lproj/OGoProject.strings" "English.lproj/OGoProject.strings" "/tmp/OGoProject.strings"
#
# or if you start from english originals:
# 
# ./ogo-strings "English.lproj/OGoProject.strings" "English.lproj/OGoProject.strings" "/tmp/OGoProject.strings


echo "1. file: "$1
echo "2. file: "$2
echo "Result file: "$3

# Parse file $1 line by line and check if the variable can be found from the english original

cat $1 | while read line; do

	# Grab the variable
         key=$(echo $line | tr -s " "|cut -d "=" -f 1|cut -d " " -f 1)

	# If the variable is not null (=empty line), continue

	 if [ ${#key} -gt 1 ]; then

		# Check if the same variable is found from the file with english originals ($2)
		 grep "^$key[[:space:]]\+" $2 >/dev/null 2>&1

		# If the variable is found, continue
		 if [ $? -eq 0 ];  then
		 
		# Create the new line and append it to the result file ($3)

		  echo $line" // "$(grep "^$key[[:space:]]\+" $2|tr -s " "|cut -d "=" -f 2) >> $3
       fi
	fi
done

ogo-validation

#!/bin/bash
#
# ogo-validation
#
# This script will check if the translation project files in the _current directory_ contain any syntax errors
# Note that the script expects to find lines like this:
#
#
# variable.nimi = "value"; // original_english_string
#					 -------------
#
# The comment part is generated by "ogo-strings", and is not available by default in OGo translations. 

echo "Checking all language project files in current directory for any syntax errors."
echo "Press Return to continue..."

read yn

	
for i in *.strings
do
	echo "Broken lines in file "\"$i\"
	grep -nv '^.*[[:space:]]=[[:space:]]".*";[[:space:]]//.*' $i
	echo
		echo "Press return to continue."
	read ok
done

ogo_variabletest

#!/bin/bash
#
# ogo_variabletest
#
# This script will check that the translation contains _ALL_ variables that are in the english originals.
# This is especially useful when a new version of OGo is released, or when some variables have for some
# reason disappeared from the translation.
#
# Usage
#
# 1. file = $1
# 2. file = $2 
#
# For example: ./ogo_variabletest "Finnish.lproj/OGoProject.strings" "English.lproj/OGoProject.strings"

echo "-------------"
echo "1. tiedosto: "$1 
echo "2. tiedosto: "$2

cat $1 | while read line; do

	# Grab the variable name
         key=$(echo $line | tr -s " "|cut -d "=" -f 1|cut -d " " -f 1)
      
	# If this line is not empty, continue
	 if [ ${#key} -gt 1 ]; then
	
		# Check if the variable can be found from the other file ($2)
		 grep "^$key[[:space:]]\+" $2 >/dev/null 2>&1
		
		# If this variable is not found from the file $2, start complaining

		 if [ $? -eq 1 ];  then
		  echo $key". is missing from file "$2
		  
       fi
	 fi
done

ogo_variabletest_run

#!/bin/bash
#
# ogo_variabletest_run
#
# This script will run "ogo_variabletest" on all files in given directories.
# In effect, it checks if the translation contains some variables that should not be there
# (=not in the english originals). It also does the check the other way around, checking for
# variables missing from the translation.

DIR1=Finnish.lproj
DIR2=English.lproj


echo "Variables in translation that are either extra or broken"
echo "--------------------------------------------------------"

for i in `ls $DIR1/*.strings`
do
	BASENAME=$(echo $i|cut -d "/" -f 2)
	ogo_variabletest $DIR1/$BASENAME $DIR2/$BASENAME
done

echo "The variables missing from the translation"
echo "------------------------------------------"


for i in `ls $DIR1/*.strings`
do
	BASENAME=$(echo $i|cut -d "/" -f 2)
	ogo_variabletest $DIR2/$BASENAME $DIR1/$BASENAME
done

echo "Done"
Created by sasepp
Last modified 2007-02-28 12:16 PM
 

Powered by Plone

This site conforms to the following standards: