Aegisub/po/make_pot.sh

57 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/sh
set -e
maybe_append() {
while read -r msg; do
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
msgfile=$(printf '%s' "$msg" | cut -d'|' -f1)
msgline=$(printf '%s' "$msg" | cut -d'|' -f2)
msgid=$(printf '%s' "$msg" | cut -d'|' -f3-)
if ! grep -Fq "msgid $msgid" aegisub.pot; then
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
printf "\n#: %s:%s\nmsgid %s\nmsgstr \"\"\n\n" \
"$msgfile" "$msgline" "$msgid" >> aegisub.pot
fi
done
}
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
find ../src ../src/command -name '*.cpp' -o -name '*.h' \
| xgettext --files-from=- -o - --c++ --sort-by-file \
-k_ -kSTR_MENU -kSTR_DISP -kSTR_HELP -kfmt_tl -kfmt_plural:2,3 -kwxT -kwxPLURAL:1,2 \
2014-03-12 17:40:40 +01:00
| sed 's/SOME DESCRIPTIVE TITLE./Aegisub 3.2/' \
2014-01-01 16:19:25 +01:00
| sed 's/YEAR/2005-2014/' \
| sed "s/THE PACKAGE'S COPYRIGHT HOLDER/Rodrigo Braz Monteiro, Niels Martin Hansen, Thomas Goyne et. al./" \
| sed 's/PACKAGE/Aegisub/' \
2014-03-12 17:40:40 +01:00
| sed 's/VERSION/3.2.0/' \
| sed 's/FIRST AUTHOR <EMAIL@ADDRESS>/Niels Martin Hansen <nielsm@aegisub.org>/' \
| sed 's/CHARSET/UTF-8/' \
> aegisub.pot
sed '/"text"/!d;s/^.*"text" : \("[^"]\+"\).*$/default_menu.json|0|\1/' ../src/libresrc/default_menu.json \
| maybe_append
sed '/"text"/!d;s/^.*"text" : \("[^"]\+"\).*$/default_menu.json|0|\1/' ../src/libresrc/osx/default_menu.json \
| maybe_append
grep '"[A-Za-z ]\+" : {' -n ../src/libresrc/default_hotkey.json \
| sed 's/^\([0-9]\+:\).*\("[^"]\+"\).*$/default_hotkey.json|\1|\2/' \
| maybe_append
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
find ../automation -name '*.lua' \
| LC_ALL=C sort \
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
| xargs grep 'tr"[^"]*"' -o -n \
| sed 's/\(.*\):\([0-9]\+\):tr\(".*"\)/\1|\2|\3/' \
| maybe_append
xgettext ../packages/desktop/aegisub.desktop.in.in \
--language=Desktop --join-existing --omit-header -o aegisub.pot
xgettext ../packages/desktop/aegisub.appdata.xml.in.in \
--language=AppData --join-existing --omit-header -o aegisub.pot
grep '^_[A-Za-z0-9]*=.*' ../packages/win_installer/fragment_strings.iss.in | while read line
do
po/make_pot: increase portability across shells Base POSIX leaves the handling of backslahes in the operand implementation defined. The XSI extension specifies several escape sequences, like e.g. \n, which shall be transformed upon printing. Current make_pot.sh expects XSI behaviour and indeed e.g. dash’s echo builtin implements this. echo builtins of other common shells such as bash however, do not (by default). Avoid this portability pitfall by just using printf at all relevant places. See: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html This also allows us to stop substituting each backslash with four backslashes before piping to maybe_append. This substituion existed to safely pass backslahes through maybe_append’s two layers of echo. Also improve quoting. For consistency prefer single-quote quoting over shell backslash escapes. QUote the unguarded *.lua to ensure it will continue to work if there happen to be any lua files in the scripts working directory. This supersedes commits from wangqr/Aegisub which adjusted quoting and echo usage to work with different shells. This is more throughout and doesn't introduce semi-broken intermediate states. https://github.com/wangqr/Aegisub/commit/0fbcaea871be75b9dbcb2b9cee19df9a61177717 https://github.com/wangqr/Aegisub/commit/4aee271d034f5f0a47863594f07ef4d172ecc4f4 https://github.com/wangqr/Aegisub/commit/940181c7bc76128a008c15292d9a5dc0cb8c2281 (Note the second commit actually didn't manage to achieve the intended portability, since several echo usages remained and it forgot to adjust the backslash substitution, which was then fixed in the third commit.)
2023-04-29 02:58:20 +02:00
printf '%s\n' "$line" \
| sed 's/[^=]*=\(.*\)/packages\/win_installer\/fragment_strings.iss|1|"\1"/' \
| maybe_append
done