Commit a9c73054 authored by Murray Cumming's avatar Murray Cumming

Use the LC_TIME environment variable to get translated date formats.

So we have the correct 4 digit date formats for those too,
even where the default behaviour is incorrect.

Also add a regression test for this.

Bug #742968
parent 7c7bb6e4
......@@ -112,6 +112,7 @@ dist_noinst_SCRIPTS = tests/ \
tests/ \
tests/ \
tests/ \
tests/ \
tests/ \
tests/ \
......@@ -388,7 +389,8 @@ if GLOM_ENABLE_UI_TESTS
TESTS += \
tests/ \
tests/test_glade_derived_instantiation \
tests/ \
......@@ -406,5 +406,6 @@ AC_CONFIG_FILES([Makefile
AC_CONFIG_FILES([tests/], [chmod u+x tests/])
AC_CONFIG_FILES([tests/], [chmod u+x tests/])
......@@ -88,10 +88,39 @@ static inline const char* glom_get_locale_date_format()
//TODO: Find some way to get the %x translation that's appropriate for the value of LC_NUMERIC in the locale,
//because this just assumes that the main locale name will be correct,
//so this can fail, for instance, if gettext() is looking for the translation for en_US.UTF-8
//but LC_NUMERIC is set to en_GB.UTF-8 (which uses 2 digits when using %x).
//Get the current LC_TIME value:
//We copy the string because setlocale() probably returns the same array
//each time.
//Even when the LC_TIME environment variable is not set, we still seem
//to get a useful value here, based on LC_ALL, for instance.
char* lc_time = setlocale(LC_TIME, NULL);
lc_time = g_strdup(lc_time);
std::cout << "DEBUG: LC_TIME: " << lc_time << std::endl;
char* old_lc_messages = 0;
bool changed_lc_messages = false;
//We call setlocale() so we get the %x translation that's appropriate for the
//value of LC_TIME's locale,
//Otherwise _() would fail if, for instance, gettext() just looked for the
//translation for en_US.UTF-8, but LC_NUMERIC was set to en_GB.UTF-8
//(which uses 2 digits when using %x).
//Get the current LC_MESSAGES value:
old_lc_messages = g_strdup(setlocale(LC_MESSAGES, NULL));
old_lc_messages = g_strdup(old_lc_messages);
//Change LC_MESSAGES to change how gettext works():
if(g_strcmp0(lc_time, old_lc_messages) != 0) {
setlocale(LC_MESSAGES, lc_time);
changed_lc_messages = true;
/* TRANSLATORS: Please only translate this string if you know that strftime()
* shows only 2 year digits when using format "x". We want to always display
......@@ -102,6 +131,16 @@ static inline const char* glom_get_locale_date_format()
* Thanks.
* xgettext:no-c-format */
c_locale_date_format = _("%x");
//Change LC_MESSAGES back:
setlocale(LC_MESSAGES, old_lc_messages);
//std::cout << G_STRFUNC << ": c_locale_date_format=" << c_locale_date_format << std::endl;
#/bin/sh -e
# This test checks that dates are presented and interpreted correctly,
# even when the LC_TIME's locale would need to use a translation of the "%x" date
# format from .po file, but the main locale doesn't need a translation of the "%x"
# date format.
# For instance, LANG="en_US.UTF-8" (uses "%x", giving 4 digit years),
# with LC_TIME="es_ES.UTF-8" (should not use "%x", because it gives 2 digit years).
# This test requires these locales to be installed and configured.
# That might be a problem on some systems, so feel free to use a patch to edit this file or disable it altogether.
# These are chosen based on problems found previously,
# and the ones with good translations shown here:
# TODO: Get a list from po/*.po ?
# On debian/Ubuntu do this:
# sudo apt-get install language-pack-de language-pack-es language-pack-fi language-pack-fr language-pack-hu language-pack-it language-pack-pt language-pack-sl language-pack-da language-pack-cs language-pack-nb language-pack-sv
# These are apparently not available on Fedora: "da_DK.UTF-8" "cs_CZ.UTF-8" "nb_NO.UTF-8" "sv_SE.UTF-8"
function test_date {
echo testing with LANG="$lang" and LC_TIME="$lc_time"
export LANG="$lang"
# We don't set LANGUAGE because that seems to affect, for instance, printf(),
# ignoring LC_TIME. Maybe we need to handle that too.
# export LANGUAGE="$lang"
export LC_TIME="$lc_time"
@abs_top_builddir@/glom/glom --debug-date-check || exit 1
test_date "en_US.UTF-8" "en_GB.UTF-8"
test_date "en_US.UTF-8" "es_ES.UTF-8"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment