[glom] Translations: Offer non-country-specific language locales too.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Translations: Offer non-country-specific language locales too.
- Date: Mon, 9 Jan 2012 22:11:50 +0000 (UTC)
commit fbefdf71c47e15f66540311643440ad670219ef0
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jan 9 23:10:53 2012 +0100
Translations: Offer non-country-specific language locales too.
* Makefile_tests.am:
* glom/libglom/utils.cc: locale_language_id(): Parse language-only
locale IDs too.
* glom/mode_design/iso_codes.cc: get_locale_name(): Create non-country
locale IDs too, though they are not in the iso-codes XML file.
* glom/mode_design/translation/window_translations.cc: Show, for instance
German (de) as well as the existing German (Germany), German (Austria),
etc.
ChangeLog | 13 +++++++
Makefile_tests.am | 12 +++++-
glom/libglom/utils.cc | 11 +++---
glom/mode_design/iso_codes.cc | 39 +++++++++++++++++---
.../mode_design/translation/window_translations.cc | 16 +++++---
5 files changed, 73 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0499c75..321c662 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2012-01-09 Murray Cumming <murrayc murrayc com>
+ Translations: Offer non-country-specific language locales too.
+
+ * Makefile_tests.am:
+ * glom/libglom/utils.cc: locale_language_id(): Parse language-only
+ locale IDs too.
+ * glom/mode_design/iso_codes.cc: get_locale_name(): Create non-country
+ locale IDs too, though they are not in the iso-codes XML file.
+ * glom/mode_design/translation/window_translations.cc: Show, for instance
+ German (de) as well as the existing German (Germany), German (Austria),
+ etc.
+
+2012-01-09 Murray Cumming <murrayc murrayc com>
+
Add rules for batch .po import and export for the examples.
* Makefile.am: Add examples_export_po and examples_import_po targets
diff --git a/Makefile_tests.am b/Makefile_tests.am
index b106767..e106728 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -274,7 +274,8 @@ check_PROGRAMS += \
tests/python/test_python_execute_func_date \
tests/python/test_python_execute_func_change_result_type \
tests/python/test_python_execute_func_with_record \
- tests/python/test_python_execute_script
+ tests/python/test_python_execute_script \
+ tests/test_iso_codes
# glom/mode_data/test_flowtablewithfields
# glom/utility_widgets/canvas/test_canvas_editable
@@ -286,7 +287,8 @@ TESTS += \
tests/python/test_python_execute_func_date \
tests/python/test_python_execute_func_change_result_type \
tests/python/test_python_execute_func_with_record \
- tests/python/test_python_execute_script
+ tests/python/test_python_execute_script \
+ tests/test_iso_codes
glom_utility_widgets_test_flowtable_SOURCES = \
glom/utility_widgets/flowtable.cc \
@@ -349,6 +351,12 @@ tests_python_test_python_execute_script_SOURCES = tests/python/test_python_execu
tests_python_test_python_execute_script_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
tests_python_test_python_execute_script_CPPFLAGS = $(tests_cppflags_ui)
+tests_test_iso_codes_SOURCES = tests/test_iso_codes.cc \
+ glom/mode_design/iso_codes.cc \
+ glom/mode_design/iso_codes.h
+tests_test_iso_codes_LDADD = $(tests_ldadd) $(GLOM_LIBS)
+tests_test_iso_codes_CPPFLAGS = $(tests_cppflags_ui)
+
# You must remove PlaceholderGlom::get_application() to avoid having to specify
# a huge set of .cc files when building this test:
#glom_utility_widgets_test_flowtable_dnd_SOURCES = \
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index bb588dd..7600dcf 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -730,15 +730,16 @@ Glib::ustring Utils::locale_simplify(const Glib::ustring& locale_id)
Glib::ustring Utils::locale_language_id(const Glib::ustring& locale_id)
{
- Glib::ustring result;
-
const Glib::ustring::size_type posUnderscore = locale_id.find('_');
if(posUnderscore != Glib::ustring::npos)
{
- result = locale_id.substr(0, posUnderscore);
+ return locale_id.substr(0, posUnderscore);
+ }
+ else
+ {
+ //We assume that this locale ID specifies a language but no specific country.
+ return locale_id;
}
-
- return result;
}
Glib::ustring Utils::create_local_image_uri(const Gnome::Gda::Value& value)
diff --git a/glom/mode_design/iso_codes.cc b/glom/mode_design/iso_codes.cc
index a9bc379..da2d4f5 100644
--- a/glom/mode_design/iso_codes.cc
+++ b/glom/mode_design/iso_codes.cc
@@ -22,7 +22,7 @@
#include <glom/mode_design/iso_codes.h>
#include <libxml++/libxml++.h>
-#include <libglom/document/document.h>
+//#include <libglom/document/document.h>
#include <libglom/utils.h>
#include <glibmm/fileutils.h>
#include <glibmm/i18n.h>
@@ -99,6 +99,16 @@ type_list_currencies get_list_of_currency_symbols()
return list_currencies;
}
+static void split_locale_id(const Glib::ustring& locale_id, Glib::ustring& language_id, Glib::ustring& country_id)
+{
+ //Split the locale ID into language and country parts:
+ language_id = Utils::locale_language_id(locale_id);
+
+ country_id.clear();
+ if(!language_id.empty() && ((language_id.size() +1) < locale_id.size()))
+ country_id = locale_id.substr(language_id.size() + 1);
+}
+
Glib::ustring get_locale_name(const Glib::ustring& locale_id)
{
//Build the list of locales, with their translated language and countries names:
@@ -119,6 +129,26 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
std::cerr << G_STRFUNC << ": Could not open (or read) glibc locales directory: " << locales_path << "Error: " << ex.what() << std::endl;
}
+ //Make sure that we list non-specific versions of the locales too,
+ //because this is normally what translators translate to.
+ //For instance, po/ files generally contain po/de.po.
+ type_list_ids list_ids_simple;
+ for(type_list_ids::const_iterator iter = list_ids.begin(); iter != list_ids.end(); ++iter)
+ {
+ const Glib::ustring id = *iter;
+ Glib::ustring id_language, id_country;
+ split_locale_id(id, id_language, id_country);
+ list_ids_simple.push_back(id_language);
+ }
+
+ //Add the non-specific locales:
+ for(type_list_ids::const_iterator iter = list_ids_simple.begin(); iter != list_ids_simple.end(); ++iter)
+ {
+ const Glib::ustring id = *iter;
+ if(std::find(list_ids.begin(), list_ids.end(), id) == list_ids.end())
+ list_ids.push_back(id);
+ }
+
//Get the (translated) language names:
typedef std::map<Glib::ustring, Glib::ustring> type_map_language; //ID to language name.
type_map_language map_languages;
@@ -236,10 +266,9 @@ Glib::ustring get_locale_name(const Glib::ustring& locale_id)
if(map_locales.find(identifier) == map_locales.end()) //Prevent duplicates.
{
//Split the locale ID into language and country parts:
- Glib::ustring id_language = Utils::locale_language_id(identifier);
- Glib::ustring id_country;
- if(!id_language.empty() && ((id_language.size() +1) < identifier.size()))
- id_country = identifier.substr(id_language.size() + 1);
+ Glib::ustring id_language, id_country;
+ split_locale_id(identifier, id_language, id_country);
+ //std::cout << "debug: id_language=" << id_language << ", id_country=" << id_country << std::endl;
//Get the translated human-readable names of the language and country:
Glib::ustring name;
diff --git a/glom/mode_design/translation/window_translations.cc b/glom/mode_design/translation/window_translations.cc
index f33bf66..48d0247 100644
--- a/glom/mode_design/translation/window_translations.cc
+++ b/glom/mode_design/translation/window_translations.cc
@@ -69,19 +69,18 @@ Window_Translations::Window_Translations(BaseObjectType* cobject, const Glib::Re
column_original->pack_start(*renderer_name);
column_original->set_cell_data_func(*renderer_name, sigc::mem_fun(*this, &Window_Translations::on_cell_data_original));
+ const int col = m_treeview->append_column_editable(_("Translation"), m_columns.m_col_translation);
+ Gtk::CellRendererText* renderer = dynamic_cast<Gtk::CellRendererText*>(m_treeview->get_column_cell_renderer(col - 1));
+ if(renderer)
+ renderer->signal_edited().connect(sigc::mem_fun(*this, &Window_Translations::on_treeview_edited));
+ //This is at the end, because it can contain a long description of the item's context.
Gtk::TreeView::Column* column_item_typename = Gtk::manage( new Gtk::TreeView::Column(_("Item")) );
m_treeview->append_column(*column_item_typename);
Gtk::CellRendererText* renderer_item_typename = Gtk::manage(new Gtk::CellRendererText);
column_item_typename->pack_start(*renderer_item_typename);
column_item_typename->set_cell_data_func(*renderer_item_typename, sigc::mem_fun(*this, &Window_Translations::on_cell_data_item_itemhint));
-
-
- const int col = m_treeview->append_column_editable(_("Translation"), m_columns.m_col_translation);
- Gtk::CellRendererText* renderer = dynamic_cast<Gtk::CellRendererText*>(m_treeview->get_column_cell_renderer(col - 1));
- if(renderer)
- renderer->signal_edited().connect(sigc::mem_fun(*this, &Window_Translations::on_treeview_edited));
}
builder->get_widget("button_identify", m_button_identify);
@@ -114,6 +113,11 @@ Window_Translations::Window_Translations(BaseObjectType* cobject, const Glib::Re
m_combo_target_locale->set_selected_locale(m_translation_locale);
//The translations will be shown in the treeview when load_from_document() is called.
}
+ else
+ {
+ //Start with _some_ locale, rather than no locale:
+ m_combo_target_locale->set_active(0);
+ }
}
Window_Translations::~Window_Translations()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]