first translate toolkit workflow for pootle:

* java property files conversion
This commit is contained in:
lars 2009-05-23 11:20:35 +00:00
parent 31bb60e1b4
commit 264680d67a

View file

@ -0,0 +1,124 @@
#!/bin/sh
#
# convert a directory or java property files into po files and back
#
# This is just the example script used for jsymphonic.
#
set -eu
PROP_DIR="$(dirname $0)/jsymphonic.properties.d"
PO_DIR="$(dirname $0)/jsymphonic.po.d"
POOTLE_DIR=/var/lib/pootle/jsymphonic
TEMP_DIR="$(dirname $0)/temp"
PROP_EXT=".properties"
PROP_LANG_SUFFIX_REGEX="_[a-z]{2}_[A-Z]{2}"
POT_EXT=".pot"
PO_EXT=".po"
POTOOLS_OPTS="--progress none"
get_all_prop_templates() {
(
cd "$PROP_DIR"
find -type f -name "*$PROP_EXT" | grep -vE ".*$PROP_LANG_SUFFIX_REGEX$PROP_EXT$"
)
}
get_translated_properties() {
local prop_template="$1"
(
cd "$PROP_DIR"
find -type f -name "*$PROP_EXT" | grep -E "${prop_template%$PROP_EXT}$PROP_LANG_SUFFIX_REGEX$PROP_EXT$"
)
}
template_prop2po() {
mkdir -p "$PO_DIR"
prop2po $POTOOLS_OPTS -P "$PROP_DIR/$1" "$PO_DIR/${1%$PROP_EXT}$POT_EXT"
}
# input: filename of a translated properties file
# output: filename of the properties template file
get_prop_template() {
echo "${1%$PROP_EXT}" | sed -r "s/$PROP_LANG_SUFFIX_REGEX$/$PROP_EXT/g"
}
# input: filename of a translated properties file
# output: filename of the corresponding pot template file
get_pot_template() {
echo -n "${1%$PROP_EXT}" | sed -r "s/$PROP_LANG_SUFFIX_REGEX$//g"
echo "$POT_EXT"
}
# input: filename of a translated properties file
# output: filename of the corresponding translated po file
get_po_filename() {
echo "${1%$PROP_EXT}$PO_EXT"
}
convert_to_po_merged() {
local prop_file="$PROP_DIR/$1"
local prop_template="$PROP_DIR/$(get_prop_template "$1")"
local pot_file="$PO_DIR/$(get_pot_template "$1")"
local po_file="$PO_DIR/$(get_po_filename "$1")"
local temp_po_file1="$TEMP_DIR/$(get_po_filename "$1")_1.$PO_EXT"
local temp_po_file2="$TEMP_DIR/$(get_po_filename "$1")_2.$PO_EXT"
mkdir -p "$TEMP_DIR"
if test -f "$po_file"; then
# merge the prop with the po file (priority: po file)
prop2po $POTOOLS_OPTS -t "$prop_template" -i "$prop_file" -o "$temp_po_file1"
pomerge $POTOOLS_OPTS -t "$po_file" -i "$temp_po_file1" -o "$temp_po_file2"
mv "$temp_po_file2" "$po_file"
rm "$temp_po_file1"
else prop2po $POTOOLS_OPTS -t "$prop_template" -i "$prop_file" -o "$po_file"
fi
}
# convert a po file to a prop file
convert_po_to_prop() {
local prop_file="$PROP_DIR/$1"
local prop_template="$PROP_DIR/$(get_prop_template "$1")"
local po_file="$PO_DIR/$(get_po_filename "$1")"
po2prop $POTOOLS_OPTS -t "$prop_template" -i "$po_file" -o "$prop_file"
}
get_lang_code() {
echo "$1" | sed -r "s/^.*($PROP_LANG_SUFFIX_REGEX).*$/\1/" | sed 's/^_//' | sed 's/_$//'
}
create_symlink_po() {
local po_file="$PO_DIR/$(get_po_filename "$1")"
local lang_code="$(get_lang_code "$1")"
mkdir -p "$POOTLE_DIR/$lang_code"
ln -sfn "$(pwd)/$po_file" "$POOTLE_DIR/$lang_code/"
}
create_symlink_pot() {
local pot_file="$PO_DIR/$(get_pot_template "$1")"
ln -sfn "$(pwd)/$pot_file" "$POOTLE_DIR/"
}
# *************** do the conversion ***********************
get_all_prop_templates | while read prop; do
template_prop2po "$prop"
create_symlink_pot "$prop"
get_translated_properties "$prop" | while read prop_file; do
convert_to_po_merged "$prop_file"
convert_po_to_prop "$prop_file"
create_symlink_po "$prop_file"
done
done