Updated lanquage selectors and fixed traditional chinese (#598)
* Updated lanquage selectors and fixed traditional chinese #448 - Modified the language selectors to remain the base language regardless of the translation. - Traditional Chinese also had the wrong code and the name/code swapped. * Removed the split on `-` This was causing an issue with Chinese traditional / simplified. * Updated supported lanquages for chinese removed `zh` and replaced it with `zh-cn`. Modified the supported languages to match the `navigator.language` for chinese. * Updated chinese lanquage codes Updated the Chinese language codes to match the rest of the language codes. * Fixing snapshots and fixing a deprecation problem Co-authored-by: Jesús Espino <jespinog@gmail.com>
This commit is contained in:
parent
8e6a71a028
commit
cc06e0ff93
5 changed files with 30 additions and 35 deletions
|
@ -22,7 +22,7 @@ const CombinedProviders = React.memo((props: Props): JSX.Element => {
|
||||||
const {language, setLanguage, user} = props
|
const {language, setLanguage, user} = props
|
||||||
return (
|
return (
|
||||||
<IntlProvider
|
<IntlProvider
|
||||||
locale={language.split(/[-_]/)[0]}
|
locale={language.split(/[_]/)[0]}
|
||||||
messages={getMessages(language)}
|
messages={getMessages(language)}
|
||||||
>
|
>
|
||||||
<SetLanguageContext.Provider value={setLanguage}>
|
<SetLanguageContext.Provider value={setLanguage}>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {IntlProvider} from 'react-intl'
|
import {IntlProvider} from 'react-intl'
|
||||||
import {render, wait} from '@testing-library/react'
|
import {render, waitFor} from '@testing-library/react'
|
||||||
|
|
||||||
import {act} from 'react-dom/test-utils'
|
import {act} from 'react-dom/test-utils'
|
||||||
|
|
||||||
|
@ -55,11 +55,10 @@ describe('components/properties/user', () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
let container
|
let container
|
||||||
act(() => {
|
await waitFor(() => {
|
||||||
const renderResult = render(component)
|
const renderResult = render(component)
|
||||||
container = renderResult.container
|
container = renderResult.container
|
||||||
})
|
})
|
||||||
await wait()
|
|
||||||
expect(container).toMatchSnapshot()
|
expect(container).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -74,11 +73,10 @@ describe('components/properties/user', () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
let container
|
let container
|
||||||
act(() => {
|
await waitFor(() => {
|
||||||
const renderResult = render(component)
|
const renderResult = render(component)
|
||||||
container = renderResult.container
|
container = renderResult.container
|
||||||
})
|
})
|
||||||
await wait()
|
|
||||||
expect(container).toMatchSnapshot()
|
expect(container).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -93,11 +91,10 @@ describe('components/properties/user', () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
let container: Element | DocumentFragment = {} as Element
|
let container: Element | DocumentFragment = {} as Element
|
||||||
act(() => {
|
await waitFor(() => {
|
||||||
const renderResult = render(component)
|
const renderResult = render(component)
|
||||||
container = renderResult.container
|
container = renderResult.container
|
||||||
})
|
})
|
||||||
await wait()
|
|
||||||
|
|
||||||
if (container) {
|
if (container) {
|
||||||
// this is the actual element where the click event triggers
|
// this is the actual element where the click event triggers
|
||||||
|
|
|
@ -112,7 +112,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Spanish
|
Español
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -127,7 +127,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
German
|
Deutsch
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -142,7 +142,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Japanese
|
日本語
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -157,7 +157,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
French
|
Français
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -172,7 +172,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Dutch
|
Nederlands
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -187,7 +187,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Russian
|
Pусский
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -202,7 +202,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Traditional Chinese
|
中文 (繁體)
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -217,7 +217,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Simplified Chinese
|
中文 (简体)
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
@ -232,7 +232,7 @@ exports[`components/sidebar/SidebarSettingsMenu languages menu open should match
|
||||||
<div
|
<div
|
||||||
class="menu-name"
|
class="menu-name"
|
||||||
>
|
>
|
||||||
Turkish
|
Türkçe
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="noicon"
|
class="noicon"
|
||||||
|
|
|
@ -58,47 +58,47 @@ const SidebarSettingsMenu = React.memo((props: Props) => {
|
||||||
{
|
{
|
||||||
code: 'es',
|
code: 'es',
|
||||||
name: 'spanish',
|
name: 'spanish',
|
||||||
displayName: 'Spanish',
|
displayName: 'Español',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'de',
|
code: 'de',
|
||||||
name: 'german',
|
name: 'german',
|
||||||
displayName: 'German',
|
displayName: 'Deutsch',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'ja',
|
code: 'ja',
|
||||||
name: 'japanese',
|
name: 'japanese',
|
||||||
displayName: 'Japanese',
|
displayName: '日本語',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'fr',
|
code: 'fr',
|
||||||
name: 'french',
|
name: 'french',
|
||||||
displayName: 'French',
|
displayName: 'Français',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'nl',
|
code: 'nl',
|
||||||
name: 'dutch',
|
name: 'dutch',
|
||||||
displayName: 'Dutch',
|
displayName: 'Nederlands',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'ru',
|
code: 'ru',
|
||||||
name: 'russian',
|
name: 'russian',
|
||||||
displayName: 'Russian',
|
displayName: 'Pусский',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'chinese',
|
code: 'zh-cn',
|
||||||
name: 'zh',
|
name: 'chinese',
|
||||||
displayName: 'Traditional Chinese',
|
displayName: '中文 (繁體)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'zh_Hans',
|
code: 'zh-tx',
|
||||||
name: 'simplified-chinese',
|
name: 'simplified-chinese',
|
||||||
displayName: 'Simplified Chinese',
|
displayName: '中文 (简体)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'tr',
|
code: 'tr',
|
||||||
name: 'turkish',
|
name: 'turkish',
|
||||||
displayName: 'Turkish',
|
displayName: 'Türkçe',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'oc',
|
code: 'oc',
|
||||||
|
@ -160,7 +160,7 @@ const SidebarSettingsMenu = React.memo((props: Props) => {
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
key={language.code}
|
key={language.code}
|
||||||
id={`${language.name}-lang`}
|
id={`${language.name}-lang`}
|
||||||
name={intl.formatMessage({id: `Sidebar.${language.name}`, defaultMessage: language.displayName})}
|
name={language.displayName}
|
||||||
onClick={async () => setLanguage(language.code)}
|
onClick={async () => setLanguage(language.code)}
|
||||||
rightIcon={intl.locale.toLowerCase() === language.code ? <CheckIcon/> : null}
|
rightIcon={intl.locale.toLowerCase() === language.code ? <CheckIcon/> : null}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -13,7 +13,7 @@ import messages_tr from '../i18n/tr.json'
|
||||||
import messages_zhHant from '../i18n/zh_Hant.json'
|
import messages_zhHant from '../i18n/zh_Hant.json'
|
||||||
import messages_zhHans from '../i18n/zh_Hans.json'
|
import messages_zhHans from '../i18n/zh_Hans.json'
|
||||||
|
|
||||||
const supportedLanguages = ['de', 'fr', 'ja', 'nl', 'ru', 'es', 'oc', 'tr', 'zh', 'zh_Hant', 'zh_Hans']
|
const supportedLanguages = ['de', 'fr', 'ja', 'nl', 'ru', 'es', 'oc', 'tr', 'zh-cn', 'zh-tw']
|
||||||
|
|
||||||
export function getMessages(lang: string): {[key: string]: string} {
|
export function getMessages(lang: string): {[key: string]: string} {
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
|
@ -33,11 +33,9 @@ export function getMessages(lang: string): {[key: string]: string} {
|
||||||
return messages_oc
|
return messages_oc
|
||||||
case 'tr':
|
case 'tr':
|
||||||
return messages_tr
|
return messages_tr
|
||||||
case 'zh':
|
case 'zh-cn':
|
||||||
return messages_zhHant
|
return messages_zhHant
|
||||||
case 'zh_Hant':
|
case 'zh-tw':
|
||||||
return messages_zhHant
|
|
||||||
case 'zh_Hans':
|
|
||||||
return messages_zhHans
|
return messages_zhHans
|
||||||
}
|
}
|
||||||
return messages_en
|
return messages_en
|
||||||
|
|
Loading…
Reference in a new issue