Skip to content
Permalink
Browse files

adds experimental language flags

  • Loading branch information...
valpinkman committed Apr 30, 2019
1 parent 61fb585 commit 679b62106231c7bdd046aa8349b3312e1ff29118
Showing with 50 additions and 43 deletions.
  1. +42 −41 src/components/SettingsPage/LanguageSelect.js
  2. +2 −2 src/config/languages.js
  3. +6 −0 src/helpers/experimental.js
@@ -1,15 +1,16 @@
// @flow

import React, { Fragment, PureComponent } from 'react'
import React from 'react'
import moment from 'moment'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import { connect } from 'react-redux'
import { setLanguage } from 'actions/settings'
import { langAndRegionSelector } from 'reducers/settings'
import languageKeys from 'config/languages'
import { allLanguages, prodStableLanguages } from 'config/languages'
import Track from 'analytics/Track'
import Select from 'components/base/Select'
import useEnv from 'hooks/useEnv'

type Props = {
t: T,
@@ -19,52 +20,52 @@ type Props = {
i18n: Object,
}

class LanguageSelect extends PureComponent<Props> {
languageLabels = {
en: 'English',
fr: 'Français',
es: 'Español',
ko: '한국어',
zh: '简体中文',
ja: '日本語',
ru: 'Русский',
}
const languageLabels = {
en: 'English',
fr: 'Français',
es: 'Español',
ko: '한국어',
zh: '简体中文',
ja: '日本語',
ru: 'Русский',
}

const LanguageSelect = ({ i18n, setLanguage, language, useSystem, t }: Props) => {
const debugLanguage = useEnv('DEBUG_ALL_LANGS')

const languages = [{ value: null, label: t(`language.system`) }].concat(
(debugLanguage ? allLanguages : prodStableLanguages).map(key => ({
value: key,
label: languageLabels[key],
})),
)

const currentLanguage = useSystem ? languages[0] : languages.find(l => l.value === language)

handleChangeLanguage = ({ value: languageKey }: *) => {
const { i18n, setLanguage } = this.props
const handleChangeLanguage = ({ value: languageKey }: *) => {
i18n.changeLanguage(languageKey)
moment.locale(languageKey)
setLanguage(languageKey)
}

languages = [{ value: null, label: this.props.t(`language.system`) }].concat(
languageKeys.map(key => ({ value: key, label: this.languageLabels[key] })),
return (
<>
<Track
onUpdate
event="LanguageSelect"
currentRegion={currentLanguage && currentLanguage.value}
/>
<Select
small
minWidth={250}
isSearchable={false}
onChange={handleChangeLanguage}
renderSelected={item => item && item.name}
value={currentLanguage}
options={languages}
/>
</>
)

render() {
const { language, useSystem } = this.props
const currentLanguage = useSystem
? this.languages[0]
: this.languages.find(l => l.value === language)
return (
<Fragment>
<Track
onUpdate
event="LanguageSelect"
currentRegion={currentLanguage && currentLanguage.value}
/>
<Select
small
minWidth={250}
isSearchable={false}
onChange={this.handleChangeLanguage}
renderSelected={item => item && item.name}
value={currentLanguage}
options={this.languages}
/>
</Fragment>
)
}
}

export default translate()(
@@ -1,7 +1,7 @@
// @flow
import { LEDGER_DEBUG_ALL_LANGS } from 'config/constants'

const allLanguages = ['en', 'es', 'fr', 'ja', 'ko', 'ru', 'zh']
const prodStableLanguages = ['en']
export const allLanguages = ['en', 'es', 'fr', 'ja', 'ko', 'ru', 'zh']
export const prodStableLanguages = ['en']
const languages = LEDGER_DEBUG_ALL_LANGS ? allLanguages : prodStableLanguages
export default languages
@@ -55,6 +55,12 @@ export const experimentalFeatures: Feature[] = [
title: 'Pre-release apps',
description: 'Enable pre-release apps in the Manager',
},
{
type: 'toggle',
name: 'DEBUG_ALL_LANGS',
title: 'Translation testing',
description: 'Adds unreleased languages to the language list in the general settings tab.',
},
]

const lsKey = 'experimentalFlags'

0 comments on commit 679b621

Please sign in to comment.
You can’t perform that action at this time.