Language specific options
This commit is contained in:
parent
17290562c8
commit
615f316be2
|
|
@ -31,6 +31,8 @@ import {
|
||||||
StyledMain,
|
StyledMain,
|
||||||
} from './availabilityViewerStyle';
|
} from './availabilityViewerStyle';
|
||||||
|
|
||||||
|
import locales from 'res/dayjs_locales';
|
||||||
|
|
||||||
dayjs.extend(localeData);
|
dayjs.extend(localeData);
|
||||||
dayjs.extend(customParseFormat);
|
dayjs.extend(customParseFormat);
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
@ -152,7 +154,7 @@ const AvailabilityViewer = ({
|
||||||
onMouseEnter={(e) => {
|
onMouseEnter={(e) => {
|
||||||
const cellBox = e.currentTarget.getBoundingClientRect();
|
const cellBox = e.currentTarget.getBoundingClientRect();
|
||||||
const wrapperBox = wrapper?.current?.getBoundingClientRect() ?? { x: 0, y: 0 };
|
const wrapperBox = wrapper?.current?.getBoundingClientRect() ?? { x: 0, y: 0 };
|
||||||
const timeText = timeFormat === '12h' ? 'h:mma' : 'HH:mm';
|
const timeText = timeFormat === '12h' ? `h${locales[locale].separator}mma` : `HH${locales[locale].separator}mm`;
|
||||||
setTooltip({
|
setTooltip({
|
||||||
x: Math.round(cellBox.x-wrapperBox.x + cellBox.width/2),
|
x: Math.round(cellBox.x-wrapperBox.x + cellBox.width/2),
|
||||||
y: Math.round(cellBox.y-wrapperBox.y + cellBox.height)+6,
|
y: Math.round(cellBox.y-wrapperBox.y + cellBox.height)+6,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
Cover,
|
Cover,
|
||||||
} from './settingsStyle';
|
} from './settingsStyle';
|
||||||
|
|
||||||
import localeImports from 'res/dayjs_locales';
|
import locales from 'res/dayjs_locales';
|
||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
@ -24,8 +24,8 @@ const Settings = () => {
|
||||||
const setLocale = useLocaleUpdateStore(state => state.setLocale);
|
const setLocale = useLocaleUpdateStore(state => state.setLocale);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Object.keys(localeImports).includes(i18n.language)) {
|
if (Object.keys(locales).includes(i18n.language)) {
|
||||||
localeImports[i18n.language]().then(() => {
|
locales[i18n.language].import().then(() => {
|
||||||
dayjs.locale(i18n.language);
|
dayjs.locale(i18n.language);
|
||||||
setLocale(dayjs.locale());
|
setLocale(dayjs.locale());
|
||||||
document.documentElement.setAttribute('lang', i18n.language);
|
document.documentElement.setAttribute('lang', i18n.language);
|
||||||
|
|
@ -36,6 +36,14 @@ const Settings = () => {
|
||||||
}
|
}
|
||||||
}, [i18n.language, setLocale]);
|
}, [i18n.language, setLocale]);
|
||||||
|
|
||||||
|
i18n.on('languageChanged', lang => {
|
||||||
|
// Language specific options
|
||||||
|
if (locales.hasOwnProperty(lang)) {
|
||||||
|
store.setWeekStart(locales[lang].weekStart);
|
||||||
|
store.setTimeFormat(locales[lang].timeFormat);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<OpenButton
|
<OpenButton
|
||||||
|
|
@ -106,14 +114,10 @@ const Settings = () => {
|
||||||
name="language"
|
name="language"
|
||||||
id="language"
|
id="language"
|
||||||
options={{
|
options={{
|
||||||
'de': 'Deutsch',
|
...Object.keys(locales).reduce((ls, l) => {
|
||||||
'en': 'English',
|
ls[l] = locales[l].name;
|
||||||
'es': 'Español',
|
return ls;
|
||||||
'fr': 'Français',
|
}, {}),
|
||||||
'hi': 'हिंदी',
|
|
||||||
'id': 'Indonesia',
|
|
||||||
'ko': '한국어',
|
|
||||||
'ru': 'Pусский',
|
|
||||||
...process.env.NODE_ENV !== 'production' && { 'cimode': 'DEV' },
|
...process.env.NODE_ENV !== 'production' && { 'cimode': 'DEV' },
|
||||||
}}
|
}}
|
||||||
small
|
small
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,67 @@
|
||||||
const locales = {
|
const locales = {
|
||||||
de: () => import('dayjs/locale/de'), // German
|
'de': { // German
|
||||||
en: () => import('dayjs/locale/en'), // English
|
name: 'Deutsch',
|
||||||
es: () => import('dayjs/locale/es'), // Spanish
|
import: () => import('dayjs/locale/de'),
|
||||||
fr: () => import('dayjs/locale/fr'), // French
|
weekStart: 1,
|
||||||
hi: () => import('dayjs/locale/hi'), // Hindi
|
timeFormat: '24h',
|
||||||
id: () => import('dayjs/locale/id'), // Indonesian
|
separator: ':',
|
||||||
ko: () => import('dayjs/locale/ko'), // Korean
|
},
|
||||||
ru: () => import('dayjs/locale/ru'), // Russian
|
'en': { // English (US)
|
||||||
|
name: 'English (US)',
|
||||||
|
import: () => import('dayjs/locale/en'),
|
||||||
|
weekStart: 0,
|
||||||
|
timeFormat: '12h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'en-GB': { // English (UK)
|
||||||
|
name: 'English (UK)',
|
||||||
|
import: () => import('dayjs/locale/en-gb'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '12h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'es': { // Spanish
|
||||||
|
name: 'Español',
|
||||||
|
import: () => import('dayjs/locale/es'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '24h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'fr': { // French
|
||||||
|
name: 'Français',
|
||||||
|
import: () => import('dayjs/locale/fr'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '24h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'hi': { // Hindi
|
||||||
|
name: 'हिंदी',
|
||||||
|
import: () => import('dayjs/locale/hi'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '12h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'id': { // Indonesian
|
||||||
|
name: 'Indonesia',
|
||||||
|
import: () => import('dayjs/locale/id'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '24h',
|
||||||
|
separator: '.',
|
||||||
|
},
|
||||||
|
'ko': { // Korean
|
||||||
|
name: '한국어',
|
||||||
|
import: () => import('dayjs/locale/ko'),
|
||||||
|
weekStart: 0,
|
||||||
|
timeFormat: '24h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
|
'ru': { // Russian
|
||||||
|
name: 'Pусский',
|
||||||
|
import: () => import('dayjs/locale/ru'),
|
||||||
|
weekStart: 1,
|
||||||
|
timeFormat: '24h',
|
||||||
|
separator: ':',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default locales;
|
export default locales;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue