Code

add possibility to change the UI language (gettext) in preferences dialogue
authortheAdib <theAdib@users.sourceforge.net>
Tue, 30 Dec 2008 20:33:13 +0000 (20:33 +0000)
committertheAdib <theAdib@users.sourceforge.net>
Tue, 30 Dec 2008 20:33:13 +0000 (20:33 +0000)
src/inkscape.cpp
src/preferences-skeleton.h
src/ui/dialog/inkscape-preferences.cpp
src/ui/dialog/inkscape-preferences.h
src/ui/widget/preferences-widget.cpp
src/ui/widget/preferences-widget.h

index 2a7f31c3e92647b7c42e042fcd64ca60635ad2be..8cd01c226745a702176d442cf896372eabc28110 100644 (file)
@@ -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
index dd6a9a92f3fed86906358694430b8f176a424c0d..6b477f12eb517d8b47b3ea1647db5807e5f95be0 100644 (file)
@@ -424,6 +424,8 @@ static char const preferences_skeleton[] =
 "  <group id=\"debug\">\n"
 "    <group id=\"latency\" skew=\"1\"/>\n"
 "  </group>\n"
+"  <group id=\"i18n\"\n"
+"    language=\"\"/>\n"
 "\n"
 "</inkscape>\n";
 
index d656e2a537b970be878be298df81ada73e3933f5..f2611c377a4790de059595475f5f5db5a7629db0 100644 (file)
@@ -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;
index 1c5a3a85f667c0bb09217e0864c2977beea6794e..93b9faad01bb4e0430782eda9f11ab0a1abfb7ee 100644 (file)
@@ -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();
 
index 395726511722fd507f779515b3ddb5a4f3b0e1de..e84eaa45834da4294eedf9915887529a50bdb908 100644 (file)
@@ -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()]);
+        }
     }
 }
 
index 1576184acc86fc932fce75624c62d6dee79bca95..6c4533451d679872d1cfc763511cb36bd5e80617 100644 (file)
@@ -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<int> _values;
+    std::vector<Glib::ustring> _ustr_values;    ///< string key values used optionally instead of numeric _values
     void on_changed();
 };