mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01: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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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 getCurrentLanguage = () => i18next.language;
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
import { Dropdown } from "bootstrap";
 | 
			
		||||
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 type { EventData } from "../components/app_context.js";
 | 
			
		||||
import type FNote from "../entities/fnote.js";
 | 
			
		||||
@ -118,7 +118,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
 | 
			
		||||
 | 
			
		||||
    async refreshWithNote(note: FNote) {
 | 
			
		||||
        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.$noteLanguageDesc.text(language.name);
 | 
			
		||||
        this.dropdown.hide();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user