[glom/glom-1-28] glom_get_locale_date_format(): Make this work even when LANGUAGE is set.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-28] glom_get_locale_date_format(): Make this work even when LANGUAGE is set.
- Date: Tue, 10 Feb 2015 10:59:03 +0000 (UTC)
commit cb111f0b452f37054863b899cef16da9d83d8686
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jan 19 09:12:12 2015 +0100
glom_get_locale_date_format(): Make this work even when LANGUAGE is set.
By temporarily unsetting LANGUAGE while getting LC_TIME via
setlocale(LC_TIME, NULL). As Geary does already too.
glom/libglom/data_structure/glomconversions.cc | 17 +++++++++++++++++
tests/test_glom_date_in_locales_lc_time.sh.in | 16 +++++++++++++---
2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index 3d43770..a17bf87 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -89,6 +89,17 @@ static inline const char* glom_get_locale_date_format()
if(!c_locale_date_format)
{
//Get the current LC_TIME value:
+
+ //Unset LANGUAGE because it affects what setlocale(LC_TIME, NULL) returns,
+ //though it doesn't affect what, for instance, printf() uses. So unsetting
+ //it lets us get the correct LC_TIME locale.
+ const char* ENV_LANGUAGE = "LANGUAGE";
+ char* language = getenv(ENV_LANGUAGE);
+ if(language)
+ language = g_strdup(language);
+
+ setenv(ENV_LANGUAGE, "", 1 /* replace */);
+
//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
@@ -139,8 +150,14 @@ static inline const char* glom_get_locale_date_format()
setlocale(LC_MESSAGES, old_lc_messages);
}
+ //Restore this:
+ if(language) { //setenv() can't take NULL for this.
+ setenv(ENV_LANGUAGE, language, 1 /* replace */);
+ }
+
g_free(old_lc_messages);
g_free(lc_time);
+ g_free(language);
}
//std::cout << G_STRFUNC << ": c_locale_date_format=" << c_locale_date_format << std::endl;
diff --git a/tests/test_glom_date_in_locales_lc_time.sh.in b/tests/test_glom_date_in_locales_lc_time.sh.in
index a0ff71b..5ef357b 100644
--- a/tests/test_glom_date_in_locales_lc_time.sh.in
+++ b/tests/test_glom_date_in_locales_lc_time.sh.in
@@ -26,16 +26,26 @@ function test_date {
echo testing with LANG="$lang" and LC_TIME="$lc_time"
export LANG="$lang"
+ export LC_TIME="$lc_time"
- # 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"
+ @abs_top_builddir@/glom/glom --debug-date-check || exit 1
+}
+
+function test_date_with_language {
+ lang="$1"
+ lc_time="$2"
+
+ echo testing with LANG="$lang" and LC_TIME="$lc_time"
+ export LANG="$lang"
+ 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_with_language "en_US.UTF-8" "en_GB.UTF-8"
test_date "en_US.UTF-8" "es_ES.UTF-8"
+test_date_with_language "en_US.UTF-8" "es_ES.UTF-8"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]