Skip to content

Commit

Permalink
Implement alternative month names (bug 10871).
Browse files Browse the repository at this point in the history
Some languages (Slavic, Baltic, etc.) require a genitive case of the
month name when formatting a full date (with the day number) while
they require a nominative case when referring to the month standalone.
This requirement cannot be fulfilled without providing two forms for
each month name.  From now it is specified that nl_langinfo(MON_1)
series (up to MON_12) and strftime("%B") generate the month names in
the grammatical form used when the month is a part of a complete date.
If the grammatical form used when the month is named by itself is needed,
the new values nl_langinfo(ALTMON_1) (up to ALTMON_12) and
strftime("%OB") are supported.  This new feature is optional so the
languages which do not need it or do not yet provide the updated
locales simply do not use it and their behaviour is unchanged.

	[BZ #10871]
	* locale/C-time.c (_nl_C_LC_TIME): Add alternative month names,
	define them as the same as primary full month names explicitly.
	* locale/categories.def (LC_TIME): Add alt_mon and wide-alt_mon.
	* locale/langinfo.h (__ALTMON_1, __ALTMON_2, __ALTMON_3, __ALTMON_4,
	__ALTMON_5, __ALTMON_6, __ALTMON_7, __ALTMON_8, __ALTMON_9, __ALTMON_10,
	__ALTMON_11, __ALTMON_12, _NL_WALTMON_1, _NL_WALTMON_2, _NL_WALTMON_3,
	_NL_WALTMON_4, _NL_WALTMON_5, _NL_WALTMON_6, _NL_WALTMON_7,
	_NL_WALTMON_8, _NL_WALTMON_9, _NL_WALTMON_10, _NL_WALTMON_11,
	_NL_WALTMON_12): New enum constants.
	[__USE_GNU] (ALTMON_1, ALTMON_2, ALTMON_3, ALTMON_4, ALTMON_5, ALTMON_6,
	ALTMON_7, ALTMON_8, ALTMON_9, ALTMON_10, ALTMON_11, ALTMON_12): New
	macros.
	* locale/programs/ld-time.c (struct locale_time_t): Add alt_mon,
	walt_mon, and alt_mon_defined members.
	(time_output): Output alt_mon and walt_mon members.
	(time_read): Read them, initialize them as copies of mon and wmon
	respectively if they are missing, initialize alt_mon_defined.
	* locale/programs/locfile-kw.gperf (alt_mon): Define.
	* locale/programs/locfile-kw.h: Regenerate.
	* locale/programs/locfile-token.h (tok_alt_mon): New enum constant.
	* localedata/tst-langinfo.c (map): Add tests for the new constants
	ALTMON_1 .. ALTMON_12.
	* time/Makefile [$(run-built-tests) = yes] (LOCALES): Add fr_FR.UTF-8
	and pl_PL.UTF-8.
	* time/strftime_l.c (f_altmonth): New macro.
	(__strftime_internal): Handle %OB format.
	* time/strptime_l.c [_LIBC] (alt_month_name): New macro.
	(__strptime_internal): Handle %OB format.
	* time/tst-strptime.c (day_tests): Add tests to parse different forms
	of month names including the new %OB format specifier.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
  • Loading branch information
rluzynski committed Jan 22, 2018
1 parent 4612268 commit 95cb863
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 64 deletions.
34 changes: 34 additions & 0 deletions ChangeLog
@@ -1,3 +1,37 @@
2018-01-22 Rafal Luzynski <digitalfreak@lingonborough.com>

[BZ #10871]
* locale/C-time.c (_nl_C_LC_TIME): Add alternative month names,
define them as the same as primary full month names explicitly.
* locale/categories.def (LC_TIME): Add alt_mon and wide-alt_mon.
* locale/langinfo.h (__ALTMON_1, __ALTMON_2, __ALTMON_3, __ALTMON_4,
__ALTMON_5, __ALTMON_6, __ALTMON_7, __ALTMON_8, __ALTMON_9, __ALTMON_10,
__ALTMON_11, __ALTMON_12, _NL_WALTMON_1, _NL_WALTMON_2, _NL_WALTMON_3,
_NL_WALTMON_4, _NL_WALTMON_5, _NL_WALTMON_6, _NL_WALTMON_7,
_NL_WALTMON_8, _NL_WALTMON_9, _NL_WALTMON_10, _NL_WALTMON_11,
_NL_WALTMON_12): New enum constants.
[__USE_GNU] (ALTMON_1, ALTMON_2, ALTMON_3, ALTMON_4, ALTMON_5, ALTMON_6,
ALTMON_7, ALTMON_8, ALTMON_9, ALTMON_10, ALTMON_11, ALTMON_12): New
macros.
* locale/programs/ld-time.c (struct locale_time_t): Add alt_mon,
walt_mon, and alt_mon_defined members.
(time_output): Output alt_mon and walt_mon members.
(time_read): Read them, initialize them as copies of mon and wmon
respectively if they are missing, initialize alt_mon_defined.
* locale/programs/locfile-kw.gperf (alt_mon): Define.
* locale/programs/locfile-kw.h: Regenerate.
* locale/programs/locfile-token.h (tok_alt_mon): New enum constant.
* localedata/tst-langinfo.c (map): Add tests for the new constants
ALTMON_1 .. ALTMON_12.
* time/Makefile [$(run-built-tests) = yes] (LOCALES): Add fr_FR.UTF-8
and pl_PL.UTF-8.
* time/strftime_l.c (f_altmonth): New macro.
(__strftime_internal): Handle %OB format.
* time/strptime_l.c [_LIBC] (alt_month_name): New macro.
(__strptime_internal): Handle %OB format.
* time/tst-strptime.c (day_tests): Add tests to parse different forms
of month names including the new %OB format specifier.

2018-01-19 Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>

[BZ #22685]
Expand Down
28 changes: 26 additions & 2 deletions locale/C-time.c
Expand Up @@ -30,7 +30,7 @@ const struct __locale_data _nl_C_LC_TIME attribute_hidden =
{ NULL, }, /* no cached data */
UNDELETABLE,
0,
111,
135,
{
{ .string = "Sun" },
{ .string = "Mon" },
Expand Down Expand Up @@ -142,6 +142,30 @@ const struct __locale_data _nl_C_LC_TIME attribute_hidden =
{ .string = "" },
{ .string = "%a %b %e %H:%M:%S %Z %Y" },
{ .wstr = (const uint32_t *) L"%a %b %e %H:%M:%S %Z %Y" },
{ .string = _nl_C_codeset }
{ .string = _nl_C_codeset },
{ .string = "January" },
{ .string = "February" },
{ .string = "March" },
{ .string = "April" },
{ .string = "May" },
{ .string = "June" },
{ .string = "July" },
{ .string = "August" },
{ .string = "September" },
{ .string = "October" },
{ .string = "November" },
{ .string = "December" },
{ .wstr = (const uint32_t *) L"January" },
{ .wstr = (const uint32_t *) L"February" },
{ .wstr = (const uint32_t *) L"March" },
{ .wstr = (const uint32_t *) L"April" },
{ .wstr = (const uint32_t *) L"May" },
{ .wstr = (const uint32_t *) L"June" },
{ .wstr = (const uint32_t *) L"July" },
{ .wstr = (const uint32_t *) L"August" },
{ .wstr = (const uint32_t *) L"September" },
{ .wstr = (const uint32_t *) L"October" },
{ .wstr = (const uint32_t *) L"November" },
{ .wstr = (const uint32_t *) L"December" }
}
};
2 changes: 2 additions & 0 deletions locale/categories.def
Expand Up @@ -249,6 +249,8 @@ DEFINE_CATEGORY
DEFINE_ELEMENT (_DATE_FMT, "date_fmt", opt, string)
DEFINE_ELEMENT (_NL_W_DATE_FMT, "wide-date_fmt", opt, wstring)
DEFINE_ELEMENT (_NL_TIME_CODESET, "time-codeset", std, string)
DEFINE_ELEMENT (ALTMON_1, "alt_mon", opt, stringarray, 12, 12)
DEFINE_ELEMENT (_NL_WALTMON_1, "wide-alt_mon", opt, wstringarray, 12, 12)
), NO_POSTLOAD)


