Skip to content
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

Settings: change locale keys to ISO 639-1 #1533

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 67 additions & 28 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,66 @@ export const LNC_MAILBOX_KEYS = [
];

export const LOCALE_KEYS = [
{ key: 'English', value: 'English' },
{ key: 'Español', value: 'Español' },
{ key: 'Português', value: 'Português' },
{ key: 'Français', value: 'Français' },
{ key: 'Čeština', value: 'Čeština' },
{ key: 'Slovenčina', value: 'Slovenčina' },
{ key: 'Deutsch', value: 'Deutsch' },
{ key: 'Polski', value: 'Polski' },
{ key: 'Türkçe', value: 'Türkçe' },
{ key: 'magyar nyelv', value: 'magyar nyelv' },
{ key: '简化字', value: '简化字' },
{ key: 'Nederlands', value: 'Nederlands' },
{ key: 'Bokmål', value: 'Bokmål' },
{ key: 'Svenska', value: 'Svenska' },
{ key: 'ภาษาไทย', value: 'ภาษาไทย' },
{ key: 'украї́нська мо́ва', value: 'украї́нська мо́ва' },
{ key: 'Limba română', value: 'Limba română' },
// in progress
{ key: 'Ελληνικά', value: 'Ελληνικά' },
{ key: 'زبان فارسي', value: 'زبان فارسي' },
{ key: 'Slovenski jezik', value: 'Slovenski jezik' },
{ key: 'русский язык', value: 'русский язык' },
{ key: 'Suomen kieli', value: 'Suomen kieli' },
{ key: 'Italiano', value: 'Italiano' },
{ key: 'Tiếng Việt', value: 'Tiếng Việt' },
{ key: '日本語', value: '日本語' },
{ key: 'עִבְרִית', value: 'עִבְרִית' },
{ key: 'Hrvatski', value: 'Hrvatski' }
{ key: 'en', value: 'English' },
{ key: 'es', value: 'Español' },
{ key: 'pt', value: 'Português' },
{ key: 'fr', value: 'Français' },
{ key: 'cs', value: 'Čeština' },
{ key: 'sk', value: 'Slovenčina' },
{ key: 'de', value: 'Deutsch' },
{ key: 'pl', value: 'Polski' },
{ key: 'tr', value: 'Türkçe' },
{ key: 'hu', value: 'magyar nyelv' },
{ key: 'zh', value: '简化字' },
{ key: 'nl', value: 'Nederlands' },
{ key: 'nb', value: 'Bokmål' },
{ key: 'sv', value: 'Svenska' },
{ key: 'th', value: 'ภาษาไทย' },
{ key: 'uk', value: 'украї́нська мо́ва' },
{ key: 'ro', value: 'Limba română' },
{ key: 'el', value: 'Ελληνικά' },
{ key: 'fa', value: 'زبان فارسي' },
{ key: 'sl', value: 'Slovenski jezik' },
{ key: 'ru', value: 'русский язык' },
{ key: 'fi', value: 'Suomen kieli' },
{ key: 'it', value: 'Italiano' },
{ key: 'vi', value: 'Tiếng Việt' },
{ key: 'jp', value: '日本語' },
{ key: 'he', value: 'עִבְרִית' },
{ key: 'hr', value: 'Hrvatski' }
];

// this mapping is only for migration and does not need to be updated when new languages are added
const localeMigrationMapping: { [oldLocale: string]: string } = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is just for the migration, this doesn't need to be updated, correct? Perhaps a comment should be added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. Added a comment.

English: 'en',
Español: 'es',
Português: 'pt',
Français: 'fr',
Čeština: 'cs',
Slovenčina: 'sk',
Deutsch: 'de',
Polski: 'pl',
Türkçe: 'tr',
'magyar nyelv': 'hu',
简化字: 'zh',
Nederlands: 'nl',
Bokmål: 'nb',
Svenska: 'sv',
ภาษาไทย: 'th',
'украї́нська мо́ва': 'uk',
'Limba română': 'ro',
Ελληνικά: 'el',
'زبان فارسي': 'fa',
'Slovenski jezik': 'sl',
'русский язык': 'ru',
'Suomen kieli': 'fi',
Italiano: 'it',
'Tiếng Việt': 'vi',
日本語: 'jp',
עִבְרִית: 'he',
Hrvatski: 'hr'
};

