Skip to content

Commit

Permalink
Merge pull request #39 from xquiet/master
Browse files Browse the repository at this point in the history
Add support to i18n localization
  • Loading branch information
tobias47n9e committed Jul 19, 2015
2 parents c584019 + 05e12f3 commit 76083a5
Show file tree
Hide file tree
Showing 10 changed files with 2,269 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log
Expand Down
8 changes: 8 additions & 0 deletions EXTRAS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# create the pot file from the source code
xgettext --from-code=UTF-8 --keyword=translatable --keyword=_ --sort-output innstereo/*.{py,glade} -o po/innstereo.pot

# to start a new localization
msginit --locale=$LANG --input=innstereo.pot

# to compile the po thus build mo
msgfmt -o po/it_IT.UTF-8.mo po/it_IT.UTF-8.po
4 changes: 2 additions & 2 deletions innstereo/dialog_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def __init__(self, run_file_parser, main_window):
self.dialog = self.builder.get_object("filechooserdialog_parse")
self.dialog.set_transient_for(main_window)
self.filefilters = self.builder.get_object("filefilter_parse")
self.filefilters.set_name("Text Files")
self.filefilters.set_name(_("Text Files"))
self.dialog.add_filter(self.filefilters)
self.run_file_parser = run_file_parser
self.builder.connect_signals(self)
Expand Down Expand Up @@ -716,7 +716,7 @@ def __init__(self, main_window, open_project):
self.dialog.add_filter(filter_json)
filter_all = Gtk.FileFilter()
filter_all.add_pattern("*")
filter_all.set_name("All Files")
filter_all.set_name(_("All Files"))
self.dialog.add_filter(filter_all)
self.open_project = open_project
self.builder.connect_signals(self)
Expand Down
3 changes: 2 additions & 1 deletion innstereo/gui_layout.glade
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Author: Tobias Schönberg
In Preperation (2015)</property>
<property name="website">http://innstereo.github.io</property>
<property name="website_label" translatable="yes">http://innstereo.github.io</property>
<property name="authors">Tobias Schönberg</property>
<property name="authors">Tobias Schönberg
Matteo Pasotti</property>
<property name="logo">logo_about.svg</property>
<property name="license_type">gpl-2-0</property>
<signal name="close" handler="on_aboutdialog_close" swapped="no"/>
Expand Down
79 changes: 79 additions & 0 deletions innstereo/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#==============================================================================#
# InnStereo #
# #
# Copyright (c) 2012-2015 Matteo Pasotti <matteo.pasotti@gmail.com> #
# #
# #
# This file was originally part of OpenStereoNet (fork of OpenStereo). #
# This file is part of InnStereo since July 2015 #
# InnStereo is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 2 of the License, or #
# (at your option) any later version. #
# #
# InnStereo is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with InnStereo. If not, see <http://www.gnu.org/licenses/>. #
#==============================================================================#
# -*- coding: utf-8 -*-

import os, sys
import locale
import gettext

class i18n:
app_name = ""
language = None

def __init__(self):
# The translation files will be under
# @locale_dir@/@LANGUAGE@/LC_MESSAGES/@app_name@.mo
self.app_name = "innstereo"

#app_dir = os.getcwd()
app_dir = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
locale_dir = os.path.join(app_dir, 'po')
# .mo files will then be located in APP_Dir/po/LANGUAGECODE/LC_MESSAGES/

# Now we need to choose the language. We will provide a list, and gettext
# will use the first translation available in the list
#
default_languages = os.environ.get('LANG', '').split(':')
default_languages += ['en_US']

lc, encoding = locale.getdefaultlocale()
if lc:
languages = [lc]

# Concat all languages (env + default locale),
# and here we have the languages and location of the translations
languages += default_languages
mo_location = locale_dir

kwargs = {}
if sys.version < '3':
kwargs['unicode'] = 1
gettext.install(True,localedir=None,**kwargs)

gettext.find(self.app_name, mo_location)

locale.bindtextdomain(self.app_name, locale_dir)

gettext.bindtextdomain (self.app_name, locale_dir)

gettext.textdomain (self.app_name)

#gettext.bind_textdomain_codeset(self.app_name, "UTF-8")

self._language = gettext.translation(self.app_name, mo_location, languages = languages, fallback = True)

def language(self):
return self._language

def get_ts_domain(self):
return self.app_name

6 changes: 3 additions & 3 deletions innstereo/layer_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def __init__(self, treestore, treeview):
"""
PlaneLayer.__init__(self, treestore, treeview)
self.props["type"] = "line"
self.props["label"] = "Linear layer"
self.props["label"] = _("Linear layer")
self.props["page"] = 1

def get_pixbuf(self):
Expand Down Expand Up @@ -1092,7 +1092,7 @@ def __init__(self, treestore, treeview):
"""
PlaneLayer.__init__(self, treestore, treeview)
self.props["type"] = "eigenvector"
self.props["label"] = "Eigenvector layer"
self.props["label"] = _("Eigenvector layer")
self.props["page"] = 1

def get_pixbuf(self):
Expand Down Expand Up @@ -1130,5 +1130,5 @@ def __init__(self, treestore, treeview):
"""
PlaneLayer.__init__(self, treestore, treeview)
self.props["type"] = "smallcircle"
self.props["label"] = "Small circle layer"
self.props["label"] = _("Small circle layer")

2 changes: 1 addition & 1 deletion innstereo/layer_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, store):

self.renderer_name = Gtk.CellRendererText(weight=700,
weight_set=True)
self.column_name = Gtk.TreeViewColumn("Layer",
self.column_name = Gtk.TreeViewColumn(_("Layer"),
self.renderer_name, text=2)
self.column_name.set_min_width(100)
self.renderer_name.set_property("editable", True)
Expand Down
11 changes: 8 additions & 3 deletions innstereo/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
from .rotation_dialog import RotationDialog
from .viridis import viridis

from .i18n import i18n

_ = i18n().language().gettext

class MainWindow(object):

Expand Down Expand Up @@ -194,13 +197,13 @@ def add_fisher_confidence(signal, entry_conf, tb_fisher, pom_fisher):
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0,
border_width=10)
row_conf.add(hbox)
label_conf = Gtk.Label("Fisher Confidence", xalign=0)
label_conf = Gtk.Label(_("Fisher Confidence"), xalign=0)
hbox.pack_start(label_conf, True, True, 3)
entry_conf = Gtk.Entry(width_chars=3, max_width_chars=3, text="95")
hbox.pack_start(entry_conf, False, False, 3)
lb_fisher.add(row_conf)

btn_calc = Gtk.Button("Calculate")
btn_calc = Gtk.Button(_("Calculate"))
row_btn = Gtk.ListBoxRow()
box = Gtk.Box()
box.pack_start(btn_calc, True, True, 0)
Expand Down Expand Up @@ -2612,7 +2615,7 @@ def push_stereo_coordinates(mpl_event):
self.statbar.push(1, ("{0} / {1}".format(alpha_deg, gamma_deg)))

def push_rose_coordinates(mpl_event):
self.statbar.push(1, ("Rose Diagram"))
self.statbar.push(1, (_("Rose Diagram")))

def push_mpl_event(mpl_event):
title = mpl_event.inaxes.get_title()
Expand Down Expand Up @@ -2826,6 +2829,8 @@ def startup():
rel_path = "gui_layout.glade"
abs_path = os.path.join(script_dir, rel_path)

builder.set_translation_domain(i18n().get_ts_domain())

objects = builder.add_objects_from_file(abs_path,
("main_window", "image_new_plane", "image_new_faultplane",
"image_new_line", "image_new_fold", "image_plane_intersect",
Expand Down

0 comments on commit 76083a5

Please sign in to comment.