Merge branch 'main' into feature/draw-on-images

This commit is contained in:
Jonatan Heyman 2026-01-26 10:27:30 +01:00
commit a090607cd6
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import { toRaw, nextTick, watch } from 'vue';
import { defineStore } from "pinia"
import { NoteFormat } from "../common/note-format"
import { toSafeBrowserLocale } from "../util/locale.js"
import { useEditorCacheStore } from "./editor-cache"
import {
SCRATCH_FILE_NAME, WINDOW_FULLSCREEN_STATE, WINDOW_FOCUS_STATE,
@ -397,5 +398,5 @@ export async function initHeynoteStore() {
watch(() => heynoteStore.currentBufferPath, () => heynoteStore.saveTabsState())
watch(() => heynoteStore.openTabs, () => heynoteStore.saveTabsState())
heynoteStore.systemLocale = await window.heynote.getSystemLocale()
heynoteStore.systemLocale = toSafeBrowserLocale(await window.heynote.getSystemLocale())
}

23
src/util/locale.js Normal file
View File

@ -0,0 +1,23 @@
export function toSafeBrowserLocale(locale) {
// first attempt: maybe it's already fine
try {
return Intl.getCanonicalLocales(locale)[0];
} catch { }
// underscores -> hyphens (en_US -> en-US)
locale = locale.replace(/_/g, "-")
// drop ".UTF-8", ".utf8", etc.
locale = locale.replace(/\.[A-Za-z0-9_-]+$/, "")
// If there's an ICU/POSIX modifier like @calendar=... or @euro, we must drop it
// (Intl doesnt understand "@...").
locale = locale.split("@", 1)[0];
// try again after normalization
try {
return Intl.getCanonicalLocales(locale)[0]
} catch { }
// last resort
return navigator.language
}