feat: localize interface messages
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
PREFERENCE_KEYS,
|
||||
getStoredPreference
|
||||
} from "../utils/theme-preferences.js";
|
||||
import {getMessage} from "../utils/messages.js";
|
||||
|
||||
const COLOR_SCHEME_SELECTOR_PATTERN = /html\[theme-color-scheme\s*=\s*(['"]?)([^'"\]\s]+)\1\]/g;
|
||||
|
||||
@@ -33,7 +34,7 @@ function getDefinedColorSchemes() {
|
||||
return schemes;
|
||||
}
|
||||
|
||||
function createColorSchemeOption(scheme) {
|
||||
function createColorSchemeOption(scheme, label = scheme) {
|
||||
const option = document.createElement("button");
|
||||
option.className = "color-scheme-option";
|
||||
option.type = "button";
|
||||
@@ -41,12 +42,15 @@ function createColorSchemeOption(scheme) {
|
||||
option.tabIndex = -1;
|
||||
option.dataset.colorScheme = scheme;
|
||||
option.setAttribute("aria-selected", "false");
|
||||
option.textContent = scheme;
|
||||
option.textContent = label;
|
||||
return option;
|
||||
}
|
||||
|
||||
function populateColorSchemeMenu(menu) {
|
||||
menu.replaceChildren(createColorSchemeOption("default"));
|
||||
menu.replaceChildren(createColorSchemeOption(
|
||||
"default",
|
||||
getMessage("defaultColorScheme", "Default")
|
||||
));
|
||||
|
||||
for (const scheme of getDefinedColorSchemes()) {
|
||||
menu.appendChild(createColorSchemeOption(scheme));
|
||||
@@ -71,9 +75,13 @@ export function syncColorSchemePicker() {
|
||||
}
|
||||
|
||||
const selectedScheme = hasStoredOption ? storedScheme : "default";
|
||||
const selectedLabel = selectedScheme === "default"
|
||||
? getMessage("defaultColorScheme", "Default")
|
||||
: selectedScheme;
|
||||
const trigger = picker.querySelector("#color-scheme-trigger");
|
||||
if (trigger) {
|
||||
const description = `选择配色,当前:${selectedScheme}`;
|
||||
const currentLabel = getMessage("currentColorScheme", "Current color scheme");
|
||||
const description = `${currentLabel}: ${selectedLabel}`;
|
||||
trigger.setAttribute("aria-label", description);
|
||||
trigger.title = description;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {terminal} from "../terminal.js";
|
||||
import {getMessage} from "../utils/messages.js";
|
||||
|
||||
const RESOURCE_KEY = "moment";
|
||||
const RESOURCE_GROUP = "moment.halo.run";
|
||||
@@ -74,7 +75,7 @@ function handleUpvote(name) {
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
alert("Network Error");
|
||||
alert(getMessage("networkError", "Network error. Please try again."));
|
||||
};
|
||||
|
||||
xhr.send(JSON.stringify({group: RESOURCE_GROUP, plural: RESOURCE_PLURAL, name: name}));
|
||||
|
||||
+7
-1
@@ -1,5 +1,6 @@
|
||||
import {terminal} from "../terminal.js";
|
||||
import {debounce, toggleClass} from "../utils/dom.js";
|
||||
import {getMessage} from "../utils/messages.js";
|
||||
import tocbot from "tocbot";
|
||||
|
||||
const TOC_SELECTOR = "#toc";
|
||||
@@ -45,7 +46,12 @@ function syncToggleButton(toc = getToc()) {
|
||||
|
||||
const isVisible = toc.classList.contains(TOC_VISIBLE_CLASS);
|
||||
tocToggle.textContent = isVisible ? TOC_CLOSE_ICON : TOC_OPEN_ICON;
|
||||
tocToggle.setAttribute("aria-label", isVisible ? "Hide Table of Contents" : "Show Table of Contents");
|
||||
tocToggle.setAttribute(
|
||||
"aria-label",
|
||||
isVisible
|
||||
? getMessage("hideToc", "Hide table of contents")
|
||||
: getMessage("showToc", "Show table of contents")
|
||||
);
|
||||
|
||||
if (tocToggle.dataset.tocBound === "true") return;
|
||||
tocToggle.addEventListener("click", toggleToc);
|
||||
|
||||
Reference in New Issue
Block a user