Skip to content

Commit fd91669

Browse files
Add lab ja_hello.html: Demo Japanese translation
This adds lab `ja_hello.html`, a Japanese translation of lab `hello.html`. It also adds various fixes of `checker.js`, because the process of implementing this lab revealed some bugs in our library. Signed-off-by: David A. Wheeler <[email protected]>
1 parent 128a7b3 commit fd91669

File tree

2 files changed

+106
-14
lines changed

2 files changed

+106
-14
lines changed

docs/labs/checker.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ let startTime = Date.now();
2121
let BACKQUOTE = "`"; // Make it easy to use `${BACKQUOTE}`
2222
let DOLLAR = "$"; // Make it easy to use `${DOLLAR}`
2323

24-
// Current language
25-
let lang;
24+
// Current language. Guess English until we learn otherwise.
25+
let lang = "en";
2626

2727
const resources = {
2828
en: {
2929
translation: {
3030
already_correct: 'The answer is already correct!',
31+
complete: 'COMPLETE!',
32+
completed: 'Completed',
3133
congrats: 'Congratulations! Your answer is correct!',
3234
congrats_all: 'Great work! All your answers are correct!',
3335
expecting: "We were expecting an answer like this:\n{0}",
@@ -36,12 +38,15 @@ const resources = {
3638
no_hints: 'Sorry, there are no hints for this lab.',
3739
no_matching_hint: 'Sorry, I cannot find a hint that matches your attempt.',
3840
reset_title: 'Reset initial state (throwing away current attempt).',
41+
to_be_completed: 'to be completed',
3942
try_harder: "Try harder! Don't give up so soon. Current time spent (in seconds): {0}",
4043
}
4144
},
4245
ja: {
4346
translation: {
4447
already_correct: '答えはすでに正しいです!',
48+
complete: '完了',
49+
completed: '完了しました',
4550
congrats: '「おめでとうございます!」あなたの答えは正解です!',
4651
congrats_all: '素晴らしい仕事でした!あなたの答えはすべて正解です!',
4752
expecting: "次のような答えを期待していました:\n{0}",
@@ -50,6 +55,7 @@ const resources = {
5055
no_hints: '申し訳ありませんが、このラボにはヒントがありません。',
5156
no_matching_hint: '申し訳ありませんが、あなたの試みに一致するヒントが見つかりません。',
5257
reset_title: '初期状態をリセットします (現在の試行を破棄します)。',
58+
to_be_completed: '完成する',
5359
try_harder: '「もっと頑張ってください! すぐに諦めないでください。現在の所要時間 (秒): {0}」',
5460
}
5561
},
@@ -87,6 +93,7 @@ function retrieve_t(obj, field) {
8793
return result;
8894
}
8995

96+
// Determine language of document. Set with <html lang="...">.
9097
function determine_locale() {
9198
let lang = document.documentElement.lang;
9299
if (!lang) {
@@ -409,10 +416,10 @@ function makeStamp() {
409416
let hash = cyrb64Hash(resultBeginning);
410417
let gave_up_indicator = '';
411418
if (user_gave_up) { // If user gave up first, subtly indicate this.
412-
// The user could reload later this and cause this marking to be omitted.
419+
// The user could reload this and cause this marking to be omitted.
413420
gave_up_indicator = ' (GA)';
414421
}
415-
return `Completed ${resultBeginning} ${hash}${gave_up_indicator}`;
422+
return `${t('completed')} ${resultBeginning} ${hash}${gave_up_indicator}`;
416423
}
417424

418425
/**
@@ -432,7 +439,7 @@ function runCheck() {
432439
};
433440
// isCorrect is now true only if everything matched
434441
let oldGrade = document.getElementById('grade').innerHTML;
435-
let newGrade = isCorrect ? 'COMPLETE!' : 'to be completed';
442+
let newGrade = isCorrect ? t('complete') : t('to_be_completed');
436443
document.getElementById('grade').innerHTML = newGrade;
437444

438445
if (isCorrect && (oldGrade !== newGrade)) {
@@ -557,17 +564,14 @@ function processHints(requestedHints) {
557564
Array.from(forbiddenFields).join(' '));
558565
}
559566

560-
let newHint = {};
567+
let newHint = { ...hint }; // Copy everything over, incl. translations
561568
newHint.index = hint.index ? Number(hint.index) : 0;
562-
newHint.text = hint.text;
563569
// Precompile all regular expressions & report any failures
564570
if (hint.present) {
565-
newHint.present = hint.present;
566571
newHint.presentRe = processRegex(hint.present,
567572
`hint[${i}].present`, false);
568573
};
569574
if (hint.absent) {
570-
newHint.absent = hint.absent;
571575
newHint.absentRe = processRegex(hint.absent,
572576
`hint[${i}].absent`, false);
573577
};
@@ -715,8 +719,9 @@ function runSelftest() {
715719
// values if the index > 0. We only return hints with the
716720
// given hint index.
717721
actualHint = findHint(example, [hint.index]);
718-
if (actualHint != hint.text) {
719-
alert(`Lab Error: Unexpected hint!\n\nExample:\n${example}\n\nExpected hint:\n${hint.text}\n\nProduced hint:\n${actualHint}\n\nExpected (passing example)=${JSON.stringify(expected)}\n\ntestAttempt=${JSON.stringify(testAttempt)}\nFailing hint=${JSON.stringify(hint)}`);
722+
expectedHint = retrieve_t(hint, 'text');
723+
if (actualHint != expectedHint) {
724+
alert(`Lab Error: Unexpected hint!\n\nExample:\n${example}\n\n\nExpected hint:\n${expectedHint}\n\nActual hint:\n${actualHint}\n\nExample:\n${JSON.stringify(example)}\n\nFailing hint=${JSON.stringify(hint)}`);
720725
};
721726
};
722727
};
@@ -795,15 +800,15 @@ function setupInfo() {
795800
}
796801

797802
function initPage() {
803+
// Set current locale
804+
lang = determine_locale();
805+
798806
// Use configuration info to set up all relevant global values.
799807
setupInfo();
800808

801809
// Run a selftest on page load, to prevent later problems
802810
runSelftest();
803811

804-
// Set current locale
805-
lang = determine_locale();
806-
807812
// Set up user interaction for all attempts.
808813
let current = 0;
809814
while (true) {

docs/labs/ja_hello.html

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html lang="ja">
3+
<head>
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="stylesheet" href="https://best.openssf.org/assets/css/style.css">
7+
<link rel="stylesheet" href="checker.css">
8+
<script src="js-yaml.min.js"></script>
9+
<script src="checker.js"></script>
10+
<script src="hello.js"></script>
11+
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
12+
13+
<!-- See create_labs.md for how to create your own lab! -->
14+
</head>
15+
<body>
16+
<!-- For GitHub Pages formatting: -->
17+
<div class="container-lg px-3 my-5 markdown-body">
18+
<h1>ラボ演習「hello」</h1>
19+
<p>
20+
これは安全なソフトウェアの開発に関するラボ演習です。
21+
詳細については、<a href="introduction.html" target="_blank">概要を参照してください。
22+
研究所</a>です。
23+
24+
<p>
25+
<h2>ゴール</h2>
26+
<p>
27+
<b>「Hello, world!」と書いてラボの使い方を学びましょう。プログラム</b>
28+
29+
<p>
30+
<h2>背景</h2>
31+
<p>
32+
33+
<a href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program"
34+
>「ハロー、ワールド!」プログラム</a>
35+
多くの場合、最初に書かれたプログラムは
36+
新しいプログラミング言語またはシステム。
37+
これらのラボがどのように機能するかを確認できるように、ラボを作成します。
38+
39+
<p>
40+
<h2>タスク情報</h2>
41+
<p>
42+
43+
<p>
44+
あなたのタスクは以下のプログラムを変更することです
45+
「Hello, world!」を印刷するには私たちのラボがどのように機能するかを学ぶために。
46+
以下のラベルが付いたボタンを試してください
47+
<i>ヒント</i><i>リセット</i><i>諦め</i>
48+
49+
<p>
50+
正解すると、ポップアップ通知が表示されます。
51+
入力ボックスの背景色が変わり、
52+
「インタラクティブ ラボ」の見出しが「<i>完了!</i>」に変わります。
53+
54+
<p>
55+
<h2>インタラクティブラボ (<span id="grade"></span>)</h2>
56+
<p>
57+
<b>「Hello, World!」を出力するには、以下のコードを変更してください。
58+
(引用符は含まれません)
59+
Node.js 上の JavaScript について学びながら、 ラボの仕組みも学びましょう</b>
60+
<p>
61+
<!--
62+
You can use this an example for new labs.
63+
For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use
64+
<textarea id="attempt" rows="2" cols="65">...</textarea>
65+
-->
66+
<form id="lab">
67+
<pre><code
68+
><input id="attempt0" type="text" size="60" spellcheck="false"
69+
value='console.log("Goodbye.");'>
70+
</code></pre>
71+
<button type="button" class="hintButton">ヒント</button>
72+
<button type="button" class="resetButton">リセット</button>
73+
<button type="button" class="giveUpButton">あきらめる</button>
74+
<br><br>
75+
<p>
76+
<i>このラボは、David A. Wheeler によって開発されました。
77+
<a href="https://www.linuxfoundation.org/"
78+
> Linux Foundation</a></i>
79+
<br><br>
80+
<p id="correctStamp" class="small">
81+
<textarea id="debugData" class="displayNone" rows="20" cols="65" readonly>
82+
</textarea>
83+
</form>
84+
85+
</div><!-- End GitHub pages formatting -->
86+
</body>
87+
</html>

0 commit comments

Comments
 (0)