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 picker localizations #968

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,11 @@ input:disabled + .slider {
}

/* Styles for Right Alignment of input type date */
#preferences-window input[type="text"].date-right {
text-align: right;
position: relative;
}

#preferences-window input[type="date"].date-right::-webkit-datetime-edit {
text-align: right;
position: relative;
Expand Down
15 changes: 14 additions & 1 deletion js/date-to-string-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ function getMonthName(languageData, monthIndex)
return getTranslationInLanguageData(languageData, `$DateUtil.${monthNames[monthIndex]}`);
}


function getMonthNames(languageData)
{
return monthNames.map(val => getTranslationInLanguageData(languageData, `$DateUtil.${val}`));
}

function getDay(languageData)
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
{
return dayAbbrs.map(val => getTranslationInLanguageData(languageData, `$DateUtil.${val}`));
}

export {
getDayAbbr,
getMonthName
getMonthName,
getMonthNames,
getDay
};
8 changes: 8 additions & 0 deletions js/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ function getEditMenuTemplate(mainWindow)
BrowserWindow.getFocusedWindow().webContents.toggleDevTools();
}
});
prefWindow.webContents.on('before-input-event', (event, input) =>
{
if (input.control && input.shift && input.key.toLowerCase() === 'r')
{
BrowserWindow.getFocusedWindow().reload();
}
});

},
},
{type: 'separator'},
Expand Down
6 changes: 5 additions & 1 deletion src/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../node_modules/@fortawesome/fontawesome-free/css/all.min.css">
<link rel="stylesheet" href="../css/styles.css">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved

<!-- First we need to declare jQuery and $ globals with jquery -->
<script src="../node_modules/jquery/dist/jquery.min.js" charset="utf-8"></script>
Expand All @@ -13,6 +14,7 @@
</script>

<script src="../node_modules/bootstrap/dist/js/bootstrap.bundle.js" charset="utf-8"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
<script type="module" src="preferences.js"></script>
</head>

Expand Down Expand Up @@ -105,7 +107,9 @@
</div>
<div class="flex-box">
<p><i class="fas fa-sign-in-alt"></i><span data-i18n="$Preferences.overallBalanceStart">Overall Balance Start Date</span></p>
<label id='overall-balance-start-date'><input type="date" class="date-right" name="overall-balance-start-date"></label>
<label id='overall-balance-start-date'><input id="datepicker" type="text" class="date-right" name="overall-balance-start-date">
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
<i class="fa fa-calendar" aria-hidden="true"></i>
</label>
</div>
<div class="flex-box">
<p><i class="fas fa-eye"></i><span data-i18n="$Preferences.view">View</span></p>
Expand Down
28 changes: 27 additions & 1 deletion src/preferences.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size is a little odd on the month names
September got cut

image

Also, when we switch to a month with more days, it covers the input we were going to choose

image

Wonder if there's a setting for this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people suggest having a fixed height, but that can leave an empty row in some months.
The native datepicker solves that by having the days from the other months fill up even new rows to always have the 6 rows

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no property exposed to set the constant rows (6 in our case)
As you mentioned, people suggesting to have a fixed height
What you say? can we go with fixed height?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fixed height is ok. There might be a way to adjust the other height proportions so it doesn't look too bad.

Also, have you seen https://www.npmjs.com/package/js-datepicker?
I was looking at alternatives, and I think it looks nicer visually that jquery's 😅
The native datepicker is very slick and nice, but the jquery one looks a bit dated, like older web stuff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, So can we switch to this suggested npm package, did you had a check whether it covers all our requirement ? If yes and all good, I am fine to move to this npm package instead of jquery-ui datepicker

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be translated and looks simple enough to replace the colors afterwards.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { applyTheme } from '../renderer/themes.js';
import { translatePage } from '../renderer/i18n-translator.js';
import { getMonthNames, getDay } from '../js/date-to-string-util.js';


// Global values for preferences page
let usersStyles;
Expand Down Expand Up @@ -35,6 +37,7 @@ function listenerLanguage()
window.mainApi.changeLanguagePromise(this.value).then((languageData) =>
{
translatePage(this.value, languageData, 'Preferences');
refreshDate(this.value,languageData);
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
window.mainApi.notifyNewPreferences(preferences);
});
});
Expand All @@ -47,9 +50,23 @@ function setupLanguages()
window.mainApi.getLanguageDataPromise().then(languageData =>
{
translatePage(usersStyles['language'], languageData.data, 'Preferences');
refreshDate(usersStyles['language'],languageData.data);
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
});
}

function refreshDate(language, languageData)
{
$.datepicker.regional[`${language}`] = {
monthNames: getMonthNames(languageData),
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
monthNamesShort: getMonthNames(languageData),
weekHeader: 'Sm',
dayNames: getDay(languageData),
dayNamesShort: getDay(languageData),
dayNamesMin: getDay(languageData),
firstDay: 0};
$.datepicker.setDefaults($.datepicker.regional[`${language}`]);
}

function refreshContent()
{
return new Promise((resolve) =>
Expand Down Expand Up @@ -91,6 +108,15 @@ function renderPreferencesWindow()
$('#view').val(usersStyles['view']);
}

$( function()
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
{
$( '#datepicker' ).datepicker({
RahulKannan12 marked this conversation as resolved.
Show resolved Hide resolved
dateFormat: 'yy-mm-dd',
changeYear: true,
changeMonth: true
});
});

$('input[type="checkbox"]').on('change', function()
{
changeValue(this.name, this.checked);
Expand All @@ -105,7 +131,7 @@ function renderPreferencesWindow()
}
});

$('input[type="number"], input[type="date"]').on('change', function()
$('input[type="number"], input[type="date"], input[type="text"]').on('change', function()
{
changeValue(this.name, this.value);
});
Expand Down