gettext/gettext-tools/tests/format-javascript-3
Bruno Haible ccd07974b0 xgettext: JavaScript: Improve heuristic for format strings.
* gettext-tools/src/format-javascript.c (struct spec): Add field
'likely_intentional_directives'.
(format_parse): Set it to the number of directives that don't contain a space.
(format_is_unlikely_intentional): New function.
(formatstring_javascript): Use it.
* gettext-tools/tests/format-javascript-3: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
2025-06-02 02:22:42 +02:00

54 lines
1.4 KiB
Bash
Executable File

#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
# Test heuristic recognition of JavaScript format strings like "100% complete".
cat <<\EOF > f-js-3.js
gettext("Test 1a is 100% complete");
// gettext("Test 1b is 100% complete").format(120); // TODO
sformat(gettext("Test 1b is 100% complete"), 120);
gettext("Test 2a from 0% complete to 100% complete");
// gettext("Test 2b from 0% complete to 100% complete").format(120, 121); // TODO
sformat(gettext("Test 2b from 0% complete to 100% complete"), 120, 121);
gettext("Test 3a of %s is 100% complete");
// gettext("Test 3b of %s is 100% complete").format("foo", 120); // TODO
sformat(gettext("Test 3b of %s is 100% complete"), "foo", 120);
EOF
: ${XGETTEXT=xgettext}
${XGETTEXT} --flag=sformat:1:javascript-format \
--omit-header --no-location -d f-js-3.tmp f-js-3.js || Exit 1
LC_ALL=C tr -d '\r' < f-js-3.tmp.po > f-js-3.po || Exit 1
cat <<\EOF > f-js-3.ok
msgid "Test 1a is 100% complete"
msgstr ""
#, javascript-format
msgid "Test 1b is 100% complete"
msgstr ""
msgid "Test 2a from 0% complete to 100% complete"
msgstr ""
#, javascript-format
msgid "Test 2b from 0% complete to 100% complete"
msgstr ""
#, javascript-format
msgid "Test 3a of %s is 100% complete"
msgstr ""
#, javascript-format
msgid "Test 3b of %s is 100% complete"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} f-js-3.ok f-js-3.po
result=$?
exit $result