-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from daboigbae/enhancement/add-localization
Added localization
- Loading branch information
Showing
11 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { I18nManager } from "react-native"; | ||
import * as RNLocalize from "react-native-localize"; | ||
|
||
import i18n from "i18n-js"; | ||
import memoize from "lodash.memoize"; | ||
|
||
const translationGetters = { | ||
en: () => require("../utils/translations/en.json"), | ||
es: () => require("../utils/translations/es.json") | ||
// add lanugauges you want to support here | ||
}; | ||
|
||
const translate = memoize( | ||
(key, config) => i18n.t(key, config), | ||
(key, config) => (config ? key + JSON.stringify(config) : key) | ||
); | ||
|
||
export default function useLocalize() { | ||
const setI18nConfig = () => { | ||
const fallback = { languageTag: "en", isRTL: false }; | ||
|
||
const { languageTag, isRTL } = | ||
RNLocalize.findBestAvailableLanguage(Object.keys(translationGetters)) || | ||
fallback; | ||
|
||
translate.cache.clear(); | ||
|
||
I18nManager.forceRTL(isRTL); | ||
|
||
i18n.translations = { [languageTag]: translationGetters[languageTag]() }; | ||
|
||
i18n.locale = languageTag; | ||
}; | ||
|
||
return { setI18nConfig, translate }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"changeButton": "Change this button", | ||
"main": "Main" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"changeButton": "Cambiar este botón", | ||
"main": "Principal" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const TRANSLATIONS = { | ||
CHANGE_BUTTON: "changeButton", | ||
MAIN: "main" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4015,6 +4015,11 @@ human-signals@^3.0.1: | |
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-3.0.1.tgz#c740920859dafa50e5a3222da9d3bf4bb0e5eef5" | ||
integrity sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ== | ||
|
||
[email protected]: | ||
version "3.9.2" | ||
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-3.9.2.tgz#4a015dcfabd4c9fc73115fc2d02d2627e4c15ca5" | ||
integrity sha512-+Gm8h5HL0emzKhRx2avMKX+nKiVPXeaOZm7Euf2/pbbFcLQoJ3zZYiUykAzoRasijCoWos2Kl1tslmScTgAQKw== | ||
|
||
ieee754@^1.1.13: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" | ||
|
@@ -5140,6 +5145,11 @@ lodash.isequal@^4.5.0: | |
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" | ||
integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ== | ||
|
||
[email protected]: | ||
version "4.1.2" | ||
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" | ||
integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag== | ||
|
||
lodash.merge@^4.6.2: | ||
version "4.6.2" | ||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" | ||
|
@@ -5604,7 +5614,7 @@ mkdirp@^0.5.1, mkdirp@~0.5.1: | |
dependencies: | ||
minimist "^1.2.6" | ||
|
||
moment@^2.19.3: | ||
moment@^2.19.3, moment@^2.29.4: | ||
version "2.29.4" | ||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" | ||
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== | ||
|
@@ -6397,6 +6407,11 @@ react-native-keyboard-aware-scroll-view@^0.9.5: | |
prop-types "^15.6.2" | ||
react-native-iphone-x-helper "^1.0.3" | ||
|
||
react-native-localize@^2.2.4: | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/react-native-localize/-/react-native-localize-2.2.4.tgz#3bc46ade48499ab9df61bf17a9b66633a5ba9bb9" | ||
integrity sha512-gVmbyAEQQnBQ8vKlAQchFfIISeId3qT6Lc7LHmKF39nsYWX9KN4PHuG6Hk+7gduMI6IHKeZGKcLsOdh6wvN6cg== | ||
|
||
react-native-reanimated@^2.10.0: | ||
version "2.10.0" | ||
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.10.0.tgz#ed53be66bbb553b5b5e93e93ef4217c87b8c73db" | ||
|