Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Date editor localization 2022 4 #1816

Merged
merged 2 commits into from Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -129,9 +129,9 @@ export class CalendarWidget extends React.Component<{
</button>
<div
className={S.title}
title={this.displayedMonth.format("YYYY MMMM")}
title={formatYearAndMonth(this.displayedMonth)}
>
{this.displayedMonth.format("YYYY MMMM")}
{formatYearAndMonth(this.displayedMonth)}
</div>
<button className={S.controlBtn} onClick={this.handleYearDecClick}>
<i className="fas fa-caret-down"/>
Expand All @@ -147,4 +147,21 @@ export class CalendarWidget extends React.Component<{
</div>
);
}
}

function formatYearAndMonth(moment: moment.Moment){
return moment.format("YYYY ") + getMonthName(moment);
}

// moment.format("MMMM") does not return czech month name in the first case
// ("června" instead of "červen"). This function does.
function getMonthName(moment: moment.Moment){
const csMonths = [
'leden', 'únor', 'březen', 'duben', 'květen', 'červen',
'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'
];
if (moment.locale() === "cs") {
return csMonths[moment.month()];
}
return moment.format("MMMM");
}
8 changes: 7 additions & 1 deletion frontend-html/src/index.tsx
Expand Up @@ -33,7 +33,13 @@ import Cookie from "js-cookie";
import { translationsInit } from "./utils/translation";
import { getLocaleFromCookie, initLocaleCookie } from "utils/cookies";
import moment from "moment";
import "moment/min/locales";
import 'moment/dist/locale/de';
import 'moment/dist/locale/de-at';
import 'moment/dist/locale/de-ch';
import 'moment/dist/locale/fr.js';
import 'moment/dist/locale/fr-ch.js';
import 'moment/dist/locale/fr-ca.js';
import 'moment/dist/locale/cs';
import { preventDoubleclickSelect } from "utils/mouse";
import { RootError } from "RootError";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down