Expand Down
50 changes: 48 additions & 2 deletions locale/langinfo.h
Expand Up @@ -100,7 +100,8 @@ enum
ABMON_12,
#define ABMON_12 ABMON_12

/* Long month names. */
/* Long month names, in the grammatical form used when the month
is a part of a complete date. */
MON_1, /* January */
#define MON_1 MON_1
MON_2,
Expand Down Expand Up @@ -189,7 +190,8 @@ enum
_NL_WABMON_11,
_NL_WABMON_12,

/* Long month names. */
/* Long month names, in the grammatical form used when the month
is a part of a complete date. */
_NL_WMON_1, /* January */
_NL_WMON_2,
_NL_WMON_3,
Expand Down Expand Up @@ -231,6 +233,50 @@ enum

_NL_TIME_CODESET,

/* Long month names, in the grammatical form used when the month
is named by itself. */
__ALTMON_1, /* January */
__ALTMON_2,
__ALTMON_3,
__ALTMON_4,
__ALTMON_5,
__ALTMON_6,
__ALTMON_7,
__ALTMON_8,
__ALTMON_9,
__ALTMON_10,
__ALTMON_11,
__ALTMON_12,
#ifdef __USE_GNU
# define ALTMON_1 __ALTMON_1
# define ALTMON_2 __ALTMON_2
# define ALTMON_3 __ALTMON_3
# define ALTMON_4 __ALTMON_4
# define ALTMON_5 __ALTMON_5
# define ALTMON_6 __ALTMON_6
# define ALTMON_7 __ALTMON_7
# define ALTMON_8 __ALTMON_8
# define ALTMON_9 __ALTMON_9
# define ALTMON_10 __ALTMON_10
# define ALTMON_11 __ALTMON_11
# define ALTMON_12 __ALTMON_12
#endif

