date-selector: fix crash on some locales

As stated on the bug below Calendar crashes in some locales because of the
parsing of the string representing the date. Since parsing this string can be
very tricky, we decided to make a simple translatable string with the format it
is needed and th translators can set the proper order according to his locale.

The translatable string goes as "%d/%m/%y" being %d the representation of the
day, %m the representation of the month and, %y, the year. The translators
should place it in the correct order for its locale, for instance en_US, should
place it: "%m/%d/%y"

The validation of the translated string is lacking some strength. It could use
some improving.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1226823
This commit is contained in:
Erick Pérez Castellanos
2015-06-03 14:46:00 -04:00
parent 61a32026c1
commit fd54a863f4
+15 -3
View File
@@ -233,14 +233,26 @@ gcal_date_selector_init (GcalDateSelector *self)
priv->month = 1;
priv->year = 1970;
priv->mask = nl_langinfo (D_FMT);
/* This string represents day/month/year order for each of the different
* languages. It could possibly be default value, %m/%d/%y placing the month
* before, or any ordering according to the translator's environment. */
priv->mask = _("%m/%d/%y");
/**
* Select the day, month and year indexes. This will
* Translators: Select the day, month and year indexes. This will
* be used later on to map the date entries to the
* corresponding indexes.
* corresponding indexes. I should have added more validations here.
*/
max = strlen (priv->mask);
if (max != 6)
{
/* I'll assume an error and bail out with the default values */
priv->day_pos = 0;
priv->month_pos = 1;
priv->year_pos = 2;
return;
}
d_index = 0;
for (i = 0; i < max; i++)