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
23 changes: 23 additions & 0 deletions docs/assets/js/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

/**
* Tiny page i18n helper.
* Language comes from <html lang="..."> (set by Material / mkdocs-static-i18n).
* Tables: { key: { ru: "...", en: "...", ... } }, placeholders {0}, {1}, ...
*/
function pageI18n(table, fallback) {
const lang = (document.documentElement.lang || fallback || "ru").toLowerCase();
const fb = fallback || "ru";

return {
lang: lang,
t: function (key) {
const entry = table[key] || {};
let s = entry[lang] || entry[fb] || "";
for (let i = 1; i < arguments.length; i++) {
s = s.split("{" + (i - 1) + "}").join(arguments[i]);
}
return s;
}
};
}
33 changes: 23 additions & 10 deletions docs/assets/js/longCoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ let curSelectedByte = -1;
let defaultByteSize = 30;
let labelsFromFile = null;

const lcI18n = pageI18n({
wrongSymbols: {
ru: "Кодировка содержит неверные символы. Поддерживаются только латинские буквы A-F и цифры 0-9.",
en: "Coding has wrong symbols. Latin characters A-F and digits 0-9 are allowed."
},
oddLength: {
ru: "Неверное значение. Кодировка должна содержать чётное количество символов.",
en: "Incorrect value. Coding should have even number of symbols."
},
bytesHeader: {
ru: "Байты",
en: "Bytes"
},
badValueFormat: {
ru: "{0} - неверный формат введенного значения!",
en: "{0} - incorrect value!"
}
});

// ========== Additional methods ==========

