Skip to content

Commit

Permalink
fix(locale): make correct locale use (#479)
Browse files Browse the repository at this point in the history
* feat(config): add default locale

* fix(locale): use correct locale helper to set locale on start app

* refactor(screens): rename language with locale

* fix(locale): make locale definition correct for moment
  • Loading branch information
lex111 authored and Houssein Djirdeh committed Oct 16, 2017
1 parent eaba489 commit 3a6879f
Show file tree
Hide file tree
Showing 41 changed files with 664 additions and 674 deletions.
7 changes: 3 additions & 4 deletions App.js
Expand Up @@ -15,8 +15,7 @@ import md5 from 'md5';
import codePush from 'react-native-code-push';

import { colors } from 'config';
import { configureLocale } from 'utils';
import { determineLanguage } from 'locale';
import { getCurrentLocale, configureLocale } from 'utils';
import { GitPoint } from './routes';
import { configureStore } from './root.store';

Expand All @@ -39,9 +38,9 @@ if (console) {

class App extends Component {
static async initLocale() {
const language = await determineLanguage();
const locale = await getCurrentLocale();

configureLocale(language);
configureLocale(locale);
}

constructor() {
Expand Down
4 changes: 2 additions & 2 deletions routes.js
Expand Up @@ -133,12 +133,12 @@ const sharedRoutes = {
screen: IssueScreen,
navigationOptions: ({ navigation }) => {
const issueNumberRegex = /issues\/([0-9]+)(#|$)/;
const { issue, issueURL, isPR, language } = navigation.state.params;
const { issue, issueURL, isPR, locale } = navigation.state.params;
const number = issue ? issue.number : issueURL.match(issueNumberRegex)[1];
const langKey = isPR ? 'pullRequest' : 'issue';
const langTitle = translate(
`issue.main.screenTitles.${langKey}`,
language
locale
);

return {
Expand Down
13 changes: 6 additions & 7 deletions src/auth/auth.action.js
@@ -1,8 +1,7 @@
import { AsyncStorage } from 'react-native';

import uniqby from 'lodash.uniqby';
import { delay, resetNavigationTo, configureLocale } from 'utils';
import { saveLanguage } from 'locale';
import { delay, resetNavigationTo, configureLocale, saveLocale } from 'utils';

import {
fetchAccessToken,
Expand All @@ -18,7 +17,7 @@ import {
GET_AUTH_USER,
GET_AUTH_ORGS,
GET_EVENTS,
CHANGE_LANGUAGE,
CHANGE_LOCALE,
GET_AUTH_STAR_COUNT,
} from './auth.type';

Expand Down Expand Up @@ -160,11 +159,11 @@ export const getUserEvents = user => {
};
};

export const changeLanguage = lang => {
export const changeLocale = locale => {
return dispatch => {
dispatch({ type: CHANGE_LANGUAGE.SUCCESS, payload: lang });
dispatch({ type: CHANGE_LOCALE.SUCCESS, payload: locale });

saveLanguage(lang);
configureLocale(lang);
saveLocale(locale);
configureLocale(locale);
};
};
10 changes: 5 additions & 5 deletions src/auth/auth.reducer.js
@@ -1,11 +1,11 @@
import { getLanguage } from 'locale';
import { getLocale } from 'utils';
import {
LOGIN,
LOGOUT,
GET_AUTH_USER,
GET_AUTH_ORGS,
GET_EVENTS,
CHANGE_LANGUAGE,
CHANGE_LOCALE,
GET_AUTH_STAR_COUNT,
} from './auth.type';

Expand All @@ -18,7 +18,7 @@ const initialState = {
hasInitialUser: false,
orgs: [],
events: [],
language: getLanguage(),
locale: getLocale(),
isPendingUser: false,
isPendingOrgs: false,
isPendingEvents: false,
Expand Down Expand Up @@ -132,10 +132,10 @@ export const authReducer = (state = initialState, action = {}) => {
error: action.payload,
isPendingEvents: false,
};
case CHANGE_LANGUAGE.SUCCESS:
case CHANGE_LOCALE.SUCCESS:
return {
...state,
language: action.payload,
locale: action.payload,
};
default:
return state;
Expand Down
4 changes: 2 additions & 2 deletions src/auth/auth.selectors.js
Expand Up @@ -2,7 +2,7 @@ import { createSelector } from 'reselect';

export const getAuthFromStore = state => state.auth;

export const getAuthLanguage = createSelector(
export const getAuthLocale = createSelector(
getAuthFromStore,
auth => auth.getAuthLanguage
auth => auth.locale
);
2 changes: 1 addition & 1 deletion src/auth/auth.type.js
Expand Up @@ -5,5 +5,5 @@ export const LOGOUT = createActionSet('LOGOUT');
export const GET_AUTH_USER = createActionSet('GET_AUTH_USER');
export const GET_AUTH_ORGS = createActionSet('GET_AUTH_ORGS');
export const GET_EVENTS = createActionSet('GET_EVENTS');
export const CHANGE_LANGUAGE = createActionSet('CHANGE_LANGUAGE');
export const CHANGE_LOCALE = createActionSet('CHANGE_LOCALE');
export const GET_AUTH_STAR_COUNT = createActionSet('GET_AUTH_STAR_COUNT');
22 changes: 11 additions & 11 deletions src/auth/screens/auth-profile.screen.js
Expand Up @@ -26,7 +26,7 @@ import { emojifyText, openURLInView, translate } from 'utils';
const mapStateToProps = state => ({
user: state.auth.user,
orgs: state.auth.orgs,
language: state.auth.language,
locale: state.auth.locale,
starCount: state.auth.starCount,
isPendingUser: state.auth.isPendingUser,
isPendingOrgs: state.auth.isPendingOrgs,
Expand Down Expand Up @@ -83,7 +83,7 @@ class AuthProfile extends Component {
getStarCount: Function,
user: Object,
orgs: Array,
language: string,
locale: string,
starCount: string,
isPendingUser: boolean,
isPendingOrgs: boolean,
Expand All @@ -107,7 +107,7 @@ class AuthProfile extends Component {
orgs,
isPendingUser,
isPendingOrgs,
language,
locale,
starCount,
navigation,
hasInitialUser,
Expand All @@ -124,7 +124,7 @@ class AuthProfile extends Component {
initialUser={hasInitialUser ? user : {}}
user={hasInitialUser ? user : {}}
starCount={hasInitialUser ? starCount : ''}
language={language}
locale={locale}
navigation={navigation}
/>
)}
Expand All @@ -139,7 +139,7 @@ class AuthProfile extends Component {
menuIcon="gear"
menuAction={() =>
navigation.navigate('UserOptions', {
title: translate('auth.userOptions.title', language),
title: translate('auth.userOptions.title', locale),
})}
>
{isPending && (
Expand All @@ -153,7 +153,7 @@ class AuthProfile extends Component {
{hasInitialUser &&
user.bio &&
user.bio !== '' && (
<SectionList title={translate('common.bio', language)}>
<SectionList title={translate('common.bio', locale)}>
<ListItem
subtitle={emojifyText(user.bio)}
subtitleStyle={styles.listSubTitle}
Expand All @@ -163,15 +163,15 @@ class AuthProfile extends Component {
)}

{!isPending && (
<EntityInfo entity={user} orgs={orgs} navigation={navigation} />
<EntityInfo entity={user} orgs={orgs} navigation={navigation} locale={locale} />
)}

{!isPending && (
<View>
<SectionList
title={translate('common.orgs', language)}
title={translate('common.orgs', locale)}
noItems={orgs.length === 0}
noItemsMessage={translate('common.noOrgsMessage', language)}
noItemsMessage={translate('common.noOrgsMessage', locale)}
>
{orgs.map(item => (
<UserListItem
Expand All @@ -181,7 +181,7 @@ class AuthProfile extends Component {
/>
))}
<Text style={styles.note}>
{translate('auth.profile.orgsRequestApprovalTop', language)}
{translate('auth.profile.orgsRequestApprovalTop', locale)}
{'\n'}
<Text
style={styles.noteLink}
Expand All @@ -190,7 +190,7 @@ class AuthProfile extends Component {
>
{translate(
'auth.profile.orgsRequestApprovalBottom',
language
locale
)}
</Text>
</Text>
Expand Down

0 comments on commit 3a6879f

Please sign in to comment.