Commit e2429937 authored by Murray Cumming's avatar Murray Cumming
Browse files

translations change in progress

More in progress

More in progress 2
parent 984507fa
......@@ -68,6 +68,9 @@ namespace Glom
// Global application variable
Application* global_application = 0;
Glib::ustring Application::m_current_locale;
Glib::ustring Application::m_original_locale;
const char* Application::glade_id("window_main");
const bool Application::glade_developer(false);
......@@ -906,9 +909,14 @@ void Application::init_create_document()
if(!m_pDocument)
{
Document* document_glom = new Document();
//By default, we assume that the original is in the current locale.
document_glom->set_translation_original_locale(Application::get_current_locale());
m_pDocument = document_glom;
//document_glom->set_parent_window(this); //So that it can show a BusyCursor when loading and saving.
//Tell document about view:
m_pDocument->set_view(m_pFrame);
......@@ -987,6 +995,9 @@ bool Application::on_document_load()
if(!pDocument)
return false;
//Set this so that Application::get_current_locale() works as expected:
Application::set_original_locale(pDocument->get_translation_original_locale());
if(!pDocument->get_is_new() && !check_document_hosting_mode_is_supported(pDocument))
return false;
......@@ -1998,7 +2009,7 @@ void Application::fill_menu_tables()
ui_description += "<menuitem action='" + action_name + "' />";
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create(action_name, Utils::string_escape_underscores(table_info->get_title_or_name()));
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create(action_name, Utils::string_escape_underscores(table_info->get_title_or_name(Application::get_current_locale())));
m_refNavTablesActionGroup->add(refAction,
sigc::bind( sigc::mem_fun(*m_pFrame, &Frame_Glom::on_box_tables_selected), table_info->get_name()) );
......@@ -2067,7 +2078,7 @@ void Application::fill_menu_reports(const Glib::ustring& table_name)
ui_description += "<menuitem action='" + action_name + "' />";
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create( action_name, Utils::string_escape_underscores(report->get_title_or_name()));
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create( action_name, Utils::string_escape_underscores(report->get_title_or_name(Application::get_current_locale())));
m_refNavReportsActionGroup->add(refAction,
sigc::bind( sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_report_selected), report->get_name()) );
......@@ -2148,7 +2159,7 @@ void Application::fill_menu_print_layouts(const Glib::ustring& table_name)
ui_description += "<menuitem action='" + action_name + "' />";
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create( action_name, Utils::string_escape_underscores(print_layout->get_title_or_name()));
Glib::RefPtr<Gtk::Action> refAction = Gtk::Action::create( action_name, Utils::string_escape_underscores(print_layout->get_title_or_name(Application::get_current_locale())));
m_refNavPrintLayoutsActionGroup->add(refAction,
sigc::bind( sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_print_layout_selected), print_layout->get_name()) );
......@@ -2513,7 +2524,7 @@ void Application::on_menu_developer_changelanguage()
if(response == Gtk::RESPONSE_OK)
{
TranslatableItem::set_current_locale(dialog->get_locale());
Application::set_current_locale(dialog->get_locale());
//Get the translations from the document (in Operator mode, we only load the necessary translations.)
//This also updates the UI, so we show all the translated titles:
......@@ -2733,7 +2744,7 @@ void Application::update_window_title()
//Show the table title:
const Glib::ustring table_name = m_pFrame->get_shown_table_name();
Glib::ustring table_label = document->get_table_title(table_name);
Glib::ustring table_label = document->get_table_title(table_name, Application::get_current_locale());
if(!table_label.empty())
{
#ifndef GLOM_ENABLE_CLIENT_ONLY
......@@ -2840,4 +2851,57 @@ void Application::clear_progress_message()
m_pFrame->set_sensitive();
}
void Application::set_current_locale(const Glib::ustring& locale)
{
if(locale.empty())
return;
m_current_locale = locale;
}
void Application::set_original_locale(const Glib::ustring& locale)
{
if(locale.empty())
return;
m_original_locale = locale;
}
Glib::ustring Application::get_original_locale()
{
if(m_original_locale.empty())
m_original_locale = "en_US"; //"en_US.UTF-8";
return m_original_locale;
}
bool Application::get_current_locale_not_original() //TODO: Make this const?
{
if(m_original_locale.empty())
get_original_locale();
if(m_current_locale.empty())
get_current_locale();
return m_original_locale != m_current_locale;
}
Glib::ustring Application::get_current_locale()
{
//Return a previously-set current locale, if any:
if(!m_current_locale.empty())
return m_current_locale;
//Get the user's current locale:
const char* cLocale = setlocale(LC_ALL, 0); //Passing NULL means query, instead of set.
if(cLocale)
{
//std::cout << "debug1: " << G_STRFUNC << ": locale=" << cLocale << std::endl;
return Utils::locale_simplify(cLocale);
//std::cout << "debug2: " << G_STRFUNC << ": m_current_locale=" << m_current_locale << std::endl;
}
else
return "C";
}
} //namespace Glom
......@@ -128,6 +128,26 @@ public:
void pulse_progress_message();
void clear_progress_message();
/** Set the locale used for original text of titles. This
* must usually be stored in the document.
* Ideally, it would be English.
*/
static void set_original_locale(const Glib::ustring& locale);
static Glib::ustring get_original_locale();
static bool get_current_locale_not_original();
/** Set the locale used for titles, to test translations.
* Usually the current locale is just the locale at startup.
*/
static void set_current_locale(const Glib::ustring& locale);
/** Get the locale used by this program when it was started,
* or the locale set by set_current_locale().
*/
static Glib::ustring get_current_locale();
static Application* get_application();
protected:
......@@ -272,6 +292,8 @@ private:
Glib::ustring m_temp_username, m_temp_password;
bool m_show_sql_debug;
static Glib::ustring m_current_locale, m_original_locale;
};
} //namespace Glom
......
......@@ -19,6 +19,7 @@
*/
#include <glom/box_reports.h>
#include <glom/application.h>
#include <libglom/utils.h> //For bold_message()).
#include <gtkmm/alignment.h>
#include <gtkmm/dialog.h>
......@@ -64,7 +65,7 @@ void Box_Reports::fill_row(const Gtk::TreeModel::iterator& iter, const sharedptr
const Glib::ustring report_name = report->get_name();
m_AddDel.set_value_key(iter, report_name);
m_AddDel.set_value(iter, m_colReportName, report_name);
m_AddDel.set_value(iter, m_colTitle, report->get_title());
m_AddDel.set_value(iter, m_colTitle, report->get_title(Application::get_current_locale()));
}
}
......@@ -140,7 +141,7 @@ void Box_Reports::on_adddel_Add(const Gtk::TreeModel::iterator& row)
m_AddDel.set_value(row, m_colTitle, title);
}
report->set_title(title);
report->set_title(title, Application::get_current_locale());
get_document()->set_report(m_table_name, report);
}
......@@ -188,7 +189,7 @@ void Box_Reports::save_to_document()
sharedptr<Report> report(new Report());
report->set_name(report_name);
report->set_title( m_AddDel.get_value(iter, m_colTitle) ); //TODO: Translations: Store the original in the TreeView.
report->set_title( m_AddDel.get_value(iter, m_colTitle) , Application::get_current_locale()); //TODO: Translations: Store the original in the TreeView.
get_document()->set_report(m_table_name, report);
modified = true;
......@@ -213,7 +214,7 @@ void Box_Reports::on_adddel_changed(const Gtk::TreeModel::iterator& row, guint c
{
if(column == m_colTitle)
{
report->set_title( m_AddDel.get_value(row, m_colTitle) );
report->set_title( m_AddDel.get_value(row, m_colTitle) , Application::get_current_locale());
//TODO: Unnecessary:
document->set_report(m_table_name, report);
}
......
......@@ -1167,7 +1167,7 @@ void Frame_Glom::on_dialog_add_related_table_response(int response)
sharedptr<Relationship> relationship = sharedptr<Relationship>::create();
relationship->set_name(relationship_name);
relationship->set_title(Utils::title_from_string(relationship_name));
relationship->set_title(Utils::title_from_string(relationship_name), Application::get_current_locale());
relationship->set_from_table(m_table_name);
relationship->set_from_field(from_key_name);
relationship->set_to_table(table_name);
......@@ -1365,7 +1365,7 @@ void Frame_Glom::show_table_title()
return;
//Show the table title:
Glib::ustring table_label = document->get_table_title(m_table_name);
Glib::ustring table_label = document->get_table_title(m_table_name, Application::get_current_locale());
if(!table_label.empty())
{
if(document->get_userlevel() == AppState::USERLEVEL_DEVELOPER)
......@@ -2294,7 +2294,7 @@ void Frame_Glom::on_menu_report_selected(const Glib::ustring& report_name)
FoundSet found_set = m_Notebook_Data.get_found_set();
ReportBuilder report_builder;
ReportBuilder report_builder(Application::get_current_locale());
report_builder.set_document(document);
const std::string filepath =
report_builder.report_build_and_save(found_set, report); //TODO: Use found set's where_clause.
......
......@@ -59,18 +59,27 @@ bool HasTitleSingular::operator!=(const HasTitleSingular& src) const
}
Glib::ustring HasTitleSingular::get_title_singular() const
Glib::ustring HasTitleSingular::get_title_singular(const Glib::ustring& locale) const
{
Glib::ustring result;
if(m_title_singular)
result = m_title_singular->get_title();
result = m_title_singular->get_title(locale);
return result;
}
Glib::ustring HasTitleSingular::get_title_singular_with_fallback() const
Glib::ustring HasTitleSingular::get_title_singular_original() const
{
const Glib::ustring result = get_title_singular();
Glib::ustring result;
if(m_title_singular)
result = m_title_singular->get_title_original();
return result;
}
Glib::ustring HasTitleSingular::get_title_singular_with_fallback(const Glib::ustring& locale) const
{
const Glib::ustring result = get_title_singular(locale);
if(!result.empty())
return result;
......@@ -78,18 +87,18 @@ Glib::ustring HasTitleSingular::get_title_singular_with_fallback() const
//then try getting the regular title instead.
const TranslatableItem* translatable = dynamic_cast<const TranslatableItem*>(this);
if(translatable)
return translatable->get_title_or_name();
return translatable->get_title_or_name(locale);
return result;
}
void HasTitleSingular::set_title_singular(const Glib::ustring& title)
void HasTitleSingular::set_title_singular(const Glib::ustring& title, const Glib::ustring& locale)
{
if(!m_title_singular)
m_title_singular = sharedptr<TranslatableItem>::create();
m_title_singular->set_title(title);
m_title_singular->set_title(title, locale);
}
} //namespace Glom
......@@ -45,17 +45,21 @@ public:
/** Get the (translation of the) singular form of the title, in the current locale,
* if specified.
*/
Glib::ustring get_title_singular() const;
Glib::ustring get_title_singular(const Glib::ustring& locale) const;
/** Get the title's original (non-translated, usually English) text.
*/
Glib::ustring get_title_singular_original() const;
/** Get the (translation of the) singular form of the title, in the current locale,
* if specified, falling back to the non-singular title, and
* then falling back to the table name.
*/
Glib::ustring get_title_singular_with_fallback() const;
Glib::ustring get_title_singular_with_fallback(const Glib::ustring& locale) const;
/** Set the singular title's translation for the current locale.
*/
void set_title_singular(const Glib::ustring& title);
void set_title_singular(const Glib::ustring& title, const Glib::ustring& locale);
/** For instance, "Customer" if the table is titled "Customers".
* This is useful in some UI strings.
......
......@@ -207,7 +207,7 @@ void FieldFormatting::set_choices_custom(const type_list_values& choices)
m_choices_custom_list = choices;
}
Glib::ustring FieldFormatting::get_custom_choice_original_for_translated_text(const Glib::ustring& text) const
Glib::ustring FieldFormatting::get_custom_choice_original_for_translated_text(const Glib::ustring& text, const Glib::ustring& locale) const
{
for(FieldFormatting::type_list_values::const_iterator iter = m_choices_custom_list.begin(); iter != m_choices_custom_list.end(); ++iter)
{
......@@ -215,14 +215,14 @@ Glib::ustring FieldFormatting::get_custom_choice_original_for_translated_text(co
if(!value)
continue;
if(value->get_title() == text)
if(value->get_title(locale) == text)
return value->get_title_original();
}
return Glib::ustring();
}
Glib::ustring FieldFormatting::get_custom_choice_translated(const Glib::ustring& original_text) const
Glib::ustring FieldFormatting::get_custom_choice_translated(const Glib::ustring& original_text, const Glib::ustring& locale) const
{
for(FieldFormatting::type_list_values::const_iterator iter = m_choices_custom_list.begin(); iter != m_choices_custom_list.end(); ++iter)
{
......@@ -231,7 +231,7 @@ Glib::ustring FieldFormatting::get_custom_choice_translated(const Glib::ustring&
continue;
if(value->get_title_original() == original_text)
return value->get_title();
return value->get_title(locale);
}
return Glib::ustring();
......
......@@ -62,12 +62,12 @@ public:
/** Get the original text that corresponds to the translated choice for the
* current locale.
*/
Glib::ustring get_custom_choice_original_for_translated_text(const Glib::ustring& text) const;
Glib::ustring get_custom_choice_original_for_translated_text(const Glib::ustring& text, const Glib::ustring& locale = Glib::ustring()) const;
/** Get the translated choice text, for the
* current locale, that corresponds to the original text .
*/
Glib::ustring get_custom_choice_translated(const Glib::ustring& original_text) const;
Glib::ustring get_custom_choice_translated(const Glib::ustring& original_text, const Glib::ustring& locale = Glib::ustring()) const;
typedef std::pair< sharedptr<const LayoutItem_Field>, bool /* is_ascending */> type_pair_sort_field;
typedef std::list<type_pair_sort_field> type_list_sort_fields;
......
......@@ -115,53 +115,114 @@ Glib::ustring LayoutItem_Field::get_name() const
return LayoutItem_WithFormatting::get_name();
}
Glib::ustring LayoutItem_Field::get_title_no_custom() const
Glib::ustring LayoutItem_Field::get_title_no_custom(const Glib::ustring& locale) const
{
//Use the field's default title:
if(m_field_cache_valid && m_field)
{
return m_field->get_title_or_name();
return m_field->get_title_or_name(locale);
}
else
return get_name(); //We ignore TranslatableItem::get_title() for LayoutItem_Field.
}
Glib::ustring LayoutItem_Field::get_title_no_custom_translation(const Glib::ustring& locale, bool fallback) const
{
//Use the field's default title:
if(m_field_cache_valid && m_field)
{
return m_field->get_title_translation(locale, fallback);
}
else
return Glib::ustring();
}
Glib::ustring LayoutItem_Field::get_title_no_custom_original() const
{
//Use the field's default title:
if(m_field_cache_valid && m_field)
{
return m_field->get_title_original();
}
else
return get_name(); //We ignore TranslatableItem::get_title() for LayoutItem_Field.
}
Glib::ustring LayoutItem_Field::get_title_or_name_no_custom() const
Glib::ustring LayoutItem_Field::get_title_or_name_no_custom(const Glib::ustring& locale) const
{
//Use the field's default title:
if(m_field_cache_valid && m_field)
{
return m_field->get_title();
return m_field->get_title(locale);
}
return Glib::ustring();
}
Glib::ustring LayoutItem_Field::get_title() const
Glib::ustring LayoutItem_Field::get_title(const Glib::ustring& locale) const
{
//Use the custom title (overriding the field's default title), if there is one:
//This may even be empty if the developer specifies that.
if(m_title_custom && m_title_custom->get_use_custom_title())
{
return m_title_custom->get_title(locale);
}
//Use the field's default title:
return get_title_no_custom(locale);
}
Glib::ustring LayoutItem_Field::get_title_translation(const Glib::ustring& locale, bool fallback) const
{
//Use the custom title (overriding the field's default title), if there is one:
//This may even be empty if the developer specifies that.
if(m_title_custom && m_title_custom->get_use_custom_title())
{
return m_title_custom->get_title_translation(locale, fallback);
}
return m_field->get_title_translation(locale, fallback);
}
Glib::ustring LayoutItem_Field::get_title_original() const
{
//Use the custom title (overriding the field's default title), if there is one:
//This may even be empty if the developer specifies that.
if(m_title_custom && m_title_custom->get_use_custom_title())
{
return m_title_custom->get_title_original();
}
//Use the field's default title:
return get_title_no_custom_original();
}
Glib::ustring LayoutItem_Field::get_title_or_name(const Glib::ustring& locale) const
{
//Use the custom title (overriding the field's default title), if there is one:
//This may even be empty if the developer specifies that.
if(m_title_custom && m_title_custom->get_use_custom_title())
{
return m_title_custom->get_title();
return m_title_custom->get_title(locale);
}
//Use the field's default title:
return get_title_no_custom();
return get_title_no_custom(locale);
}
Glib::ustring LayoutItem_Field::get_title_or_name() const
Glib::ustring LayoutItem_Field::get_title_or_name_original() const
{
//Use the custom title (overriding the field's default title), if there is one:
//This may even be empty if the developer specifies that.
if(m_title_custom && m_title_custom->get_use_custom_title())
{
return m_title_custom->get_title();
return m_title_custom->get_title_original();
}
//Use the field's default title:
return get_title_no_custom();
return get_title_no_custom_original();
}
bool LayoutItem_Field::get_editable_and_allowed() const
......
......@@ -86,13 +86,24 @@ public:
/** Get the user-visible title for the field, in the user's current locale.
* This returns the name if no title is set.
*/
virtual Glib::ustring get_title() const;
virtual Glib::ustring get_title(const Glib::ustring& locale) const;
/** Get the user-visible title for the field, in the user's current locale.
* This returns the name if no title is set.
*/
virtual Glib::ustring get_title_original() const;
virtual Glib::ustring get_title_translation(const Glib::ustring& locale, bool fallback = true) const;
/** Get the user-visible title for the field, in the user's current locale.
*/
virtual Glib::ustring get_title_or_name() const;
virtual Glib::ustring get_title_or_name(const Glib::ustring& locale) const;
Glib::ustring get_title_or_name_no_custom() const;
/** Get the user-visible title for the field, in the original locale.
*/
virtual Glib::ustring get_title_or_name_original() const;
Glib::ustring get_title_or_name_no_custom(const Glib::ustring& locale) const;
sharedptr<const CustomTitle> get_title_custom() const;
sharedptr<CustomTitle> get_title_custom();
......@@ -163,7 +174,12 @@ public:
private:
Glib::ustring get_title_no_custom() const;
Glib::ustring get_title_no_custom(const Glib::ustring& locale) const;
Glib::ustring get_title_no_custom_original() const;
Glib::ustring get_title_no_custom_translation(const Glib::ustring& locale, bool fallback = true) const;
//This is just a cache, filled in by looking at the database structure:
sharedptr<const Field> m_field;
......
......@@ -414,9 +414,9 @@ sharedptr<const LayoutItem_Field> LayoutItem_Portal::get_field_identifies_non_hi
return result;
}
Glib::ustring LayoutItem_Portal::get_title_or_name() const
Glib::ustring LayoutItem_Portal::get_title_or_name(const Glib::ustring& locale) const
{
Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */);
Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */, locale);
if(title.empty())
title = get_relationship_name_used();
......@@ -426,9 +426,9 @@ Glib::ustring LayoutItem_Portal::get_title_or_name() const
return title;
}
Glib::ustring LayoutItem_Portal::get_title() const
Glib::ustring LayoutItem_Portal::get_title(const Glib::ustring& locale) const
{
Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */);
Glib::ustring title = get_title_used(Glib::ustring() /* parent table - not relevant */, locale);
if(title.empty()) //TODO: This prevents "" as a real title.
title = _("Undefined Table");
......
......@@ -47,8 +47,10 @@ public:
virtual LayoutItem* clone() const;
virtual Glib::ustring get_title() const;
virtual Glib::ustring get_title_or_name() const;
virtual Glib::ustring get_title(const Glib::ustring& locale) const;
//TODO: get_title_original() and get_title_translation()?
virtual Glib::ustring get_title_or_name(const Glib::ustring& locale) const;
//TODO: get_title_or_name_original()?
virtual Glib::ustring get_part_type_name() const;
virtual void change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
......
......@@ -78,14 +78,19 @@ Glib::ustring LayoutItem_Text::get_report_part_id() const
return "field"; //We reuse this for this node.
}
Glib::ustring LayoutItem_Text::get_text() const
Glib::ustring LayoutItem_Text::get_text(const Glib::ustring& locale) const
{
return m_text->get_title();
return m_text->get_title(locale);
}
void LayoutItem_Text::set_text(const Glib::ustring& text)
void LayoutItem_Text::set_text(const Glib::ustring& text, const Glib::ustring& locale)
{
m_text->set_title(text);
m_text->set_title(text, locale);
}
void LayoutItem_Text::set_text_original(const Glib::ustring& text)
{
m_text->set_title_original(text);
}