1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test msgexec on a PO file with contexts.
5
6# This test fails on mingw (in a Cygwin environment), due to the combination
7# of two reasons:
8# 1. The value of the environment variable MSGEXEC_MSGCTXT is stored
9#    in UTF-8 encoding (i.e. the PO file's encoding); it should be stored
10#    in the GetACP() encoding instead. This problem is inherent in msgexec,
11#    and msgexec warns about it - but in this test, we filter the warnings
12#    away.
13# 2. The child process is Cygwin's sh.exe, and is affected by a Cygwin bug:
14#    the values returned by getenv() in the child process, when the parent
15#    process is a mingw program, are in the GetOEMCP() encoding (should be
16#    in the GetACP() encoding). This has been reported at
17#    <https://cygwin.com/ml/cygwin/2009-08/msg00430.html>.
18
19cat <<\EOF > mex-test4.po
20msgid ""
21msgstr ""
22"Content-Type: text/plain; charset=UTF-8\n"
23"Content-Transfer-Encoding: 8bit\n"
24
25#. A menu item
26msgctxt "File|"
27msgid "Open"
28msgstr "Ouvrir"
29
30#. A menu item
31msgctxt "File|"
32msgid "New"
33msgstr "Nouveau"
34
35#. Denote a lock's state
36msgctxt "Lock state"
37msgid "Open"
38msgstr "Ouvert"
39
40#. Denote a lock's state
41msgctxt "Lock state"
42msgid "Closed"
43msgstr "Fermé"
44
45#. A product
46msgctxt "Audi"
47msgid "car"
48msgstr "voiture"
49
50#. A product
51msgctxt "Océ"
52msgid "copier"
53msgstr "photocopieur"
54
55#~ msgid "Save As"
56#~ msgstr "Enregistrer l'as"
57
58#. A menu item
59#~ msgctxt "File|"
60#~ msgid "Save As"
61#~ msgstr "Enregistrer sous"
62EOF
63
64cat <<\EOF > mex-test4.sh
65#! /bin/sh
66echo "========================= $MSGEXEC_LOCATION =========================" | LC_ALL=C tr -d '\r'
67if test -n "${MSGEXEC_MSGCTXT+set}"; then
68  echo "context: $MSGEXEC_MSGCTXT" | LC_ALL=C tr -d '\r'
69fi
70cat <<MEOF
71$MSGEXEC_MSGID
72---
73MEOF
74cat
75echo | LC_ALL=C tr -d '\r'
76exit 0
77EOF
78chmod a+x mex-test4.sh
79
80: ${MSGEXEC=msgexec}
81LC_ALL=C \
82${MSGEXEC} -i mex-test4.po ./mex-test4.sh > mex-test4.out 2> mex-test4.err
83result=$?
84cat mex-test4.err | grep -v 'warning: Locale charset' | grep -v '^ '
85test $result = 0 || { Exit 1; }
86
87cat <<\EOF > mex-test4.ok
88========================= mex-test4.po:2 =========================
89
90---
91Content-Type: text/plain; charset=UTF-8
92Content-Transfer-Encoding: 8bit
93
94========================= mex-test4.po:9 =========================
95context: File|
96Open
97---
98Ouvrir
99========================= mex-test4.po:14 =========================
100context: File|
101New
102---
103Nouveau
104========================= mex-test4.po:19 =========================
105context: Lock state
106Open
107---
108Ouvert
109========================= mex-test4.po:24 =========================
110context: Lock state
111Closed
112---
113Fermé
114========================= mex-test4.po:29 =========================
115context: Audi
116car
117---
118voiture
119========================= mex-test4.po:34 =========================
120context: Océ
121copier
122---
123photocopieur
124========================= mex-test4.po:37 =========================
125Save As
126---
127Enregistrer l'as
128========================= mex-test4.po:42 =========================
129context: File|
130Save As
131---
132Enregistrer sous
133EOF
134
135: ${DIFF=diff}
136${DIFF} mex-test4.ok mex-test4.out
137result=$?
138
139exit $result
140