-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: dynamically load language locale maps #4089
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { useDebounce } from 'use-debounce' | |
import Wrapper from '../common/layout/Wrapper' | ||
import { Icon, Section, Text } from '../common' | ||
import { LanguageContext } from '../../language/i18n' | ||
import { countryCodes, countryCodeToLocale, languageLabels } from '../../language/locales' | ||
import { CountryFlag } from '../profile/ProfileDataTable' | ||
|
||
// hooks | ||
|
@@ -66,43 +67,6 @@ const PrivacyOption = ({ title, value, field, setPrivacy }) => { | |
</RadioButton.Group> | ||
) | ||
} | ||
const supportedCountryCodes = ['US', 'GB', 'ES', 'FR', 'IT', 'KR', 'BR', 'UA', 'TR', 'VN', 'CN', 'IN', 'ID', 'AR'] | ||
type CountryCode = $ElementType<typeof supportedCountryCodes, number> | ||
|
||
const countryCodeToLocale: { [key: CountryCode]: string } = { | ||
US: 'en', | ||
GB: 'en-gb', | ||
ES: 'es', | ||
FR: 'fr', | ||
IT: 'it', | ||
KR: 'ko', | ||
BR: 'pt-br', | ||
UA: 'uk', | ||
TR: 'tr', | ||
VN: 'vi', | ||
CN: 'zh', | ||
IN: 'hi', | ||
ID: 'id', | ||
AR: 'es-419', | ||
} | ||
|
||
const languageCustomLabels: { [key: CountryCode]: string } = { | ||
US: 'English-US', | ||
GB: 'English-UK', | ||
ES: 'Spanish', | ||
FR: 'French', | ||
IT: 'Italian', | ||
KR: 'Korean', | ||
DE: 'German', | ||
BR: 'Portuguese-Brazilian', | ||
UA: 'Ukrainian', | ||
TR: 'Turkish', | ||
VN: 'Vietnamese', | ||
CN: 'Chinese-Simplified', | ||
IN: 'Hindi', | ||
ID: 'Indonesian', | ||
AR: 'Latin-Spanish', | ||
} | ||
|
||
const getKeyByValue = (object, value) => { | ||
return Object.keys(object).find(key => object[key] === value) | ||
|
@@ -111,7 +75,7 @@ const getKeyByValue = (object, value) => { | |
const DropDownRowComponent = props => { | ||
const { containerStyles, textStyles, children } = props | ||
const { children: countryCode } = children.props | ||
const countryLabel = languageCustomLabels[countryCode] ?? 'Device Default' | ||
const countryLabel = languageLabels[countryCode] ?? 'Device Default' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declare
helper outside component and use it |
||
|
||
return ( | ||
<TouchableOpacity {...containerStyles} onPress={props.onPress}> | ||
|
@@ -291,13 +255,13 @@ const Settings = ({ screenProps, styles, theme, navigation }) => { | |
<Section.Row style={styles.languageRow}> | ||
<View style={styles.languageInputContainer}> | ||
<ModalDropdown | ||
defaultValue={languageCustomLabels[countryCode] ?? t`Select a language...`} | ||
options={[isWeb ? '' : 'DD', ...supportedCountryCodes]} // empty string breaks on native | ||
defaultValue={languageLabels[countryCode] ?? t`Select a language...`} | ||
options={[isWeb ? '' : 'DD', ...countryCodes]} // empty string breaks on native | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we still using this 'DD' ? empty value should mean 'system default'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We removed it but I had to turn it back here (on android) |
||
alignOptionsToRight={true} | ||
saveScrollPosition={false} | ||
showsVerticalScrollIndicator={true} | ||
renderButtonText={option => { | ||
const language = languageCustomLabels[option] ?? 'Device Default' | ||
const language = languageLabels[option] ?? 'Device Default' | ||
return t`${language}` | ||
}} | ||
renderRowComponent={DropDownRowComponent} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the whole list.
lingui is actually based over Android-supported locales which are: https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/localization
(just the underscore char is replaced via dash)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I started an whole map:
how to fill it
you could ask @patpedrosa to do it or work on it if you don't have more prioritised tasks
for now I suggest to fill this map with languages we currently support only then merge PR and open a task to fill the whole list