chore(react/settings): port language selection

This commit is contained in:
Elian Doran 2025-08-14 23:25:44 +03:00
parent 48896e67cb
commit 22c3de582f
No known key found for this signature in database
4 changed files with 49 additions and 30 deletions

View File

@ -41,6 +41,7 @@ import AppearanceSettings from "./options/appearance.jsx";
import { renderReactWidget } from "../react/ReactBasicWidget.jsx";
import ImageSettings from "./options/images.jsx";
import AdvancedSettings from "./options/advanced.jsx";
import InternationalizationOptions from "./options/i18n.jsx";
const TPL = /*html*/`<div class="note-detail-content-widget note-detail-printable">
<style>
@ -118,10 +119,7 @@ const CONTENT_WIDGETS: Record<OptionPages | "_backendLog", ((typeof NoteContextA
ShareSettingsOptions,
NetworkConnectionsOptions
],
_optionsLocalization: [
LocalizationOptions,
LanguageOptions
],
_optionsLocalization: <InternationalizationOptions />,
_optionsAdvanced: <AdvancedSettings />,
_backendLog: [
BackendLogWidget

View File

@ -0,0 +1,15 @@
import { ComponentChildren } from "preact";
interface OptionsRowProps {
label: string;
children: ComponentChildren;
}
export default function OptionsRow({ label, children }: OptionsRowProps) {
return (
<div className="option-row">
<label>{label}</label>
{children}
</div>
);
}

View File

@ -0,0 +1,32 @@
import { useMemo } from "preact/hooks";
import { getAvailableLocales, t } from "../../../services/i18n";
import FormSelect from "../../react/FormSelect";
import OptionsRow from "./components/OptionsRow";
import OptionsSection from "./components/OptionsSection";
import { useTriliumOption } from "../../react/hooks";
export default function InternationalizationOptions() {
return (
<OptionsSection title={t("i18n.title")}>
<LocalizationOptions />
</OptionsSection>
)
}
function LocalizationOptions() {
const locales = useMemo(() =>
getAvailableLocales().filter(locale => !locale.contentOnly)
, []);
const [ locale, setLocale ] = useTriliumOption("locale");
return (
<OptionsRow label={t("i18n.language")}>
<FormSelect
values={locales}
keyProperty="id" titleProperty="name"
currentValue={locale} onChange={setLocale}
/>
</OptionsRow>
)
}

View File

@ -6,14 +6,7 @@ import type { OptionMap, Locale } from "@triliumnext/commons";
const TPL = /*html*/`
<div class="options-section">
<h4>${t("i18n.title")}</h4>
<div class="locale-options-container">
<div class="option-row">
<label for="locale-select">${t("i18n.language")}</label>
<select id="locale-select" class="locale-select form-select"></select>
</div>
<div class="option-row electron-only">
<label for="formatting-locale-select">${t("i18n.formatting-locale")}</label>
<select id="formatting-locale-select" class="formatting-locale-select form-select"></select>
@ -123,12 +116,6 @@ export default class LocalizationOptions extends OptionsWidget {
this.$minDaysRow = this.$widget.find(".min-days-row");
this.$localeSelect = this.$widget.find(".locale-select");
this.$localeSelect.on("change", async () => {
const newLocale = this.$localeSelect.val();
await server.put(`options/locale/${newLocale}`);
});
this.$formattingLocaleSelect = this.$widget.find(".formatting-locale-select");
this.$formattingLocaleSelect.on("change", async () => {
const newLocale = this.$formattingLocaleSelect.val();
@ -169,19 +156,6 @@ export default class LocalizationOptions extends OptionsWidget {
async optionsLoaded(options: OptionMap) {
const allLocales = getAvailableLocales();
function buildLocaleItem(locale: Locale, value: string) {
return $("<option>")
.attr("value", value)
.text(locale.name)
}
// Build list of UI locales.
this.$localeSelect.empty();
for (const locale of allLocales.filter(l => !l.contentOnly)) {
this.$localeSelect.append(buildLocaleItem(locale, locale.id));
}
this.$localeSelect.val(options.locale);
// Build list of Electron locales.
this.$formattingLocaleSelect.empty();
for (const locale of allLocales.filter(l => l.electronLocale)) {