Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI update: Get default language from navigator.language (#1325)

Michael Rademakerdb4dab52971e
diff --git a/ui/app/console_loader/src/index.ts b/ui/app/console_loader/src/index.ts
index e1b140390..ad4562dd1 100644
--- a/ui/app/console_loader/src/index.ts
+++ b/ui/app/console_loader/src/index.ts
@@ -74,7 +74,7 @@ const managerConfig: ManagerConfig = {
realm: Util.getQueryParameter("realm"),
consoleAutoEnable: false,
loadTranslations: ["app", "or"],
- defaultLanguage: Util.getQueryParameter("lang") || "en",
+ defaultLanguage: Util.getBrowserLanguage(),
};
const appConfig: AppConfig<RootState> = {
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index 3ec94ac7f..fc305e084 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -456,7 +456,7 @@ export class Manager implements EventProviderFactory {
// Look for language preference in local storage
const language: string | undefined = !this.console ? undefined : await this.console.retrieveData("LANGUAGE");
const initOptions: InitOptions = {
- lng: language || this.config.defaultLanguage || "en",
+ lng: !language || language === "null" ? this.config.defaultLanguage || "en" : language, // somehow language is "null" sometimes
fallbackLng: "en",
defaultNS: "app",
fallbackNS: "or",
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.ts
index e2cc4b312..16cb942de 100644
--- a/ui/component/core/src/util.ts
+++ b/ui/component/core/src/util.ts
@@ -62,6 +62,10 @@ export interface GeoNotification {
notification?: PushNotificationMessage;
}
+export function getBrowserLanguage(): string {
+ return navigator.language.split("-")[0] || "en";
+}
+
export function getQueryParameters(queryStr: string): any {
return Qs.parse(queryStr, {ignoreQueryPrefix: true});
}
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.ts
index 5dcddebc3..b3bee39e4 100644
--- a/ui/component/or-app/src/index.ts
+++ b/ui/component/or-app/src/index.ts
@@ -194,7 +194,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
managerConfig.realm = Util.getQueryParameter("realm");
}
if (!managerConfig.defaultLanguage) {
- managerConfig.defaultLanguage = Util.getQueryParameter("lang")?.toLowerCase();
+ managerConfig.defaultLanguage = Util.getBrowserLanguage();
}
managerConfig.skipFallbackToBasicAuth = true; // We do this so we can load styling config before displaying basic login
managerConfig.basicLoginProvider = (u:any, p:any) => this.doBasicLogin(u, p);