1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
#!/bin/sh
# POT file creator (or PO file updater) for FVWM-Crystal
#
# Version: 3.4.0 (rev. 800)
# License: GPL 3+
#
# Author: Alwin <translations@ziggo.nl>
#
# Created: <12/11/2015>
# Changed: <17/11/2015> Description added.
# <26/11/2015> Prevent infinite loops better.
# <27/12/2015> Adjust Fvwm-Tooltip filter.
#
# Description: The purpose of this script, is to generate gettext
# templates for localization of FVWM-Crystal. Support for
# new languages can be created, or languages that seem to be
# unmaintained updated. Please consider sending your work to the package
# developer. Translations are a valuable part of this project!
#
# This script should be run from the `addons' directory, before or after
# installation. It can run with or without command line options.
#
# Options:
# -h Help message about command line options
# -n No file location info added. (Loss of context)
# -o Old style (of the former script); shorthand for -ns
# -s Sort strings alphabetically. (Loss of context)
# -t Text version created additionally (for no particular reason)
#
# By default, this script will produce two POT files: `fvwm-crystal.pot'
# and `fvwm-crystal-script.pot'. These files are meant to start
# translating from scratch.
#
# Previously translated files have the `.po' extension, and are located
# under the `locale' directory. When PO files (`fvwm-crystal.po' and/or
# `fvwm-crystal-script.po' of your language) are copied to the `addons'
# directory, then the newly created templates will be merged
# automatically by this script. After that, a possible workflow would be
# to search for empty msgstr's, check translations marked by the `fuzzy'
# flag, remove the lines containing `fuzzy', and (optionally) remove
# marked obsolete entries at the end of the PO files.
# Defaults if no option(s) specified
NOLOC="0"
OLDSTYLE="0"
SORT="0"
TEXT="0"
# Command line options overide defaults
while getopts ":hnost" opt; do
case $opt in
h) echo "Usage: $0 [-hnost]"; exit
;;
n) NOLOC="1"
;;
o) OLDSTYLE="1"
;;
s) SORT="1"
;;
t) TEXT="1"
;;
\?) echo "Invalid option: -$OPTARG" >&2
;;
esac
done
# The former script did this (more or less):
if [ "$OLDSTYLE" = "1" ]; then
NOLOC="1"
SORT="1"
LC_COLLATE="C"; export LC_COLLATE
else
# Keep the same sorting for now
LC_COLLATE="C"; export LC_COLLATE
fi
PREFIX="fvwm-crystal fvwm-crystal-script"
DATE="$(date '+%F %R%z')"
VERSION="$(grep Version ../fvwm/components/functions/About | cut -d" " -f 4 | sed -e 's:"::')"
###
for i in $PREFIX; do
if [ "$TEXT" = "1" ]; then
TEXTFILE="$i.txt"
else
TEXTFILE="/dev/null"
fi
# Create tmp file and optional plain text for fvwm-crystal
if [ "$i" = "fvwm-crystal" ]; then
# "../bin" is alphabetically first
FCGENMENU="../bin/fvwm-crystal.generate-menu"
# The file moves after installation
if [ ! -e $FCGENMENU ]; then
FCGENMENU="../../$FCGENMENU"
fi
grep -H -n '^[[:space:]]*[^#].*[^_]CAT="/[^$]' $FCGENMENU | sed \
-e 's|\([^:]*:[[:digit:]]*\):.*/\([^/]*\)".*|\1]\n\2|' | sed \
-e '2~2s|^[[:digit:]]*~*~||' \
-e '2~2y|_| |' | paste -d '' - - | tee .make.pot.tmp | sed \
-e 's|[^:]*:[[:digit:]]*]\(.*\)|\1|' >$TEXTFILE
# "../fvwm/Applications" is alphabetically second, etc.
ls -R ../fvwm/Applications | sed \
-e '\|^\.\./|!d' \
-e 's|\(.*/\)\([^/]*\):|\1]\n\2|' | sed \
-e '2~2s|^[[:digit:]]*~*~||' \
-e '2~2y|_| |' | paste -d '' - - | tee -a .make.pot.tmp | sed \
-e 's|.*/]\([^/]*\)|\1|' >>$TEXTFILE
grep -n -d skip --exclude=../fvwm/components/functions/Tooltip \
-e '^[[:space:]]*[^#].*\[gt\.' \
-e '^[[:space:]]*[^#].*Fvwm-Tooltip [^ ]* [\"]*[^\"$]' \
../fvwm/components/apps/* \
../fvwm/components/functions/* \
../fvwm/recipes/* \
../fvwm/scripts/* \
../fvwm/scripts/*/* | sed \
-e 's/\([^:]*:[[:digit:]]*\):.*\[gt\.\([^]]*\).*\[gt\.\([^]]*\).*/\1]\2\n\1]\3/' \
-e 's/\([^:]*:[[:digit:]]*\):.*\[gt\.\([^]]*\).*/\1]\2/' \
-e 's/\([^:]*:[[:digit:]]*\):.*Fvwm-Tooltip [^ ]* [\"]*\([^\"]*\)[\"]* [^ ]* [^ ]* [^ ]* [^ ]*/\1]\2/' \
-e 's/\\*$//' | tee -a .make.pot.tmp | sed \
-e 's/[^:]*:[[:digit:]]*]\(.*\)/\1/' >>$TEXTFILE
if [ "$TEXTFILE" != "/dev/null" ]; then
sort -u -o $TEXTFILE $TEXTFILE
fi
# Create tmp file and optional plain text for fvwm-crystal-script
elif [ "$i" = "fvwm-crystal-script" ]; then
grep -n -d skip -e '^[[:space:]]*[^#].*ocaleTitle {' \
-e '^[[:space:]]*[^#].*(Gettext {' \
../fvwm/components/scripts/* \
../fvwm/scripts/*/* | sed \
-e 's/\([^:]*:[[:digit:]]*\):.*LocaleTitle {\([^}]*\).*/\1]\2/' \
-e 's/\([^:]*:[[:digit:]]*\):.*Gettext {\([^}]*\).*/\1]\2/' | tee .make.pot.tmp | sed \
-e 's/[^:]*:[[:digit:]]*]\(.*\)/\1/' | sort -u >$TEXTFILE
fi
if [ "$SORT" = "1" ]; then
sort -t ']' -k 2 -o .make.pot.tmp .make.pot.tmp
fi
# Headers for pot files
(
cat <<'EOF'
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR FVWM-Crystal team
# This file is distributed under the same license as the fvwm-crystal package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: fvwm-crystal\n"
"POT-Creation-Date: 1970-01-01 00:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: LANGUAGE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
EOF
) | sed -e "s/1970-01-01 00:00+0000/${DATE}/" \
-e "s/Project-Id-Version: fvwm-crystal/& ${VERSION}/" \
>$i.pot
COUNT1="$(wc -l .make.pot.tmp | sed -e 's/\([[:digit:]]*\).*/\1/')"
# Create rest of pot file from tmp file
while [ -s .make.pot.tmp ]; do
STRING="$(sed \
-e '1!d' \
-e 's/.*]\([^]]*\)/\1/' \
-e 's/[*.\]/\\&/g' \
.make.pot.tmp)"
if [ "$NOLOC" = "1" ]; then
grep -e "]${STRING}\$" .make.pot.tmp | sed \
-e '$!d' \
-e 's/[\]/\\&/g' \
-e 's/.*]\([^]]*\)/msgid "\1"\nmsgstr ""\n/' \
>>$i.pot
else
grep -e "]${STRING}\$" .make.pot.tmp | sed \
-e '$!s/\(.*\)][^]]*/#: \1/' \
-e '$s/[\]/\\&/g' \
-e '$s/\(.*\)]\([^]]*\)/#: \1\nmsgid "\2"\nmsgstr ""\n/' \
>>$i.pot
fi
sed -i -e "\\]\\]${STRING}\$]d" .make.pot.tmp
# Prevent infinite loops
COUNT2="$(wc -l .make.pot.tmp | sed -e 's/\([[:digit:]]*\).*/\1/')"
if [ "$COUNT2" -lt "$COUNT1" ]; then
COUNT1="$COUNT2"
else
echo "Error: infinite loop"; exit 1
fi
done
echo '# End of generated strings' >>$i.pot
# Merge po files
if [ -e $i.po ]; then
MERGEOPTS="-U --no-wrap -q"
if [ "$NOLOC" = "1" ]; then
MERGEOPTS="$MERGEOPTS --no-location"
fi
if [ "$SORT" = "1" ]; then
MERGEOPTS="$MERGEOPTS -s"
fi
msgmerge $MERGEOPTS $i.po $i.pot && (rm -f $i.pot; sed -i -e \
"s/^\"Project-Id-Version:.*/\"Project-Id-Version: fvwm-crystal ${VERSION}\\\\n\"/" \
$i.po)
fi
done
###
# Cleanup
rm -f .make.pot*
|