mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Add function for language code shortening (#156)
Add function for language code shortening
This commit is contained in:
parent
1c2dd630d9
commit
a376c95fab
1 changed files with 12 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
import React from 'react'
|
||||||
import { Form } from 'react-bootstrap'
|
import { Form } from 'react-bootstrap'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
const LanguagePicker: React.FC = () => {
|
const LanguagePicker: React.FC = () => {
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
|
@ -11,12 +11,21 @@ const LanguagePicker: React.FC = () => {
|
||||||
await i18n.changeLanguage(event.currentTarget.value)
|
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 (
|
return (
|
||||||
<Form.Control
|
<Form.Control
|
||||||
as="select"
|
as="select"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="mb-2 mx-auto w-auto"
|
className="mb-2 mx-auto w-auto"
|
||||||
value={i18n.language}
|
value={shortenLanguageCode(i18n.language)}
|
||||||
onChange={onChangeLang}
|
onChange={onChangeLang}
|
||||||
>
|
>
|
||||||
<option value="en">English</option>
|
<option value="en">English</option>
|
||||||
|
|
Loading…
Reference in a new issue