Skip to content
Permalink
Browse files

[DDW-588] Adds getDefaultLocale util to check user's OS for locale

  • Loading branch information...
MarcusHurney committed Mar 14, 2019
1 parent d4be944 commit 14a9ca25a060ca4164d4d80e843859ec578fc256
Showing with 23 additions and 4 deletions.
  1. +12 −1 source/common/types/environment.types.js
  2. +11 −3 source/main/utils/getLocale.js
@@ -22,8 +22,15 @@ export type Environment = {
version: string,
isWindows: boolean,
isMacOS: boolean,
isLinux: boolean
isLinux: boolean,
defaultLocale: string,
};

export type DefaultLocales = {
english: string,
japanese: string
};

// constants
export const PRODUCTION = 'production';
export const DEVELOPMENT = 'development';
@@ -39,3 +46,7 @@ export const OS_NAMES = {
[WINDOWS]: 'Windows',
[LINUX]: 'Linux',
};
export const DEFAULT_LOCALES: DefaultLocales = {
english: 'en-US',
japanese: 'ja-JP',
};
@@ -1,15 +1,23 @@
// @flow
import { app } from 'electron';
import Store from 'electron-store';
import { DEFAULT_LOCALES } from '../../common/types/environment.types.js';

const store = new Store();

export const getDefaultLocale = (): string => {
const detectedLocale = app.getLocale();
if (detectedLocale === 'ja') { return DEFAULT_LOCALES.japanese; }
return DEFAULT_LOCALES.english;
};

export const getLocale = (network: string) => {
const english = 'en-US';
const defaultLocale = getDefaultLocale();
try {
const locale = store.get(`${network}-USER-LOCALE`);
if (locale) { return locale; }
return english;
return defaultLocale;
} catch (error) {
return english;
return defaultLocale;
}
};

0 comments on commit 14a9ca2

Please sign in to comment.
You can’t perform that action at this time.