diff --git a/app/i18n/index.js b/app/i18n/index.js index 4c4b32ba..578c0bc4 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 416edd35..2bc68360 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')