export const CURRENCY_KEYS = [
{
key: '🇺🇸 US Dollar (USD)',
Expand Down Expand Up @@ -798,6 +828,15 @@ export default class SettingsStore {
this.settings.fiatEnabled = true;
}

// migrate locale to ISO 639-1
myxmaster marked this conversation as resolved.
Show resolved Hide resolved
if (
this.settings.locale != null &&
localeMigrationMapping[this.settings.locale]
) {
this.settings.locale =
localeMigrationMapping[this.settings.locale];
}

const node: any =
this.settings.nodes &&
this.settings.nodes[this.settings.selectedNode || 0];
Expand Down
52 changes: 26 additions & 26 deletions utils/LocaleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,57 +65,57 @@ export function localeString(localeString: string): any {
const { locale } = settings;

switch (locale) {
case 'Español':
case 'es':
return Spanish[localeString] || English[localeString];
case 'Português':
case 'pt':
return BrazilianPortuguese[localeString] || English[localeString];
case 'Türkçe':
case 'tr':
return Turkish[localeString] || English[localeString];
case 'Slovenčina':
case 'sk':
return Slovak[localeString] || English[localeString];
case 'Čeština':
case 'cs':
return Czech[localeString] || English[localeString];
case 'Deutsch':
case 'de':
return German[localeString] || English[localeString];
case 'Ελληνικά':
case 'el':
return Greek[localeString] || English[localeString];
case 'Bokmål':
case 'nb':
return NorwegianBokmal[localeString] || English[localeString];
case 'Svenska':
case 'sv':
return Swedish[localeString] || English[localeString];
case 'ภาษาไทย':
case 'th':
return Thai[localeString] || English[localeString];
case 'украї́нська мо́ва':
case 'uk':
return Ukranian[localeString] || English[localeString];
case 'Limba română':
case 'ro':
return Romanian[localeString] || English[localeString];
case 'Polski':
case 'pl':
return Polish[localeString] || English[localeString];
case 'زبان فارسي':
case 'fa':
return Persian[localeString] || English[localeString];
case 'Français':
case 'fr':
return French[localeString] || English[localeString];
case 'Nederlands':
case 'nl':
return Dutch[localeString] || English[localeString];
case 'Magyar nyelv':
case 'hu':
return Hungarian[localeString] || English[localeString];
case '简化字':
case 'zh':
return SimplifiedChinese[localeString] || English[localeString];
case 'Slovenski jezik':
case 'sl':
return Slovenian[localeString] || English[localeString];
case 'русский язык':
case 'ru':
return Russian[localeString] || English[localeString];
case 'Suomen kieli':
case 'fi':
return Finnish[localeString] || English[localeString];
case 'Italiano':
case 'it':
return Italian[localeString] || English[localeString];
case 'Tiếng Việt':
case 'vi':
return Vietnamese[localeString] || English[localeString];
case '日本語':
case 'jp':
return Japanese[localeString] || English[localeString];
case 'עִבְרִית':
case 'he':
return Hebrew[localeString] || English[localeString];
case 'Hrvatski':
case 'hr':
return Croatian[localeString] || English[localeString];
default:
return English[localeString];
Expand Down
4 changes: 2 additions & 2 deletions views/Settings/Language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class Language extends React.Component<
<ListItem.Title
style={{
color:
selectedLocale === item.value ||
selectedLocale === item.key ||
(!selectedLocale &&
item.value === 'English')
? themeColor('highlight')
Expand All @@ -127,7 +127,7 @@ export default class Language extends React.Component<
{item.value}
</ListItem.Title>
</ListItem.Content>
{(selectedLocale === item.value ||
{(selectedLocale === item.key ||
(!selectedLocale &&
item.value === 'English')) && (
<View style={{ textAlign: 'right' }}>
Expand Down