From a8c46094de7c07a91168ec258867ac968e44f44f Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 17 Sep 2020 08:50:27 -0300 Subject: [PATCH] [CHORE] Simplify i18n files (#2472) --- app/i18n/index.js | 83 +++++++++++++++++-------- app/i18n/locales/{zh_TW.js => zh-TW.js} | 0 app/views/LanguageView/index.js | 42 +------------ 3 files changed, 58 insertions(+), 67 deletions(-) rename app/i18n/locales/{zh_TW.js => zh-TW.js} (100%) diff --git a/app/i18n/index.js b/app/i18n/index.js index 4c4b32ba2..578c0bc45 100644 --- a/app/i18n/index.js +++ b/app/i18n/index.js @@ -2,33 +2,64 @@ import i18n from 'i18n-js'; import { I18nManager } from 'react-native'; import * as RNLocalize from 'react-native-localize'; -import en from './locales/en'; -import ru from './locales/ru'; -import fr from './locales/fr'; -import de from './locales/de'; -import nl from './locales/nl'; -import ptBR from './locales/pt-BR'; -import zhCN from './locales/zh-CN'; -import zhTW from './locales/zh_TW'; -import ptPT from './locales/pt-PT'; -import esES from './locales/es-ES'; -import it from './locales/it'; -import ja from './locales/ja'; +export const LANGUAGES = [ + { + label: 'English', + value: 'en', + file: require('./locales/en').default + }, { + label: '简体中文', + value: 'zh-cn', + file: require('./locales/zh-CN').default + }, { + label: '繁體中文', + value: 'zh-tw', + file: require('./locales/zh-TW').default + }, { + label: 'Deutsch', + value: 'de', + file: require('./locales/de').default + }, { + label: 'Español (ES)', + value: 'es', + file: require('./locales/es-ES').default + }, { + label: 'Français', + value: 'fr', + file: require('./locales/fr').default + }, { + label: 'Português (BR)', + value: 'pt-br', + file: require('./locales/pt-BR').default + }, { + label: 'Português (PT)', + value: 'pt', + file: require('./locales/pt-PT').default + }, { + label: 'Russian', + value: 'ru', + file: require('./locales/ru').default + }, { + label: 'Nederlands', + value: 'nl', + file: require('./locales/nl').default + }, { + label: 'Italiano', + value: 'it', + file: require('./locales/it').default + }, { + label: '日本語', + value: 'ja', + file: require('./locales/ja').default + } +]; -i18n.translations = { - en, - ru, - 'pt-BR': ptBR, - 'zh-CN': zhCN, - 'zh-TW': zhTW, - fr, - de, - 'pt-PT': ptPT, - 'es-ES': esES, - nl, - it, - ja -}; +const translations = LANGUAGES.reduce((ret, item) => { + ret[item.value] = item.file; + return ret; +}, {}); + +i18n.translations = translations; i18n.fallbacks = true; const defaultLanguage = { languageTag: 'en', isRTL: false }; diff --git a/app/i18n/locales/zh_TW.js b/app/i18n/locales/zh-TW.js similarity index 100% rename from app/i18n/locales/zh_TW.js rename to app/i18n/locales/zh-TW.js diff --git a/app/views/LanguageView/index.js b/app/views/LanguageView/index.js index 416edd35d..2bc683605 100644 --- a/app/views/LanguageView/index.js +++ b/app/views/LanguageView/index.js @@ -4,7 +4,7 @@ import { FlatList } from 'react-native'; import { connect } from 'react-redux'; import RocketChat from '../../lib/rocketchat'; -import I18n from '../../i18n'; +import I18n, { LANGUAGES } from '../../i18n'; import { showErrorAlert } from '../../utils/info'; import log, { logEvent, events } from '../../utils/log'; import { setUser as setUserAction } from '../../actions/login'; @@ -20,46 +20,6 @@ import { getUserSelector } from '../../selectors/login'; import database from '../../lib/database'; import SafeAreaView from '../../containers/SafeAreaView'; -const LANGUAGES = [ - { - label: 'English', - value: 'en' - }, { - label: '简体中文', - value: 'zh-CN' - }, { - label: '繁體中文', - value: 'zh-TW' - }, { - label: 'Deutsch', - value: 'de' - }, { - label: 'Español (ES)', - value: 'es-ES' - }, { - label: 'Français', - value: 'fr' - }, { - label: 'Português (BR)', - value: 'pt-BR' - }, { - label: 'Português (PT)', - value: 'pt-PT' - }, { - label: 'Russian', - value: 'ru' - }, { - label: 'Nederlands', - value: 'nl' - }, { - label: 'Italiano', - value: 'it' - }, { - label: '日本語', - value: 'ja' - } -]; - class LanguageView extends React.Component { static navigationOptions = () => ({ title: I18n.t('Change_Language')