function cleanHexValue(str) {
Expand Down Expand Up @@ -139,18 +158,12 @@ function checkOrig() {
}
return true;
} else {
alert(
"Кодировка содержит неверные символы. Поддерживаются только латинские буквы A-F и цифры 0-9. " +
"Coding has wrong symbols. Latin characters A-F and digits 0-9 are allowed."
);
alert(lcI18n.t("wrongSymbols"));
clearFields();
}
} else {
if (orig.length > 0) {
alert(
"Неверное значение. Кодировка должна содержать чётное количество символов. " +
"Incorrect value. Coding should have even number of symbols."
);
alert(lcI18n.t("oddLength"));
}
clearFields();
}
Expand Down Expand Up @@ -490,7 +503,7 @@ function createByteDescription(countOfBytes) {
const lines = Math.ceil(countOfBytes / bytesPerLine);

let html = "<table class=\"bordered\">";
html += "<tr><th colspan=\"" + colsFirstLine + "\">Байты / Bytes</th></tr>";
html += "<tr><th colspan=\"" + colsFirstLine + "\">" + lcI18n.t("bytesHeader") + "</th></tr>";

for (let line = 0; line < lines; line++) {
const start = line * bytesPerLine;
Expand Down Expand Up @@ -606,7 +619,7 @@ function wireByteEvents() {
function setByte(ctrl, byteIndex) {
const regexp = /^[0-9a-fA-F]*$/;
if (!regexp.test(ctrl.value)) {
alert(ctrl.value + " - неверный формат введенного значения! Incorrect value!");
alert(lcI18n.t("badValueFormat", ctrl.value));
ctrl.value = "00";
} else {
ctrl.value = ctrl.value.toUpperCase();
Expand Down
110 changes: 81 additions & 29 deletions docs/assets/js/tiresGenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
"use strict";

const tgI18n = pageI18n({
tireSetIndividual: {
ru: "Индивидуальная настройка давления в шинах",
en: "Tire set Individual"
},
tireSetHeader: {
ru: "Настройка давления в шинах: #{0}",
en: "Tire set: #{0}"
},
fieldName: {
ru: "Имя",
en: "Name"
},
loadSituation: {
ru: "Тип загрузки машины",
en: "Load situation"
},
frontWheels: {
ru: "Передние колеса",
en: "Front wheels"
},
rearWheels: {
ru: "Задние колеса",
en: "Rear wheels"
},
fullLoad: {
ru: "Полная загрузка",
en: "Full load"
},
standardLoad: {
ru: "Стандартная загрузка",
en: "Standard load"
},
comfortLoad: {
ru: "Комфортная загрузка",
en: "Comfort load"
},
needMoreThanZero: {
ru: "Количество комплектов шин должно быть больше 0.",
en: "Number of tire sets should be greater than 0."
},
nameInvalid: {
ru: "Имя конфигурации #{0} может содержать только латинские буквы, цифры, пробел, / и +.",
en: "Configuration name #{0} should have only latin letters, numbers, space, / and +."
},
loadConfigPrompt: {
ru: "Восстановление конфигурации\n\nПожалуйста введите код, созданный ранее в данном приложении.",
en: "Load configuration\n\nPlease enter configuration code, created earlier with this tool"
},
invalidConfigCode: {
ru: "Введён некорректный код конфигурации (не base64).",
en: "Invalid configuration code."
},
versionMismatch: {
ru: "Введенный код конфигурации не может быть восстановлен\n\nСоздан версией: {0}\nТекущая версия: {1}",
en: "Configuration was created using an incompatible version of this tool and can not be restored\n\nCreated version: {0}\nCurrent version: {1}"
},
saveConfigPrompt: {
ru: "Сохранить настройки\n\nПожалуйста, сохраните код, приведённый ниже. Он может быть использован для восстановления настроек в любое время.",
en: "Save configuration\n\nPlease backup the configuration code below, it can be used to restore the current configuration at a later point in time."
}
});

function addToDataset(dataset, info) {
dataset.value += info;
}
Expand Down Expand Up @@ -210,7 +273,7 @@ function doGenerate() {
if (Number.isNaN(numTireSets)) numTireSets = 0;

if (numTireSets < 1) {
window.alert("Количество комплектов шин должно быть больше 0.\nNumber of tire sets should be greater than 0.");
window.alert(tgI18n.t("needMoreThanZero"));
return;
}

Expand Down Expand Up @@ -245,10 +308,7 @@ function doGenerate() {
const nameValue = document.getElementById("t" + index + "name").value;

if (!/^(?=.*[a-zA-Z0-9])[a-zA-Z0-9 /+]+$/.test(nameValue)) {
window.alert(
"Имя конфигурации #" + index + " может содержать только латинские буквы, цифры, пробел, / и +.\n" +
"Configuration name should have only latin letters, numbers, space, / and +."
);
window.alert(tgI18n.t("nameInvalid", index));
return;
}

Expand Down Expand Up @@ -387,33 +447,33 @@ function createTireSets() {
html += " <tr>";

if (index === 11) {
html += " <th colspan=\"3\">Индивидуальная настройка давления в шинах / Tire set Individual</th>";
html += " <th colspan=\"3\">" + tgI18n.t("tireSetIndividual") + "</th>";
} else {
html += " <th colspan=\"3\">Настройка давления в шинах / Tire set: #" + index + "</th>";
html += " <th colspan=\"3\">" + tgI18n.t("tireSetHeader", index) + "</th>";
}

html += " </tr>";
html += " <tr>";
html += " <td>Имя</td>";
html += " <td>" + tgI18n.t("fieldName") + "</td>";
html += " <td colspan=\"2\"><input id=\"t" + index + "name\" style=\"height: 25px; color: #ffff00; font-weight: bold; background-color:#4051b5; width: 100%;\"></td>";
html += " </tr>";
html += " <tr>";
html += " <td class=\"sub\"><b>Тип загрузки машины / Load situation</b></td>";
html += " <td class=\"sub\"><b>Передние колеса / Front wheels</b></td>";
html += " <td class=\"sub\"><b>Задние колеса / Rear wheels</b></td>";
html += " <td class=\"sub\"><b>" + tgI18n.t("loadSituation") + "</b></td>";
html += " <td class=\"sub\"><b>" + tgI18n.t("frontWheels") + "</b></td>";
html += " <td class=\"sub\"><b>" + tgI18n.t("rearWheels") + "</b></td>";
html += " </tr>";
html += " <tr>";
html += " <td>Полная загрузка / Full load</td>";
html += " <td>" + tgI18n.t("fullLoad") + "</td>";
html += " <td>" + generatePD("t" + index + "pff") + "</td>";
html += " <td>" + generatePD("t" + index + "prf") + "</td>";
html += " </tr>";
html += " <tr>";
html += " <td>Стандартная загрузка / Standard load</td>";
html += " <td>" + tgI18n.t("standardLoad") + "</td>";
html += " <td>" + generatePD("t" + index + "pfp") + "</td>";
html += " <td>" + generatePD("t" + index + "prp") + "</td>";
html += " </tr>";
html += " <tr id=\"trcomfort" + index + "\">";
html += " <td>Комфортная загрузка / Comfort load</td>";
html += " <td>" + tgI18n.t("comfortLoad") + "</td>";
html += " <td>" + generatePD("t" + index + "pfc") + "</td>";
html += " <td>" + generatePD("t" + index + "prc") + "</td>";
html += " </tr>";
Expand Down Expand Up @@ -444,9 +504,7 @@ const configFields = [

function loadConfig() {
const result = window.prompt(
"Восстановление конфигурации. Load configuration\n\n" +
"Пожалуйста введите код, созданный ранее в данном приложении.\n" +
"Please enter configuration code, created earlier with this tool",
tgI18n.t("loadConfigPrompt"),
""
);

Expand All @@ -456,7 +514,7 @@ function loadConfig() {
try {
code = window.atob(result);
} catch (e) {
window.alert("Введён некорректный код конфигурации (не base64).\nInvalid configuration code.");
window.alert(tgI18n.t("invalidConfigCode"));
return;
}

Expand All @@ -469,11 +527,7 @@ function loadConfig() {

if (data[0] === "configVersion") {
if (data[1] !== configVersion) {
window.alert(
"Введенный код конфигурации не может может быть восстановлен\n" +
"Configuration was created using an incompatible version of this tool and can not be restored\n\n" +
"Created version: " + data[1] + "\nCurrent version: " + configVersion
);
window.alert(tgI18n.t("versionMismatch", data[1], configVersion));
return;
}
} else if (data[0].charAt(0) === "@") {
Expand Down Expand Up @@ -512,13 +566,11 @@ function saveConfig() {
const encoded = window.btoa(code);

window.prompt(
"Сохранить настройки. Save configuration\n\n" +
"Пожалуйста, сохраните код, приведённый ниже. Он может быть использован для восстановления настроек в любое время.\n" +
"Please backup the configuration code below, it can be used to restore the current configuration at a later point in time.",
tgI18n.t("saveConfigPrompt"),
encoded
);
}

window.onload = function () {
createTireSets();
};
// Material navigation.instant re-runs this script but does not fire window.onload again.
// Script is at end of body, so the DOM is ready — call directly.
createTireSets();
18 changes: 13 additions & 5 deletions docs/assets/js/xor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
let decodeString = "c9d2";
let codeLength = 4;

const xorI18n = pageI18n({
lengthMismatch: {
ru: "Длина вводимого значения должна быть {0} символа.",
en: "Input HEX value must be exactly {0} characters long."
},
hexOnly: {
ru: "Допустимы только HEX символы (0-9, A-F).",
en: "Only HEX characters (0-9, A-F) are allowed."
}
});

function init() {
const urlParams = new URLSearchParams(window.location.search);
const codeParam = urlParams.get('code');
Expand All @@ -16,15 +27,12 @@ function calculateXor() {
let result = '';

if (input.length !== codeLength) {
alert(
"Длина вводимого значения должна быть " + codeLength + " символа.\n" +
"Input HEX value must be exactly " + codeLength + " characters long."
);
alert(xorI18n.t("lengthMismatch", codeLength));
return;
}

if (!/^[0-9a-fA-F]+$/.test(input)) {
alert("Допустимы только HEX символы (0-9, A-F).\nOnly HEX characters (0-9, A-F) are allowed.");
alert(xorI18n.t("hexOnly"));
return;
}

Expand Down
Loading
Loading