tde-l10n_split_desktop: Adjusted to ensure portability

+ the use of an array is omitted
+ printf is used instead of echo
+ $(...) is used for subshell

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/3/head
Slávek Banko 5 years ago
parent 7b46022903
commit bc35bf2852
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# default keyword # default keywords
KEYWORDS="Name GenericName Comment Keywords Description ExtraNames X-TDE-Submenu" KEYWORDS="Name GenericName Comment Keywords Description ExtraNames X-TDE-Submenu"
# parse arguments # parse arguments
@ -32,13 +32,16 @@ while [ $# -gt 0 ]; do
*) *)
[ -f "$1" ] && \ [ -f "$1" ] && \
D+=("$1") D="${D}|$1"
;; ;;
esac esac
shift shift
done done
set -- "${D[@]}" oldIFS=$IFS
IFS="|"
set -- ${D#|}
IFS=$oldIFS
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "No desktop file specified for processing. Exiting..." echo "No desktop file specified for processing. Exiting..."
@ -51,7 +54,7 @@ fi
# determine path for translations # determine path for translations
TRANSLATIONS_DIR="translations/desktop_files" TRANSLATIONS_DIR="translations/desktop_files"
if [ -n "`git rev-parse --git-dir 2>/dev/null`" ]; then if [ -n "$(git rev-parse --git-dir 2>/dev/null)" ]; then
TRANSLATIONS_DIR="$(git rev-parse --show-toplevel)/${TRANSLATIONS_DIR}" TRANSLATIONS_DIR="$(git rev-parse --show-toplevel)/${TRANSLATIONS_DIR}"
APPNAME=$(basename $(git rev-parse --show-toplevel)) APPNAME=$(basename $(git rev-parse --show-toplevel))
fi fi
@ -106,7 +109,7 @@ done
# extract strings # extract strings
#xgettext --foreign-user -L Desktop -k -k"Name" -k"GenericName" -k"Comment" -k"Keywords" -k"Description" -k"ExtraNames" -k"X-TDE-Submenu" -o - "$D" | \ #xgettext --foreign-user -L Desktop -k -k"Name" -k"GenericName" -k"Comment" -k"Keywords" -k"Description" -k"ExtraNames" -k"X-TDE-Submenu" -o - "$D" | \
echo -n "${DX#|}" | tr "|" "\0" | xargs -r0 \ printf "%s" "${DX#|}" | tr "|" "\0" | xargs -r0 \
xgettext --foreign-user -Cc -ki18n -o - | \ xgettext --foreign-user -Cc -ki18n -o - | \
sed "s|\.tde_l10n||g" | \ sed "s|\.tde_l10n||g" | \
sed "s|Content-Type: text/plain; charset=CHARSET|Content-Type: text/plain; charset=UTF-8|" \ sed "s|Content-Type: text/plain; charset=CHARSET|Content-Type: text/plain; charset=UTF-8|" \
@ -114,38 +117,38 @@ sed "s|Content-Type: text/plain; charset=CHARSET|Content-Type: text/plain; chars
POT_HEADER=$(sed -n "1,/^$/p" "$TRANSLATIONS_DIR/$POT") POT_HEADER=$(sed -n "1,/^$/p" "$TRANSLATIONS_DIR/$POT")
# remove temporary files # remove temporary files
echo -n "${DX#|}" | tr "|" "\0" | xargs -r0 \ printf "%s" "${DX#|}" | tr "|" "\0" | xargs -r0 \
rm rm
# process languages # process languages
echo -n "${DO#|}" | tr "|" "\0" | xargs -r0 cat | printf "%s" "${DO#|}" | tr "|" "\0" | xargs -r0 cat |
sed -n "s|.*\[\([^]]*\)\][ ]*=.*|\1|p" | \ sed -n "s|.*\[\([^]]*\)\][ ]*=.*|\1|p" | \
grep -vx "xx" | \ grep -vx "xx" | \
sort -u | \ sort -u | \
while read L; do while read L; do
echo "$POT_HEADER" | sed "s|\(Language: \)|\1$L|" > "$TRANSLATIONS_DIR/$L.po" printf "%s\n" "$POT_HEADER" | sed "s|\(Language: \)|\1$L|" > "$TRANSLATIONS_DIR/$L.po"
echo >> "$TRANSLATIONS_DIR/$L.po"
# process sections # process sections
echo "${DO#|}" | tr "|" "\n" | printf "%s\n" "${DO#|}" | tr "|" "\n" |
while read D; do while read D; do
sed -n "s|^\[\(.*\)\]$|\1|p" "$D" | \ sed -n "s|^\[\(.*\)\]$|\1|p" "$D" | \
while read S; do while read S; do
# process variables # process variables
sed -n "/^\[$S\]/,/^\[/s|^\([^#\[][^\[]*\)\[$L\][ ]*=.*|\1|p" "$D" | \ sed -n "/^\[$S\]/,/^\[/s|^\([^#\[][^\[]*\)\[$L\][ ]*=.*|\1|p" "$D" | \
while read V; do while read V; do
MSGID=`sed -n -e "s|\"|\\\\\"|g" -e "/^\[$S\]/,/^\[/s|^$V[ ]*=[ ]*\(.*\)$|msgid \"\1\"|p" "$D"` MSGID=$(sed -n -e "s|\"|\\\\\"|g" \
-e "/^\[$S\]/,/^\[/s|^$V[ ]*=[ ]*\(.*\)$|msgid \"\1\"|p" "$D")
if [ -n "$MSGID" ] && [ -z "$(grep -Fx "$MSGID" "$TRANSLATIONS_DIR/$L.po")" ]; then if [ -n "$MSGID" ] && [ -z "$(grep -Fx "$MSGID" "$TRANSLATIONS_DIR/$L.po")" ]; then
echo "$MSGID" printf "%s\n" "$MSGID"
sed -n -e "s|\"|\\\\\"|g" -e "/^\[$S\]/,/^\[/s|^$V\[$L\][ ]*=[ ]*\(.*\)$|msgstr \"\1\"|p" "$D" | head -n1 sed -n -e "s|\"|\\\\\"|g" -e "/^\[$S\]/,/^\[/s|^$V\[$L\][ ]*=[ ]*\(.*\)$|msgstr \"\1\"|p" "$D" | head -n1
echo printf "\n"
fi fi
done >> "$TRANSLATIONS_DIR/$L.po" done >> "$TRANSLATIONS_DIR/$L.po"
done done
done done
# update according to template # update according to template
echo -n "-- $L " printf "%s" "-- $L "
msgmerge --update --backup=none "$TRANSLATIONS_DIR/$L.po" "$TRANSLATIONS_DIR/$POT" msgmerge --update --backup=none "$TRANSLATIONS_DIR/$L.po" "$TRANSLATIONS_DIR/$POT"
done done

Loading…
Cancel
Save