/* Long month names, in the grammatical form used when the month
is named by itself. */
_NL_WALTMON_1, /* January */
_NL_WALTMON_2,
_NL_WALTMON_3,
_NL_WALTMON_4,
_NL_WALTMON_5,
_NL_WALTMON_6,
_NL_WALTMON_7,
_NL_WALTMON_8,
_NL_WALTMON_9,
_NL_WALTMON_10,
_NL_WALTMON_11,
_NL_WALTMON_12,

_NL_NUM_LC_TIME, /* Number of indices in LC_TIME category. */

/* LC_COLLATE category: text sorting.
Expand Down
21 changes: 21 additions & 0 deletions locale/programs/ld-time.c
Expand Up @@ -91,6 +91,9 @@ struct locale_time_t
const char *date_fmt;
const uint32_t *wdate_fmt;
int alt_digits_defined;
const char *alt_mon[12];
const uint32_t *walt_mon[12];
int alt_mon_defined;
unsigned char week_ndays;
uint32_t week_1stday;
unsigned char week_1stweek;
Expand Down Expand Up @@ -639,6 +642,15 @@ time_output (struct localedef_t *locale, const struct charmap_t *charmap,
add_locale_string (&file, time->date_fmt);
add_locale_wstring (&file, time->wdate_fmt);
add_locale_string (&file, charmap->code_set_name);

/* The alt'mons. */
for (n = 0; n < 12; ++n)
add_locale_string (&file, time->alt_mon[n] ?: "");

/* The wide character alt'mons. */
for (n = 0; n < 12; ++n)
add_locale_wstring (&file, time->walt_mon[n] ?: empty_wstr);

write_locale_data (output_path, LC_TIME, "LC_TIME", &file);
}

Expand Down Expand Up @@ -782,6 +794,7 @@ time_read (struct linereader *ldfile, struct localedef_t *result,
STRARR_ELEM (mon, 12, 12);
STRARR_ELEM (am_pm, 2, 2);
STRARR_ELEM (alt_digits, 0, 100);
STRARR_ELEM (alt_mon, 12, 12);

case tok_era:
/* Ignore the rest of the line if we don't need the input of
Expand Down Expand Up @@ -934,6 +947,14 @@ time_read (struct linereader *ldfile, struct localedef_t *result,
lr_error (ldfile, _("\
%1$s: definition does not end with `END %1$s'"), "LC_TIME");
lr_ignore_rest (ldfile, now->tok == tok_lc_time);

/* If alt_mon was not specified, make it a copy of mon. */
if (!ignore_content && !time->alt_mon_defined)
{
memcpy (time->alt_mon, time->mon, sizeof (time->mon));
memcpy (time->walt_mon, time->wmon, sizeof (time->wmon));
time->alt_mon_defined = 1;
}
return;

default:
Expand Down
1 change: 1 addition & 0 deletions locale/programs/locfile-kw.gperf
Expand Up @@ -148,6 +148,7 @@ first_workday, tok_first_workday, 0
cal_direction, tok_cal_direction, 0
timezone, tok_timezone, 0
date_fmt, tok_date_fmt, 0
alt_mon, tok_alt_mon, 0
LC_MESSAGES, tok_lc_messages, 0
yesexpr, tok_yesexpr, 0
noexpr, tok_noexpr, 0
Expand Down

0 comments on commit 95cb863

Please sign in to comment.