Skip to content
Permalink
Browse files

[DDW-588] Adds request for detecting user's locale to setup in Profil…

…eStore
  • Loading branch information...
MarcusHurney committed Mar 14, 2019
1 parent 14a9ca2 commit cb91fa0344fcc32bb5e6a9a5629a4b17a7ec0d94
Showing with 20 additions and 2 deletions.
  1. +5 −1 source/main/index.js
  2. +15 −1 source/renderer/app/stores/ProfileStore.js
@@ -17,9 +17,10 @@ import { setupCardano } from './cardano/setup';
import { CardanoNode } from './cardano/CardanoNode';
import { safeExitWithCode } from './utils/safeExitWithCode';
import { buildAppMenus } from './utils/buildAppMenus';
import { getLocale } from './utils/getLocale';
import { getLocale, getDefaultLocale } from './utils/getLocale';
import { ensureXDGDataIsSet } from './cardano/config';
import { rebuildApplicationMenu } from './ipc/rebuild-application-menu';
import { detectUserLocaleChannel } from './ipc/detect-user-locale';
import { CardanoNodeStates } from '../common/types/cardano-node.types';
import type { CheckDiskSpaceResponse } from '../common/types/no-disk-space.types';

@@ -60,6 +61,8 @@ const onAppReady = async () => {
const startTime = new Date().toISOString();
// systemStart refers to the Cardano Demo cluster start time!
const systemStart = parseInt(launcherConfig.configuration.systemStart, 10);
// first checks for japanese locale, otherwise returns english
const defaultLocale = getDefaultLocale();

const systemInfo = logSystemInfo({
cardanoVersion,
@@ -127,6 +130,7 @@ const onAppReady = async () => {
}

getSystemStartTimeChannel.onRequest(() => Promise.resolve(systemStart));
detectUserLocaleChannel.onRequest(() => Promise.resolve(defaultLocale));

getNumberOfEpochsConsolidated();

@@ -13,6 +13,8 @@ import { WalletSupportRequestLogsCompressError } from '../i18n/errors';
import type { LogFiles, CompressedLogStatus } from '../types/LogTypes';
import { generateFileNameWithTimestamp } from '../../../common/utils/files';
import { compressLogsChannel, downloadLogsChannel, getLogsChannel } from '../ipc/logs.ipc';
import { detectUserLocaleChannel } from '../ipc/detect-user-locale';
import { DEFAULT_LOCALES } from '../../../common/types/environment.types';

// TODO: refactor all parts that rely on this to ipc channels!
const { ipcRenderer } = global;
@@ -28,6 +30,7 @@ export default class SettingsStore extends Store {
// { value: 'hr-HR', label: globalMessages.languageCroatian },
];

@observable defaultLocale: string = DEFAULT_LOCALES.english;
@observable bigNumberDecimalFormat = {
decimalSeparator: '.',
groupSeparator: ',',
@@ -73,6 +76,7 @@ export default class SettingsStore extends Store {
this._redirectToMainUiAfterTermsAreAccepted,
this._redirectToMainUiAfterDataLayerMigrationIsAccepted,
]);
this._getDefaultLocale();
this._getTermsOfUseAcceptance();
this._getDataLayerMigrationAcceptance();
}
@@ -84,7 +88,7 @@ export default class SettingsStore extends Store {
@computed get currentLocale(): string {
const { result } = this.getProfileLocaleRequest.execute();
if (this.isCurrentLocaleSet) return result;
return 'en-US'; // default
return this.defaultLocale;
}

@computed get hasLoadedCurrentLocale(): boolean {
@@ -156,6 +160,12 @@ export default class SettingsStore extends Store {
);
}

_getDefaultLocale = async () => {
this._onReceiveDefaultLocale(
await detectUserLocaleChannel.request()
);
};

_updateLocale = async ({ locale }: { locale: string }) => {
await this.setProfileLocaleRequest.execute(locale);
await this.getProfileLocaleRequest.execute();
@@ -318,6 +328,10 @@ export default class SettingsStore extends Store {
}
});

@action _onReceiveDefaultLocale = (defaultLocale: string) => {
this.defaultLocale = defaultLocale;
};

@action _reset = () => {
this.error = null;
this.compressedLogsFilePath = null;

0 comments on commit cb91fa0

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