Skip to content

Commit

Permalink
Merge pull request #148 from CovidShield/issue/111/device-locale
Browse files Browse the repository at this point in the history
Use system locale as default locale
  • Loading branch information
henrytao-me authored Jun 24, 2020
2 parents c321517 + 59d73ad commit e4dc663
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'CovidShield'
include ':react-native-localize'
project(':react-native-localize').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-localize/android')
include ':react-native-system-setting'
project(':react-native-system-setting').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-system-setting/android')
include ':react-native-sensitive-info'
Expand Down
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ target 'CovidShield' do

pod 'RCTSystemSetting', :path => '../node_modules/react-native-system-setting'

pod 'RNLocalize', :path => '../node_modules/react-native-localize'

target 'CovidShieldTests' do
inherit! :complete
# Pods for testing
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"react-native-background-fetch": "^3.0.4",
"react-native-config": "^1.1.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-localize": "^1.4.0",
"react-native-markdown-display": "^6.1.0",
"react-native-permissions": "^2.1.4",
"react-native-reanimated": "^1.8.0",
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {TestMode} from 'testMode';
import {TEST_MODE, SUBMIT_URL, RETRIEVE_URL, HMAC_KEY, REGION} from 'env';
import {ExposureNotificationServiceProvider} from 'services/ExposureNotificationService';
import {BackendService} from 'services/BackendService';
import {SharedTranslations} from 'locale';
import {SharedTranslations, getSystemLocale} from 'locale';
import {ThemeProvider} from 'shared/theme';

// grabs the ip address
Expand All @@ -33,7 +33,7 @@ if (__DEV__) {
}

const i18nManager = new I18nManager({
locale: 'en',
locale: getSystemLocale(),
onError(error) {
console.log('>>> i18N', error);
},
Expand Down
1 change: 1 addition & 0 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './i18n';
export * from './locale';
export * from './SharedTranslations';
6 changes: 6 additions & 0 deletions src/locale/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as RNLocalize from 'react-native-localize';

export const getSystemLocale = () => {
const locales = RNLocalize.getLocales();
return locales.length > 0 ? locales[0].languageCode : 'en';
};
3 changes: 2 additions & 1 deletion src/services/StorageService/StorageService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AsyncStorage from '@react-native-community/async-storage';
import {Observable} from 'shared/Observable';
import {Region} from 'shared/Region';
import {getSystemLocale} from 'locale';

export enum Key {
IsOnboarded = 'IsOnboarded',
Expand All @@ -17,7 +18,7 @@ export class StorageService {

constructor() {
this.isOnboarding = new Observable<boolean>(true);
this.locale = new Observable<string>('en');
this.locale = new Observable<string>(getSystemLocale());
this.ready = new Observable<boolean>(false);
this.region = new Observable<Region | undefined>(undefined);
this.init();
Expand Down
3 changes: 2 additions & 1 deletion src/services/StorageService/StorageServiceProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {createContext, useCallback, useContext, useEffect, useMemo, useState} from 'react';
import AsyncStorage from '@react-native-community/async-storage';
import {I18nContext} from '@shopify/react-i18n';
import {getSystemLocale} from 'locale';
import {DevSettings} from 'react-native';

import {StorageService} from './StorageService';
Expand Down Expand Up @@ -45,7 +46,7 @@ export const useStorage = () => {

const reset = useCallback(async () => {
setOnboarded(false);
setLocale('en');
setLocale(getSystemLocale());
setRegion(undefined);
await AsyncStorage.clear();
if (__DEV__) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7155,6 +7155,11 @@ react-native-iphone-x-helper@^1.2.1:
resolved "https://registry.yarnpkg.com/react-native-iphone-x-helper/-/react-native-iphone-x-helper-1.2.1.tgz#645e2ffbbb49e80844bb4cbbe34a126fda1e6772"
integrity sha512-/VbpIEp8tSNNHIvstuA3Swx610whci1Zpc9mqNkqn14DkMbw+ORviln2u0XyHG1kPvvwTNGZY6QpeFwxYaSdbQ==

react-native-localize@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/react-native-localize/-/react-native-localize-1.4.0.tgz#4653596d066d0941c48f5404dc1c0d08b6950443"
integrity sha512-W2MQxm6hzD549ZbZcbWzWtYJseY7S7WR2WgsNhm9ULmbwP7tXFfOTbkJjQoqgPXYSXogKN3srXhntVsNZL0Ksw==

react-native-markdown-display@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/react-native-markdown-display/-/react-native-markdown-display-6.1.0.tgz#13b09b093b38fbc8beb5fd0fa71d5abec702e8ef"
Expand Down

0 comments on commit e4dc663

Please sign in to comment.