Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions docs/labs/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ let startTime = Date.now();
let BACKQUOTE = "`"; // Make it easy to use `${BACKQUOTE}`
let DOLLAR = "$"; // Make it easy to use `${DOLLAR}`

// Current language
let lang;
// Current language. Guess English until we learn otherwise.
let lang = "en";

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

// Determine language of document. Set with <html lang="...">.
function determine_locale() {
let lang = document.documentElement.lang;
if (!lang) {
Expand Down Expand Up @@ -409,10 +416,10 @@ function makeStamp() {
let hash = cyrb64Hash(resultBeginning);
let gave_up_indicator = '';
if (user_gave_up) { // If user gave up first, subtly indicate this.
// The user could reload later this and cause this marking to be omitted.
// The user could reload this and cause this marking to be omitted.
gave_up_indicator = ' (GA)';
}
return `Completed ${resultBeginning} ${hash}${gave_up_indicator}`;
return `${t('completed')} ${resultBeginning} ${hash}${gave_up_indicator}`;
}

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

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

let newHint = {};
let newHint = { ...hint }; // Copy everything over, incl. translations
newHint.index = hint.index ? Number(hint.index) : 0;
newHint.text = hint.text;
// Precompile all regular expressions & report any failures
if (hint.present) {
newHint.present = hint.present;
newHint.presentRe = processRegex(hint.present,
`hint[${i}].present`, false);
};
if (hint.absent) {
newHint.absent = hint.absent;
newHint.absentRe = processRegex(hint.absent,
`hint[${i}].absent`, false);
};
Expand Down Expand Up @@ -715,8 +719,9 @@ function runSelftest() {
// values if the index > 0. We only return hints with the
// given hint index.
actualHint = findHint(example, [hint.index]);
if (actualHint != hint.text) {
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)}`);
expectedHint = retrieve_t(hint, 'text');
if (actualHint != expectedHint) {
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)}`);
};
};
};
Expand Down Expand Up @@ -795,15 +800,15 @@ function setupInfo() {
}

function initPage() {
// Set current locale
lang = determine_locale();

// Use configuration info to set up all relevant global values.
setupInfo();

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

// Set current locale
lang = determine_locale();

// Set up user interaction for all attempts.
let current = 0;
while (true) {
Expand Down
87 changes: 87 additions & 0 deletions docs/labs/ja_hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://best.openssf.org/assets/css/style.css">
<link rel="stylesheet" href="checker.css">
<script src="js-yaml.min.js"></script>
<script src="checker.js"></script>
<script src="hello.js"></script>
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">

<!-- See create_labs.md for how to create your own lab! -->
</head>
<body>
<!-- For GitHub Pages formatting: -->
<div class="container-lg px-3 my-5 markdown-body">
<h1>ラボ演習「hello」</h1>
<p>
これは安全なソフトウェアの開発に関するラボ演習です。
詳細については、<a href="introduction.html" target="_blank">概要を参照してください。
研究所</a>です。

<p>
<h2>ゴール</h2>
<p>
<b>「Hello, world!」と書いてラボの使い方を学びましょう。プログラム</b>

<p>
<h2>背景</h2>
<p>
<a href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program"
>「ハロー、ワールド!」プログラム</a>
多くの場合、最初に書かれたプログラムは
新しいプログラミング言語またはシステム。
これらのラボがどのように機能するかを確認できるように、ラボを作成します。

<p>
<h2>タスク情報</h2>
<p>

<p>
あなたのタスクは以下のプログラムを変更することです
「Hello, world!」を印刷するには私たちのラボがどのように機能するかを学ぶために。
以下のラベルが付いたボタンを試してください
<i>ヒント</i>、<i>リセット</i>、<i>諦め</i>。

<p>
正解すると、ポップアップ通知が表示されます。
入力ボックスの背景色が変わり、
「インタラクティブ ラボ」の見出しが「<i>完了!</i>」に変わります。

<p>
<h2>インタラクティブラボ (<span id="grade"></span>)</h2>
<p>
<b>「Hello, World!」を出力するには、以下のコードを変更してください。
(引用符は含まれません)
Node.js 上の JavaScript について学びながら、 ラボの仕組みも学びましょう</b>。
<p>
<!--
You can use this an example for new labs.
For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use
<textarea id="attempt" rows="2" cols="65">...</textarea>
-->
<form id="lab">
<pre><code
><input id="attempt0" type="text" size="60" spellcheck="false"
value='console.log("Goodbye.");'>
</code></pre>
<button type="button" class="hintButton">ヒント</button>
<button type="button" class="resetButton">リセット</button>
<button type="button" class="giveUpButton">あきらめる</button>
<br><br>
<p>
<i>このラボは、David A. Wheeler によって開発されました。
<a href="https://www.linuxfoundation.org/"
> Linux Foundation</a>。</i>
<br><br>
<p id="correctStamp" class="small">
<textarea id="debugData" class="displayNone" rows="20" cols="65" readonly>
</textarea>
</form>

</div><!-- End GitHub pages formatting -->
</body>
</html>