Skip to content

Commit

Permalink
fix: Fixed default language selection (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviroo authored Sep 8, 2022
1 parent a85e28c commit 5b6dc0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { AuthenticationContext } from "./store/authentication-context"
import { LocalizationContextProvider } from "./store/localization-context"
import { loadAllLocales } from "./i18n/i18n-util.sync"
import TypesafeI18n from "./i18n/i18n-react"
import { customLocaleDetector } from "./utils/locale-detector"
export const BUILD_VERSION = "build_version"

export const { link: linkNetworkStatusNotifier, useApolloNetworkStatus } =
Expand Down Expand Up @@ -308,7 +309,7 @@ export const App = (): JSX.Element => {
<AuthenticationContext.Provider value={{ isAppLocked, setAppUnlocked, setAppLocked }}>
<ApolloProvider client={apolloClient}>
<PriceContextProvider>
<TypesafeI18n locale={"en"}>
<TypesafeI18n locale={customLocaleDetector()}>
<LocalizationContextProvider>
<ErrorBoundary FallbackComponent={ErrorScreen}>
<NavigationContainer
Expand Down
17 changes: 12 additions & 5 deletions app/utils/locale-detector.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as RNLocalize from "react-native-localize"

export const customLocaleDetector = () => {
if (RNLocalize.getLocales()) {
return RNLocalize.getLocales()?.map((locale) => {
return getLanguageFromLocale(locale.languageCode)
})
if (
RNLocalize.getLocales() &&
RNLocalize.getLocales().some(
(locale) =>
locale.languageCode?.startsWith("en") ||
locale.languageCode?.startsWith("es") ||
locale.languageCode?.startsWith("fr") ||
locale.languageCode?.startsWith("pt"),
)
) {
return getLanguageFromLocale(RNLocalize.getLocales()[0].languageCode)
}
return ["es"]
return "en"
}

export const getLanguageFromLocale = (locale: string) => {
Expand Down

0 comments on commit 5b6dc0e

Please sign in to comment.