A way to get Obsidian’s currently set language?

I’m bilingual and switch Obsidian languages quite often. We do have different number formats in UK and Germany, so I’d like to use JS .toLocaleString(undefined, {maximumFractionDigits: 1}) with the language Obsidian is set to, not my OS’s language.

Unfortunately, using undefined decides to use German (de-DE), and navigator.language also returns de when Obsidian runs in English.

It makes a difference seeing 4,096.0 vs 4.096,0

Any insights on how to get that language setting, preferably in the en-GB (or en-UK or de-DE or de-AT …) format?

I’m not sure what the “right way” is, but one possibility is to use moment.locale(). It’ll return whatever language obsidian is set to.

1 Like

Cheers, that’s perfect, since I use moment.js anyway for date calculations! Much appreciated.

1 Like

For whatever odd reason, this now seems to be broken in 0.12.4, see New with 0.12.4: Moment.locale() sticks at "en" even when I switch Obsidian to another language.

So I just discovered you can retrieve the language as it’s set in obsidian with this:

const lang = window.localStorage.getItem('language');

This will return one of these language codes:

en: "English",
zh: "简体中文",
"zh-TW": "繁體中文",
ru: "Pусский",
ko: "한국어",
it: "Italiano",
id: "Bahasa Indonesia",
ro: "Română",
"pt-BR": "Portugues do Brasil",
cz: "čeština",
de: "Deutsch",
es: "Español",
fr: "Français",
no: "Norsk",
pl: "język polski",
pt: "Português",
ja: "日本語",
da: "Dansk",
uk: "Український",
sq: "Shqip",
tr: "Türkçe (kısmi)",
hi: "हिन्दी (आंशिक)",
nl: "Nederlands (gedeeltelijk)",
ar: "العربية (جزئي)"

if lang is null, then the language is English.