[glom] get_current_locale(): Handle more complex setlocale(NULL) results.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] get_current_locale(): Handle more complex setlocale(NULL) results.
- Date: Thu, 6 Jan 2011 22:47:51 +0000 (UTC)
commit 01704c655483599cd2a7723e7ed24cd4b2556145
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jan 6 23:47:41 2011 +0100
get_current_locale(): Handle more complex setlocale(NULL) results.
* glom/libglom/utils.cc: locale_simplify(): On Ubuntu Natty,
setlocale() has started returning a more complex string. Parse it, or the
older simpler syntax.
ChangeLog | 8 +++++
glom/libglom/data_structure/translatable_item.cc | 3 +-
glom/libglom/utils.cc | 31 ++++++++++++++++++++-
glom/mode_design/iso_codes.cc | 7 +++--
glom/mode_design/translation/combobox_locale.cc | 12 ++++++--
5 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9917f08..8fad798 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2011-01-06 Murray Cumming <murrayc murrayc com>
+ get_current_locale(): Handle more complex setlocale(NULL) results.
+
+ * glom/libglom/utils.cc: locale_simplify(): On Ubuntu Natty,
+ setlocale() has started returning a more complex string. Parse it, or the
+ older simpler syntax.
+
+2011-01-06 Murray Cumming <murrayc murrayc com>
+
tests: Link to all necessary libraries.
* Makefile_libglom.am: Define libglom_all_libs to avoid duplication.
diff --git a/glom/libglom/data_structure/translatable_item.cc b/glom/libglom/data_structure/translatable_item.cc
index 86238fa..04fd85d 100644
--- a/glom/libglom/data_structure/translatable_item.cc
+++ b/glom/libglom/data_structure/translatable_item.cc
@@ -207,8 +207,9 @@ Glib::ustring TranslatableItem::get_current_locale()
const char* cLocale = setlocale(LC_ALL, 0); //Passing NULL means query, instead of set.
if(cLocale)
{
- //std::cout << "debug: " << G_STRFUNC << ": locale=" << cLocale << std::endl;
+ //std::cout << "debug1: " << G_STRFUNC << ": locale=" << cLocale << std::endl;
m_current_locale = Utils::locale_simplify(cLocale);
+ //std::cout << "debug2: " << G_STRFUNC << ": m_current_locale=" << m_current_locale << std::endl;
}
else
m_current_locale = 'C';
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index fc0b4a6..baa1b7a 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -631,20 +631,47 @@ Glib::ustring Utils::string_escape_underscores(const Glib::ustring& text)
Glib::ustring Utils::locale_simplify(const Glib::ustring& locale_id)
{
Glib::ustring result = locale_id;
-
+
+ //At least Ubuntu Natty provides a long string such as this: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=en_US.UTF-8;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_AG.utf8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8
+ //In Ubuntu Maverick, and earlier, it was apparently a simple string such as en_US.UTF-8.
+
+ //Look for LC_ALL or LC_COLLATE
+ //(We use the locale name only to identify translations
+ //Otherwise just start with the whole string.
+ Glib::ustring::size_type posCategory = result.find("LC_ALL=");
+ if(posCategory != Glib::ustring::npos)
+ {
+ result = result.substr(posCategory);
+ }
+ else
+ {
+ posCategory = result.find("LC_COLLATE=");
+ if(posCategory != Glib::ustring::npos)
+ {
+ result = result.substr(posCategory);
+ }
+ }
+
//Get everything before the .:
- Glib::ustring::size_type posDot = locale_id.find('.');
+ const Glib::ustring::size_type posDot = result.find('.');
if(posDot != Glib::ustring::npos)
{
result = result.substr(0, posDot);
}
//Get everything before the @:
- const Glib::ustring::size_type posAt = locale_id.find('@');
+ const Glib::ustring::size_type posAt = result.find('@');
if(posAt != Glib::ustring::npos)
{
result = result.substr(0, posAt);
}
+
+ //Get everything after the =, if any:
+ const Glib::ustring::size_type posEquals = result.find('=');
+ if(posEquals != Glib::ustring::npos)
+ {
+ result = result.substr(posEquals + 1);
+ }
return result;
}
diff --git a/glom/mode_design/iso_codes.cc b/glom/mode_design/iso_codes.cc
index 285baa4..9b3070d 100644
--- a/glom/mode_design/iso_codes.cc
+++ b/glom/mode_design/iso_codes.cc
@@ -107,7 +107,7 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
typedef std::list<std::string> type_list_ids;
type_list_ids list_ids;
- Glib::ustring locales_path = "/usr/share/i18n/locales/";
+ const std::string locales_path = "/usr/share/i18n/locales/";
try
{
Glib::Dir dir(locales_path);
@@ -122,7 +122,7 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
typedef std::map<Glib::ustring, Glib::ustring> type_map_language; //ID to language name.
type_map_language map_languages;
- const Glib::ustring filename_languages = ISO_CODES_PREFIX "/share/xml/iso-codes/iso_639.xml";
+ const std::string filename_languages = ISO_CODES_PREFIX "/share/xml/iso-codes/iso_639.xml";
#ifdef LIBXMLCPP_EXCEPTIONS_ENABLED
try
@@ -227,7 +227,7 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
}
#endif // LIBXMLCPP_EXCEPTIONS_ENABLED
- //Use a map so we can easily check for duplicates.
+ //Use a map so we can easily check for duplicates.
for(type_list_ids::iterator iter = list_ids.begin(); iter != list_ids.end(); ++iter)
{
const Glib::ustring identifier = Utils::locale_simplify(*iter);
@@ -262,6 +262,7 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
the_locale.m_identifier = identifier;
the_locale.m_name = name;
map_locales[identifier] = the_locale;
+ //std::cout << "DEBUG: id=" << identifier << ", name=" << name << std::endl;
}
}
}
diff --git a/glom/mode_design/translation/combobox_locale.cc b/glom/mode_design/translation/combobox_locale.cc
index a238026..cfdce41 100644
--- a/glom/mode_design/translation/combobox_locale.cc
+++ b/glom/mode_design/translation/combobox_locale.cc
@@ -84,17 +84,23 @@ void ComboBox_Locale::set_selected_locale(const Glib::ustring& locale)
for(Gtk::TreeModel::iterator iter = model->children().begin(); iter != model->children().end(); ++iter)
{
const Glib::ustring& this_text = (*iter)[m_model_columns.m_identifier];
-
+ //std::cout << G_STRFUNC << ": DEBUG: locale=" << locale << ", this_text=" << this_text << "." << std::endl;
+
if(this_text == locale)
{
set_active(iter);
return; //success
}
}
+
+ //Not found, so mark it as blank:
+ std::cerr << G_STRFUNC << ": locale not found in list: " << locale << ", list size=" << model->children().size() << std::endl;
+ }
+ else
+ {
+ std::cerr << G_STRFUNC << ": locale not found in list: " << locale << ". The model is empty." << std::endl;
}
- //Not found, so mark it as blank:
- std::cerr << G_STRFUNC << ": locale not found in list: " << locale << std::endl;
unset_active();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]