Skip to content

Commit 971d663

Browse files
authored
Merge pull request #66 from taniwallach/add-maketext
Add maketext
2 parents bfadfd9 + c22aad1 commit 971d663

6 files changed

Lines changed: 803 additions & 4 deletions

File tree

docs/make_translation_files.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
- Go to the location under which the renderer was installed.
3+
- You need to have `xgettext.pl` installed.
4+
5+
```
6+
cd container/lib
7+
xgettext.pl -o WeBWorK/lib/WeBWorK/Localize/standalone.pot -D PG/lib -D PG/macros -D RenderApp -D WeBWorK/lib RenderApp.pm
8+
```
9+
10+
- That creates the POT file of all strings found
11+
12+
```
13+
cd WeBWorK/lib/WeBWorK/Localize
14+
find . -name '*.po' -exec bash -c "echo \"Updating {}\"; msgmerge -qUN {} standalone.pot" \;
15+
```
16+

lib/RenderApp/Controller/FormatRenderedProblem.pm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use MIME::Base64 qw( encode_base64 decode_base64);
2828
use WeBWorK::Utils::AttemptsTable; #import from ww2
2929
use WeBWorK::PG::ImageGenerator; # import from ww2
3030
use WeBWorK::Utils qw( wwRound); # required for score summary
31+
use WeBWorK::Localize ; # for maketext
3132
our $UNIT_TESTS_ON = 0;
3233

