[glom] Document: Added get_translation_available_locales().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Document: Added get_translation_available_locales().
- Date: Wed, 14 Dec 2011 14:48:31 +0000 (UTC)
commit a6a94195ad1dd745b492f5ab3b545ac95ab4c53b
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Dec 14 15:48:12 2011 +0100
Document: Added get_translation_available_locales().
* glom/libglom/document/document.[h|cc]: load_after(),
load_after_translations(): Remember any new locales encountered, so
that get_translation_available_locales() can later return the list.
This could help with OnlineGlom bug #666165 .
* tests/test_document_load_translations.cc: Test the new method.
ChangeLog | 10 ++++++++++
glom/libglom/document/document.cc | 16 +++++++++++++++-
glom/libglom/document/document.h | 6 ++++++
tests/test_document_load_translations.cc | 4 ++++
4 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 853b1f4..d49c9e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-12-14 Murray Cumming <murrayc murrayc com>
+
+ Document: Added get_translation_available_locales().
+
+ * glom/libglom/document/document.[h|cc]: load_after(),
+ load_after_translations(): Remember any new locales encountered, so
+ that get_translation_available_locales() can later return the list.
+ This could help with OnlineGlom bug #666165 .
+ * tests/test_document_load_translations.cc: Test the new method.
+
2011-12-13 Murray Cumming <murrayc murrayc com>
Correct parsing of example data.
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 9079e70..92a5fc1 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -2528,6 +2528,13 @@ void Document::load_after_translations(const xmlpp::Element* element, Translatab
const Glib::ustring locale = get_node_attribute_value(element, GLOM_ATTRIBUTE_TRANSLATION_LOCALE);
const Glib::ustring translation = get_node_attribute_value(element, GLOM_ATTRIBUTE_TRANSLATION_VALUE);
item.set_translation(locale, translation);
+
+ //Remember any new translation locales in our cached list:
+ if(std::find(m_translation_available_locales.begin(),
+ m_translation_available_locales.end(), locale) == m_translation_available_locales.end())
+ {
+ m_translation_available_locales.push_back(locale);
+ }
}
}
}
@@ -2584,6 +2591,8 @@ bool Document::load_after(int& failure_code)
if(result)
{
+ m_translation_available_locales.clear();
+
const xmlpp::Element* nodeRoot = get_node_document();
if(nodeRoot)
{
@@ -2604,6 +2613,7 @@ bool Document::load_after(int& failure_code)
m_translation_original_locale = get_node_attribute_value(nodeRoot, GLOM_ATTRIBUTE_TRANSLATION_ORIGINAL_LOCALE);
TranslatableItem::set_original_locale(m_translation_original_locale);
+ m_translation_available_locales.push_back(m_translation_original_locale); //Just a cache.
const xmlpp::Element* nodeConnection = get_node_child_named(nodeRoot, GLOM_NODE_CONNECTION);
if(nodeConnection)
@@ -4321,12 +4331,16 @@ void Document::set_translation_original_locale(const Glib::ustring& locale)
set_modified();
}
-
Glib::ustring Document::get_translation_original_locale() const
{
return m_translation_original_locale;
}
+std::vector<Glib::ustring> Document::get_translation_available_locales() const
+{
+ return m_translation_available_locales;
+}
+
Document::type_list_translatables Document::get_translatable_layout_items(const Glib::ustring& table_name)
{
type_list_translatables result;
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 3ed7d25..117f7f1 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -174,6 +174,11 @@ public:
*/
Glib::ustring get_translation_original_locale() const;
+ /** Get a list of locales for which at least one string is translated.
+ * The result will include the original, from get_translation_original_locale().
+ */
+ std::vector<Glib::ustring> get_translation_available_locales() const;
+
typedef std::vector< sharedptr<Relationship> > type_vec_relationships;
type_vec_relationships get_relationships(const Glib::ustring& table_name, bool plus_system_prefs = false) const;
void set_relationships(const Glib::ustring& table_name, const type_vec_relationships& vecRelationships);
@@ -636,6 +641,7 @@ private:
Glib::ustring m_database_title;
Glib::ustring m_translation_original_locale;
+ std::vector<Glib::ustring> m_translation_available_locales; //Just a cache, based on other data.
typedef std::map<Glib::ustring, Glib::ustring> type_map_library_scripts;
type_map_library_scripts m_map_library_scripts;
diff --git a/tests/test_document_load_translations.cc b/tests/test_document_load_translations.cc
index 3b27408..d73c598 100644
--- a/tests/test_document_load_translations.cc
+++ b/tests/test_document_load_translations.cc
@@ -135,6 +135,10 @@ int main()
return EXIT_FAILURE;
}
+ const std::vector<Glib::ustring> locales = document.get_translation_available_locales();
+ g_assert(locales.size() == 3);
+ g_assert(contains(locales, "de_DE"));
+
const std::vector<Glib::ustring> table_names = document.get_table_names();
g_assert(contains(table_names, "scenes"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]