Browse Source

feat(i18n): add debug logging for language detection

master
jamaljsr 5 years ago
parent
commit
d0591a48f4
  1. 2
      TODO.md
  2. 14
      src/i18n/index.ts

2
TODO.md

@ -4,8 +4,6 @@ Small Stuff
- fix c-lightning routing after restart - fix c-lightning routing after restart
- fix pasting text in terminal - fix pasting text in terminal
- start/stop individual nodes
- add persisted storage for lang
- implement real-time channel updates from LND via GRPC streams - implement real-time channel updates from LND via GRPC streams
- implement option to auto-mine every X minutes - implement option to auto-mine every X minutes
- switch renovatebot to dependabot and use automatic security fixes - switch renovatebot to dependabot and use automatic security fixes

14
src/i18n/index.ts

@ -1,5 +1,6 @@
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from 'react-i18next';
import { app, remote } from 'electron'; import { app, remote } from 'electron';
import { debug } from 'electron-log';
import i18n from 'i18next'; import i18n from 'i18next';
const defaultLanguage = 'en-US'; const defaultLanguage = 'en-US';
@ -25,15 +26,24 @@ const resources = Object.keys(languages).reduce((acc: { [key: string]: any }, la
}, Object); }, Object);
const detectLang = () => { const detectLang = () => {
debug('Detecting language to use');
const lang = (app || remote.app).getLocale(); const lang = (app || remote.app).getLocale();
debug(' detected from Electron:', lang);
// look for an exact match // look for an exact match
const exact = languages[lang] && lang; const exact = languages[lang] && lang;
if (exact) return exact; if (exact) {
debug(' found an exact language match');
return exact;
}
// look for a match of the first two chars // look for a match of the first two chars
const prefix = lang.slice(0, 2); const prefix = lang.slice(0, 2);
const partial = Object.keys(languages).find(l => l.slice(0, 2) === prefix); const partial = Object.keys(languages).find(l => l.slice(0, 2) === prefix);
if (partial) return partial; if (partial) {
debug(' found a partial language match:', partial);
return partial;
}
// return the fallback language for no matches // return the fallback language for no matches
debug(' no match found, using default language:', defaultLanguage);
return defaultLanguage; return defaultLanguage;
}; };

Loading…
Cancel
Save