From 8216c3ff062d14097e70b504033979ab98e91d9f Mon Sep 17 00:00:00 2001 From: theAdib Date: Tue, 30 Dec 2008 20:33:13 +0000 Subject: [PATCH] add possibility to change the UI language (gettext) in preferences dialogue --- src/inkscape.cpp | 7 ++++++ src/preferences-skeleton.h | 2 ++ src/ui/dialog/inkscape-preferences.cpp | 30 ++++++++++++++++++++++ src/ui/dialog/inkscape-preferences.h | 9 +++++-- src/ui/widget/preferences-widget.cpp | 35 +++++++++++++++++++++++++- src/ui/widget/preferences-widget.h | 3 +++ 6 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 2a7f31c3e..8cd01c226 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -754,6 +754,13 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui) prefs->load(use_gui, false); inkscape_load_menus(inkscape); sp_input_load_from_preferences(); + + /* set language for user interface according setting in preferences */ + Glib::ustring i18n = prefs->getString("/i18n/language"); + if(!i18n.empty()) + { + setenv("LANGUAGE", i18n, 1); + } /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON. * Use only if use_gui is enabled diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index dd6a9a92f..6b477f12e 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -424,6 +424,8 @@ static char const preferences_skeleton[] = " \n" " \n" " \n" +" \n" "\n" "\n"; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index d656e2a53..f2611c377 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -119,6 +119,7 @@ InkscapePreferences::InkscapePreferences() initPageSteps(); initPageWindows(); initPageMisc(); + initPageI18n(); signalPresent().connect(sigc::mem_fun(*this, &InkscapePreferences::_presentPages)); @@ -1151,6 +1152,35 @@ void InkscapePreferences::initPageMisc() this->AddPage(_page_misc, _("Misc"), PREFS_PAGE_MISC); } +void InkscapePreferences::initPageI18n() +{ + Glib::ustring languages[] = {_("System default"), _("am Amharic"), _("ar Arabic"), _("az Azerbaijani"), _("be Belarusian"), + _("bg Bulgarian"), _("bn Bengali"), _("br Breton"), _("ca Catalan"), _("ca@valencia Valencian Catalan"), _("cs Czech"), + _("da Danish"), _("de German"), _("dz Dzongkha"), _("el Greek"), _("en English"), _("en_AU English, as spoken in Australia"), + _("en_CA English, as spoken in Canada"), _("en_GB English, as spoken in Great Britain"), _("en_US@piglatin Pig Latin"), + _("eo Esperanto"), _("es Spanish"), _("es_MX Spanish, as spoken in Mexico"),_("et Estonian"), _("eu Basque"), _("fi Finnish"), + _("fr French"), _("ga Irish"), _("gl Galician"), _("he Hebrew"), _("hr Croatian"), _("hu Hungarian"), _("hy Armenian"), + _("id Indonesian"), _("it Italian"), _("ja Japanese"), _("km Khmer"), _("ko Korean"), _("lt Lithuanian"), _("mk Macedonian"), + _("mn Mongolian"), _("nb Norwegian Bokmål"), _("ne Nepali"), _("nl Dutch"), _("nn Norwegian Nynorsk"), _("pa Panjabi"), + _("pl Polish"), _("pt Portuguese"), _("pt_BR Portuguese, as spoken in Brazil"), _("ro Romanian"), _("ru Russian"), + _("rw Kinyarwanda"), _("sk Slovak"), _("sl Slovenian"), _("sq Albanian"), _("sr Serbian"), _("sr@latin Serbian in Latin script"), + _("sv Swedish"), _("th Thai"), _("tr Turkish"), _("uk Ukrainian"), _("vi Vietnamese"), _("zh_CN Chinese, as spoken in China"), + _("zh_TW Chinese, as spoken in Taiwan")}; + Glib::ustring langValues[] = {"", "am", "ar", "az", "be", "bg", "bn", "br", "ca", "ca@valencia", "cs", "da", "de", + "dz", "el", "en", "en_AU", "en_CA", "en_GB", "en_US@piglatin", "eo", "es_MX", "es", "et", "eu", "fi", "fr", "ga", + "gl", "he", "hr", "hu", "hy", "id", "it", "ja", "km", "ko", "lt", "mk", "mn", "nb", "ne", "nl", "nn", "pa", + "pl", "pt_BR", "pt", "ro", "ru", "rw", "sk", "sl", "sq", "sr@latin", "sr", "sv", "th", "tr", "uk", "vi", + "zh_CN", "zh_TW"}; + + _i18n_languages.init( "/i18n/language", languages, langValues, G_N_ELEMENTS(languages), _("System")); + _page_i18n.add_line( false, _("Language for user interface"), _i18n_languages, "", + _("Set the language for menues and number-formats (requires restart)"), false); + + this->AddPage(_page_i18n, _("Internationalisation"), PREFS_PAGE_I18N); +} + + + bool InkscapePreferences::SetMaxDialogSize(const Gtk::TreeModel::iterator& iter) { Gtk::TreeModel::Row row = *iter; diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 1c5a3a85f..93b9faad0 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -75,7 +75,8 @@ enum { PREFS_PAGE_SNAPPING, PREFS_PAGE_STEPS, PREFS_PAGE_WINDOWS, - PREFS_PAGE_MISC + PREFS_PAGE_MISC, + PREFS_PAGE_I18N }; using namespace Inkscape::UI::Widget; @@ -114,7 +115,7 @@ protected: DialogPage _page_mouse, _page_scrolling, _page_snapping, _page_steps, _page_tools, _page_windows, _page_clones, _page_mask, _page_transforms, _page_filters, _page_select, _page_importexport, _page_cms, _page_grids, _page_svgoutput, _page_misc, - _page_ui, _page_autosave, _page_bitmaps; + _page_ui, _page_autosave, _page_bitmaps, _page_i18n; DialogPage _page_selector, _page_node, _page_tweak, _page_zoom, _page_shapes, _page_pencil, _page_pen, _page_calligraphy, _page_text, _page_gradient, _page_connector, _page_dropper, _page_lpetool; DialogPage _page_rectangle, _page_3dbox, _page_ellipse, _page_star, _page_spiral, _page_paintbucket, _page_eraser; @@ -230,6 +231,9 @@ protected: PrefColorPicker _grids_axonom_empcolor; PrefSpinButton _grids_axonom_empspacing; + // i18n page + PrefCombo _i18n_languages; + // SVG Output page: PrefCheckButton _svgoutput_usenamedcolors; PrefSpinButton _svgoutput_numericprecision; @@ -279,6 +283,7 @@ protected: void initPageAutosave(); void initPageBitmaps(); void initPageMisc(); + void initPageI18n(); void _presentPages(); diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 395726511..e84eaa458 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -539,12 +539,45 @@ void PrefCombo::init(Glib::ustring const &prefs_path, this->set_active(row); } +/** + initialize a combo box + second form uses strings as key values +*/ +void PrefCombo::init(Glib::ustring const &prefs_path, + Glib::ustring labels[], Glib::ustring values[], int num_items, Glib::ustring default_value) +{ + _prefs_path = prefs_path; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int row = 0; + Glib::ustring value = prefs->getString(_prefs_path); + if(value.empty()) + { + value = default_value; + } + + for (int i = 0 ; i < num_items; ++i) + { + this->append_text(labels[i]); + _ustr_values.push_back(values[i]); + if (value == values[i]) + row = i; + } + this->set_active(row); +} + void PrefCombo::on_changed() { if (this->is_visible()) //only take action if user changed value { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(_prefs_path, _values[this->get_active_row_number()]); + if(_values.size() > 0) + { + prefs->setInt(_prefs_path, _values[this->get_active_row_number()]); + } + else + { + prefs->setString(_prefs_path, _ustr_values[this->get_active_row_number()]); + } } } diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 1576184ac..6c4533451 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -144,9 +144,12 @@ class PrefCombo : public Gtk::ComboBoxText public: void init(Glib::ustring const &prefs_path, Glib::ustring labels[], int values[], int num_items, int default_value); + void init(Glib::ustring const &prefs_path, + Glib::ustring labels[], Glib::ustring values[], int num_items, Glib::ustring default_value); protected: Glib::ustring _prefs_path; std::vector _values; + std::vector _ustr_values; ///< string key values used optionally instead of numeric _values void on_changed(); }; -- 2.30.2