mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Modified language selection to use language names
This commit is contained in:
@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { Locales, languages } from '../../contexts/LanguageContext';
|
import { Locales, languages } from '../../contexts/LanguageContext';
|
||||||
import { useLocalState } from '../../states/LocalState';
|
import { useLocalState } from '../../states/LocalState';
|
||||||
|
|
||||||
export function LanguageSelect() {
|
export function LanguageSelect({ width = 80 }: { width?: number }) {
|
||||||
const [value, setValue] = useState<string | null>(null);
|
const [value, setValue] = useState<string | null>(null);
|
||||||
const [locale, setLanguage] = useLocalState((state) => [
|
const [locale, setLanguage] = useLocalState((state) => [
|
||||||
state.language,
|
state.language,
|
||||||
@ -21,6 +21,18 @@ export function LanguageSelect() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(locale);
|
setValue(locale);
|
||||||
}, [locale]);
|
}, [locale]);
|
||||||
|
const langOptions = Object.keys(languages).map((key) => ({
|
||||||
|
value: key,
|
||||||
|
label: languages[key as Locales]
|
||||||
|
}));
|
||||||
|
|
||||||
return <Select w={80} data={languages} value={value} onChange={setValue} />;
|
return (
|
||||||
|
<Select
|
||||||
|
w={width}
|
||||||
|
data={langOptions}
|
||||||
|
value={value}
|
||||||
|
onChange={setValue}
|
||||||
|
searchable
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ export default function DisplayWidget() {
|
|||||||
<Trans>Language</Trans>
|
<Trans>Language</Trans>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<LanguageSelect />
|
<LanguageSelect width={140} />
|
||||||
</div>
|
</div>
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</span>
|
</span>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { i18n } from '@lingui/core';
|
import { i18n } from '@lingui/core';
|
||||||
|
import { t } from '@lingui/macro';
|
||||||
import { I18nProvider } from '@lingui/react';
|
import { I18nProvider } from '@lingui/react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
@ -38,37 +39,38 @@ export type Locales =
|
|||||||
| 'zh-hant'
|
| 'zh-hant'
|
||||||
| 'pseudo-LOCALE';
|
| 'pseudo-LOCALE';
|
||||||
|
|
||||||
export const languages: Locales[] = [
|
export const languages: Record<Locales, string> = {
|
||||||
'cs',
|
cs: t`Czech`,
|
||||||
'da',
|
da: t`Danish`,
|
||||||
'de',
|
de: t`German`,
|
||||||
'el',
|
el: t`Greek`,
|
||||||
'en',
|
en: t`English`,
|
||||||
'es',
|
es: t`Spanish`,
|
||||||
'es-mx',
|
'es-mx': t`Spanish (Mexican)`,
|
||||||
'fa',
|
fa: t`Farsi / Persian`,
|
||||||
'fi',
|
fi: t`Finnish`,
|
||||||
'fr',
|
fr: t`French`,
|
||||||
'he',
|
he: t`Hebrew`,
|
||||||
'hi',
|
hi: t`Hindi`,
|
||||||
'hu',
|
hu: t`Hungarian`,
|
||||||
'it',
|
it: t`Italian`,
|
||||||
'ja',
|
ja: t`Japanese`,
|
||||||
'ko',
|
ko: t`Korean`,
|
||||||
'nl',
|
nl: t`Dutch`,
|
||||||
'no',
|
no: t`Norwegian`,
|
||||||
'pl',
|
pl: t`Polish`,
|
||||||
'pt',
|
pt: t`Portuguese`,
|
||||||
'pt-br',
|
'pt-br': t`Portuguese (Brazilian)`,
|
||||||
'ru',
|
ru: t`Russian`,
|
||||||
'sl',
|
sl: t`Slovenian`,
|
||||||
'sv',
|
sv: t`Swedish`,
|
||||||
'th',
|
th: t`Thai`,
|
||||||
'tr',
|
tr: t`Turkish`,
|
||||||
'vi',
|
vi: t`Vietnamese`,
|
||||||
'zh-hans',
|
'zh-hans': t`Chinese (Simplified)`,
|
||||||
'zh-hant'
|
'zh-hant': t`Chinese (Traditional)`,
|
||||||
];
|
'pseudo-LOCALE': t`Pseudo Locale`
|
||||||
|
};
|
||||||
|
|
||||||
export function LanguageContext({ children }: { children: JSX.Element }) {
|
export function LanguageContext({ children }: { children: JSX.Element }) {
|
||||||
const [language] = useLocalState((state) => [state.language]);
|
const [language] = useLocalState((state) => [state.language]);
|
||||||
|
@ -149,7 +149,7 @@ function DisplaySettings({ height }: { height: number }) {
|
|||||||
<Trans>Language</Trans>
|
<Trans>Language</Trans>
|
||||||
</Text>
|
</Text>
|
||||||
<Stack>
|
<Stack>
|
||||||
<LanguageSelect />
|
<LanguageSelect width={200} />
|
||||||
<Button onClick={enablePseudoLang} variant="light">
|
<Button onClick={enablePseudoLang} variant="light">
|
||||||
<Trans>Use pseudo language</Trans>
|
<Trans>Use pseudo language</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
|
Reference in New Issue
Block a user