mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-22 20:28:07 +08:00
refactor(client): move finding by locale in service
This commit is contained in:
parent
d582fdea02
commit
f150ec15bc
@ -29,5 +29,15 @@ export function getAvailableLocales() {
|
|||||||
return locales;
|
return locales;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the given locale by ID.
|
||||||
|
*
|
||||||
|
* @param localeId the locale ID to search for.
|
||||||
|
* @returns the corresponding {@link Locale} or `null` if it was not found.
|
||||||
|
*/
|
||||||
|
export function getLocaleById(localeId: string ) {
|
||||||
|
return locales?.find((l) => l.id === localeId);
|
||||||
|
}
|
||||||
|
|
||||||
export const t = i18next.t;
|
export const t = i18next.t;
|
||||||
export const getCurrentLanguage = () => i18next.language;
|
export const getCurrentLanguage = () => i18next.language;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Dropdown } from "bootstrap";
|
import { Dropdown } from "bootstrap";
|
||||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||||
import { getAvailableLocales } from "../services/i18n.js";
|
import { getAvailableLocales, getLocaleById } from "../services/i18n.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import type { EventData } from "../components/app_context.js";
|
import type { EventData } from "../components/app_context.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
@ -118,7 +118,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
async refreshWithNote(note: FNote) {
|
||||||
const currentLanguageId = note.getLabelValue("language") ?? "";
|
const currentLanguageId = note.getLabelValue("language") ?? "";
|
||||||
const language = (this.locales.find((l) => (typeof l === "object" && l.id === currentLanguageId)) as Locale | null) ?? DEFAULT_LOCALE;
|
const language = getLocaleById(currentLanguageId) ?? DEFAULT_LOCALE;
|
||||||
this.currentLanguageId = currentLanguageId;
|
this.currentLanguageId = currentLanguageId;
|
||||||
this.$noteLanguageDesc.text(language.name);
|
this.$noteLanguageDesc.text(language.name);
|
||||||
this.dropdown.hide();
|
this.dropdown.hide();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user