3334
#####################
@@ -181,6 +182,8 @@ sub formatRenderedProblem {
181182
my $formLanguage = $self->{inputs_ref}{language} // 'en';
182183
my $scoreSummary = '';
183184

185+
my $mt = WeBWorK::Localize::getLangHandle($self->{inputs_ref}{language} // 'en');
186+
184187
my $tbl = WeBWorK::Utils::AttemptsTable->new(
185188
$rh_answers,
186189
answersSubmitted => $self->{inputs_ref}{answersSubmitted}//0,
@@ -209,7 +212,10 @@ sub formatRenderedProblem {
209212
# render equation images
210213

211214
if ($submitMode && $problemResult && $showSummary) {
212-
$scoreSummary = CGI::p('Your score on this attempt is '.wwRound(0, $problemResult->{score} * 100).'%');
215+
$scoreSummary = CGI::p($mt->maketext('Your score on this attempt is [_1]', wwRound(0, $problemResult->{score} * 100).'%'));
216+
217+
#$scoreSummary .= CGI::p($mt->maketext("Your score was not recorded."));
218+
213219
#scoreSummary .= CGI::p('Your score on this problem has not been recorded.');
214220
#$scoreSummary .= CGI::hidden({id=>'problem-result-score', name=>'problem-result-score',value=>$problemResult->{score}});
215221
}
@@ -267,9 +273,9 @@ sub formatRenderedProblem {
267273
}
268274
}
269275

270-
my $STRING_Preview = "Preview My Answers";
271-
my $STRING_ShowCorrect = "Show correct answers";
272-
my $STRING_Submit = "Submit Answers";
276+
my $STRING_Preview = $mt->maketext("Preview My Answers");
277+
my $STRING_ShowCorrect = $mt->maketext("Show correct answers");
278+
my $STRING_Submit = $mt->maketext("Submit Answers");
273279

274280
#my $pretty_print_self = pretty_print($self);
275281

lib/WeBWorK/lib/WeBWorK/Localize.pm

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,55 @@ eval "
2626

2727
package WeBWorK::Localize;
2828

29+
# This subroutine is shared with the safe compartment in PG to
30+
# allow maketext() to be constructed in PG problems and macros
31+
# It seems to be a little fragile -- possibly it breaks
32+
# on perl 5.8.8
2933
sub getLoc {
3034
my $lang = shift;
3135
my $lh = WeBWorK::Localize::I18N->get_handle($lang);
3236
return sub {$lh->maketext(@_)};
3337
}
3438

39+
sub getLangHandle {
40+
my $lang = shift;
41+
my $lh = WeBWorK::Localize::I18N->get_handle($lang);
42+
return $lh;
43+
}
44+
45+
# this is like [quant] but it doesn't write the number
46+
# usage: [quant,_1,<singular>,<plural>,<optional zero>]
47+
48+
sub plural {
49+
my($handle, $num, @forms) = @_;
50+
51+
return "" if @forms == 0;
52+
return $forms[2] if @forms > 2 and $num == 0;
53+
54+
# Normal case:
55+
return( $handle->numerate($num, @forms) );
56+
}
57+
58+
# this is like [quant] but it also has -1 case
59+
# usage: [negquant,_1,<neg case>,<singular>,<plural>,<optional zero>]
60+
61+
sub negquant {
62+
my($handle, $num, @forms) = @_;
63+
64+
return $num if @forms == 0;
65+
66+
my $negcase = shift @forms;
67+
return $negcase if $num < 0;
68+
69+
return $forms[2] if @forms > 2 and $num == 0;
70+
return( $handle->numf($num) . ' ' . $handle->numerate($num, @forms) );
71+
}
72+
73+
%Lexicon = (
74+
'_AUTO' => 1,
75+
);
76+
77+
package WeBWorK::Localize::I18N;
78+
use base(WeBWorK::Localize);
3579

3680
1;
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
#
5+
# Translators:
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: webwork2\n"
9+
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
10+
"PO-Revision-Date: 2021-03-09 17:00-0600\n"
11+
"Last-Translator: \n"
12+
"Language: en_US\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: 8bit\n"
16+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
17+
18+
#. (wwRound(0, $answerScore*100)
19+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:255
20+
msgid "%1% correct"
21+
msgstr ""
22+
23+
#. ($numBlanks)
24+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:395
25+
msgid "%quant(%1,of the questions remains,of the questions remain) unanswered."
26+
msgstr ""
27+
28+
#: PG/macros/PGbasicmacros.pl:1277 PG/macros/PGbasicmacros.pl:1286
29+
msgid ""
30+
"(Instructor hint preview: show the student hint after the following number "
31+
"of attempts:"
32+
msgstr ""
33+
34+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:386
35+
msgid "All of the answers above are correct."
36+
msgstr ""
37+
38+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:384
39+
msgid "All of the gradeable answers above are correct."
40+
msgstr ""
41+
42+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:289
43+
msgid "Answer Preview"
44+
msgstr ""
45+
46+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:391
47+
msgid "At least one of the answers above is NOT correct."
48+
msgstr ""
49+
50+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:291
51+
msgid "Correct Answer"
52+
msgstr ""
53+
54+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:288
55+
msgid "Entered"
56+
msgstr ""
57+
58+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:238
59+
msgid "FeedbackMessage"
60+
msgstr ""
61+
62+
#: PG/macros/problemRandomize.pl:185 PG/macros/problemRandomize.pl:186
63+
msgid "Get a new version of this problem"
64+
msgstr ""
65+
66+
#: PG/macros/compoundProblem.pl:470
67+
msgid "Go back to Part 1"
68+
msgstr ""
69+
70+
#: PG/macros/compoundProblem.pl:291 PG/macros/compoundProblem.pl:480
71+
#: PG/macros/compoundProblem.pl:491
72+
msgid "Go on to next part"
73+
msgstr ""
74+
75+
#: PG/macros/problemRandomize.pl:409
76+
msgid "Hardcopy will always print the original version of the problem."
77+
msgstr ""
78+
79+
#: PG/macros/PGbasicmacros.pl:1558
80+
msgid "Hint:"
81+
msgstr ""
82+
83+
#: PG/macros/PGbasicmacros.pl:1558
84+
msgid "Hint: "
85+
msgstr ""
86+
87+
#: PG/macros/problemRandomize.pl:408
88+
msgid "If you come back to it later, it may revert to its original version."
89+
msgstr ""
90+
91+
#: PG/macros/PGbasicmacros.pl:1226
92+
msgid "Instructor solution preview: show the student solution after due date."
93+
msgstr ""
94+
95+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:292
96+
msgid "Message"
97+
msgstr ""
98+
99+
#: PG/macros/problemRandomize.pl:382 PG/macros/problemRandomize.pl:407
100+
msgid "Note:"
101+
msgstr ""
102+
103+
#: RenderApp/Controller/FormatRenderedProblem.pm:276
104+
msgid "Preview My Answers"
105+
msgstr ""
106+
107+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:290
108+
msgid "Result"
109+
msgstr ""
110+
111+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:302
112+
msgid "Results for this submission"
113+
msgstr ""
114+
115+
#: PG/macros/problemRandomize.pl:187
116+
msgid "Set random seed to:"
117+
msgstr ""
118+
119+
#: RenderApp/Controller/FormatRenderedProblem.pm:277
120+
msgid "Show correct answers"
121+
msgstr ""
122+
123+
#: PG/macros/PGbasicmacros.pl:1554 PG/macros/PGbasicmacros.pl:1555
124+
msgid "Solution:"
125+
msgstr ""
126+
127+
#: PG/macros/PGbasicmacros.pl:1553
128+
msgid "Solution: "
129+
msgstr ""
130+
131+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:377
132+
msgid "Some answers will be graded later."
133+
msgstr ""
134+
135+
#: RenderApp/Controller/FormatRenderedProblem.pm:278
136+
msgid "Submit Answers"
137+
msgstr ""
138+
139+
#: PG/macros/compoundProblem.pl:502
140+
msgid "Submit your answers again to go on to the next part."
141+
msgstr ""
142+
143+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:379
144+
msgid "The answer above is NOT correct."
145+
msgstr ""
146+
147+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:375
148+
msgid "The answer above is correct."
149+
msgstr ""
150+
151+
#: PG/macros/problemRandomize.pl:407
152+
msgid "This is a new (re-randomized) version of the problem."
153+
msgstr ""
154+
155+
#: PG/macros/PGbasicmacros.pl:3084
156+
msgid "This problem contains a video which must be viewed online."
157+
msgstr ""
158+
159+
#: PG/macros/compoundProblem.pl:602
160+
msgid "This problem has more than one part."
161+
msgstr ""
162+
163+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:248
164+
msgid "Ungraded"
165+
msgstr ""
166+
167+
#: PG/macros/PGanswermacros.pl:1693
168+
msgid "You can earn partial credit on this problem."
169+
msgstr ""
170+
171+
#: PG/macros/problemRandomize.pl:383
172+
msgid "You can get a new version of this problem after the due date."
173+
msgstr ""
174+
175+
#: PG/macros/compoundProblem.pl:610
176+
msgid "You may not change your answers when going on to the next part!"
177+
msgstr ""
178+
179+
#: PG/macros/PGbasicmacros.pl:3079
180+
msgid "Your browser does not support the video tag."
181+
msgstr ""
182+
183+
#: PG/macros/compoundProblem.pl:603
184+
msgid "Your score for this attempt is for this part only;"
185+
msgstr ""
186+
187+
#. (wwRound(0, $problemResult->{score} * 100)
188+
#: RenderApp/Controller/FormatRenderedProblem.pm:215
189+
msgid "Your score on this attempt is %1"
190+
msgstr ""
191+
192+
#: RenderApp/Controller/FormatRenderedProblem.pm:217
193+
msgid "Your score was not recorded."
194+
msgstr ""
195+
196+
#: PG/macros/PGbasicmacros.pl:645 PG/macros/PGbasicmacros.pl:656
197+
msgid "answer"
198+
msgstr ""
199+
200+
#: PG/macros/PGbasicmacros.pl:669
201+
msgid "column"
202+
msgstr ""
203+
204+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:244
205+
msgid "correct"
206+
msgstr ""
207+
208+
#. ('j','k','_0')
209+
#. ('j','k')
210+
#: PG/lib/Parser/List/Vector.pm:35 PG/lib/Value/Vector.pm:278
211+
#: PG/macros/contextLimitedVector.pl:94
212+
msgid "i"
213+
msgstr ""
214+
215+
#: PG/macros/contextPiecewiseFunction.pl:774
216+
msgid "if"
217+
msgstr ""
218+
219+
#: WeBWorK/lib/WeBWorK/Utils/AttemptsTable.pm:253
220+
msgid "incorrect"
221+
msgstr ""
222+
223+
#: PG/macros/contextPiecewiseFunction.pl:777
224+
msgid "otherwise"
225+
msgstr ""
226+
227+
#: PG/macros/PGbasicmacros.pl:662
228+
msgid "part"
229+
msgstr ""
230+
231+
#: PG/macros/PGbasicmacros.pl:651
232+
msgid "problem"
233+
msgstr ""
234+
235+
#: PG/macros/PGbasicmacros.pl:668
236+
msgid "row"
237+
msgstr ""
238+
239+
#: PG/macros/compoundProblem.pl:470 PG/macros/compoundProblem.pl:480
240+
msgid "when you submit your answers"
241+
msgstr ""
242+
243+
#: PG/macros/compoundProblem.pl:604
244+
msgid "your overall score is for all the parts combined."
245+
msgstr ""

0 commit comments

Comments
 (0)