homebridge-econet-rheem
Version:
Homebridge plugin for control of Rheem and Ruud thermostats and water heaters
35 lines • 1.12 kB
JavaScript
import { readFileSync } from 'fs';
import merge from 'lodash.merge';
import en from './en.js';
export var Language;
(function (Language) {
Language["EN"] = "en";
})(Language || (Language = {}));
const Translations = {
[Language.EN]: en,
};
export function getTranslation(language) {
return Translations[language] ?? {};
}
export function getStrings(language) {
return merge({}, en, getTranslation(language));
}
export let strings = en;
export function setLanguage(configPath) {
let isoLang;
try {
const systemConfig = readFileSync(configPath, { encoding: 'utf8' });
isoLang = JSON.parse(systemConfig).platforms.filter((c) => c.platform === 'config')[0].lang;
}
catch {
// nothing
}
if (isoLang === undefined || isoLang.trim().length === 0 || isoLang === 'auto') {
isoLang = Intl.DateTimeFormat().resolvedOptions().locale.split('-')[0];
}
const currentLanguage = isoLang in Translations ? isoLang : Language.EN;
if (currentLanguage !== Language.EN) {
strings = getStrings(currentLanguage);
}
}
//# sourceMappingURL=i18n.js.map