Add function for language code shortening (#156)

Add function for language code shortening
This commit is contained in:
mrdrogdrog 2020-06-06 11:55:41 +02:00 committed by GitHub
parent 1c2dd630d9
commit a376c95fab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,7 @@
import React from 'react'
import { useTranslation } from 'react-i18next'
import moment from 'moment'
import React from 'react'
import { Form } from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
const LanguagePicker: React.FC = () => {
const { i18n } = useTranslation()
@ -11,12 +11,21 @@ const LanguagePicker: React.FC = () => {
await i18n.changeLanguage(event.currentTarget.value)
}
const shortenLanguageCode = (language: string): string => {
const languageWithoutArea = language.substr(0, 2)
if (languageWithoutArea === 'zh') {
return language
} else {
return languageWithoutArea
}
}
return (
<Form.Control
as="select"
size="sm"
className="mb-2 mx-auto w-auto"
value={i18n.language}
value={shortenLanguageCode(i18n.language)}
onChange={onChangeLang}
>
<option value="en">English</option>