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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ python3 -m http.server 8000

### 进行本地化

翻译文件位于 `data/i18n.json`, 您可以简单的编辑此 JSON 文件进行进行开发
翻译文件位于 `data/i18n.json`, 您可以简单的编辑此 JSON 文件进行翻译

编辑翻译后, 请运行 i18n 检查以确保翻译质量:
编辑完翻译后, 请运行 i18n 检查以确保翻译质量:

~~~bash
python3 tests/check_i18n.py
Expand All @@ -48,6 +48,8 @@ python3 tests/check_i18n.py

### 开发功能

你可以使用任意你所喜爱的编辑器进行开发!

开发完成后, 请执行以下检查确保代码质量:

~~~bash
Expand Down
16 changes: 8 additions & 8 deletions src/events.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { processText } from "./processor.js";
import { state, getState, saveHistory, loadHistory, clearHistoryStorage, saveMode } from "./state.js";
import { setLang, t, applyLanguage } from "./i18n.js";
import { state, saveHistory, clearHistoryStorage, saveMode } from "./state.js";
import { setLang, t } from "./i18n.js";
import { $, escapeHtml, showToast, showModal, hideModal } from "./dom.js";

export async function loadCharLib() {
if (!state.charLib) {
const basePath = window.BASE_PATH || './';
state.charLib = await (await fetch(basePath + "data/character.json")).json();
state.charLib = await (await fetch(`${basePath}data/character.json`)).json();
}
return state.charLib;
}
Expand All @@ -31,7 +31,7 @@ export function initEvents() {
}
});
};
modeRadios.forEach(radio => radio.addEventListener('change', updateMode));
for (const radio of modeRadios) radio.addEventListener('change', updateMode);
modeRadios.forEach(radio => {
if (radio.value === state.currentMode) {
radio.checked = true;
Expand Down Expand Up @@ -78,12 +78,12 @@ export function initEvents() {
customPrefix: $("custom-prefix")?.value || "",
customSuffix: $("custom-suffix")?.value || "",
customRepeat: $("custom-repeat")?.value || "",
customRepeatCount: parseInt($("custom-repeat-count")?.value) || 7,
customRepeatCount: parseInt($("custom-repeat-count")?.value, 10) || 7,
dbvowel: $("dbvowel")?.selected,
dbvowelCount: parseInt($("dbvowel-count")?.value) || 1,
dbvowelCount: parseInt($("dbvowel-count")?.value, 10) || 1,
numcir: $("numcir")?.selected,
addHash: $("addHash")?.selected,
hashLength: parseInt($("hash-length")?.value) || 6,
hashLength: parseInt($("hash-length")?.value, 10) || 6,
preserveEsc: $("preserveEsc")?.selected
};
try {
Expand All @@ -98,7 +98,7 @@ export function initEvents() {
saveHistory(state.processingHistory);
}
} catch (e) {
$("output-text").value = "Error: " + e.message;
$("output-text").value = `Error: ${e.message}`;
}
});

Expand Down
10 changes: 5 additions & 5 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getLangInfo(langCode) {
const nativeName = nativeDisplayNames.of(langCode) || nativeDisplayNames.of(baseCode) || baseCode;

return { name, nativeName };
} catch (e) {
} catch (_e) {
return LANGUAGE_NAMES_FALLBACK[baseCode] || { name: langCode, nativeName: langCode };
}
}
Expand All @@ -46,8 +46,8 @@ function buildSupportedLanguages(i18nData) {
export async function loadI18n() {
const basePath = window.BASE_PATH || './';
const [i18nRes, metaRes] = await Promise.all([
fetch(basePath + "data/i18n.json"),
fetch(basePath + "data/metadata.json")
fetch(`${basePath}data/i18n.json`),
fetch(`${basePath}data/metadata.json`)
]);
state.i18nData = await i18nRes.json();
state.metadata = await metaRes.json();
Expand Down Expand Up @@ -78,14 +78,14 @@ export function setLang(lang) {

export function t() {
const fallbackLang = getLangFallback(state.currentLang);
return state.i18nData[fallbackLang] || state.i18nData["en"];
return state.i18nData[fallbackLang] || state.i18nData.en;
}

export function applyLanguage() {
const txt = t();
if (!txt) return;

const s = getState();
const _s = getState();
const version = state.metadata.version || "";
const titleWithVersion = version ? `${txt.title} v${version}` : txt.title;
document.title = txt.title;
Expand Down
14 changes: 7 additions & 7 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let charLib = null;
async function loadCharLib() {
if (!charLib) {
const basePath = window.BASE_PATH || './';
const response = await fetch(basePath + "data/character.json");
const response = await fetch(`${basePath}data/character.json`);
charLib = await response.json();
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ function addSuffix(result, oriLength, mode, options) {

function suffixMS(result, oriLength) {
let suf = "";
let n = Math.floor(oriLength / 7);
const n = Math.floor(oriLength / 7);

for (let i = 0; i < n; i++) {
suf += "!";
Expand All @@ -126,10 +126,10 @@ function suffixMS(result, oriLength) {
function suffixAndroid(result, oriLength) {
let suf = "";
const n = Math.floor(oriLength / 7);
const numbers = charLib["enNumber"] || ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"];
const numbers = charLib.enNumber || ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"];

for (let i = 0; i < n; i++) {
suf += numbers[i % numbers.length] + " ";
suf += `${numbers[i % numbers.length]} `;
}

return `[${result} ${suf}]`;
Expand Down Expand Up @@ -160,15 +160,15 @@ function suffixCustom(result, oriLength, options) {
const n = Math.floor(oriLength / repeatCount);

for (let i = 0; i <= n; i++) {
suf += repeat + " ";
suf += `${repeat} `;
}

return prefix + result + " " + suf + suffix;
return `${prefix + result} ${suf}${suffix}`;
}

function addHashID(result, length = 6) {
let hash = "";
const alphabet = charLib["alphabet"] || "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const alphabet = charLib.alphabet || "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (let i = 0; i < length; i++) {
hash += alphabet[Math.floor(Math.random() * alphabet.length)];
}
Expand Down