Added internationalization support, updated the glade file to gtk 3.6

This commit is contained in:
José Carlos Cuevas 2014-07-14 12:30:46 +02:00
parent ea6a221f6c
commit 1f36bcdbc1
7 changed files with 192 additions and 14 deletions

BIN
locale/es.mo Normal file

Binary file not shown.

76
locale/es.po Normal file
View file

@ -0,0 +1,76 @@
# Spanish translations for PACKAGE package
# Traducciones al español para el paquete PACKAGE.
# Copyright (C) 2014 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# José Carlos Cuevas <reset@localhost>, 2014.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-07-14 12:21+0200\n"
"PO-Revision-Date: 2014-07-14 12:24+0100\n"
"Last-Translator: José Carlos Cuevas <reset@localhost>\n"
"Language-Team: Spanish\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.5.4\n"
#: jsoninspector.py:81
msgid "Open JSON text file"
msgstr "Abrir fichero de texto JSON"
#: jsoninspector.py:104
msgid "No JSON loaded."
msgstr "No se ha cargado JSON."
#: jsoninspector.py:152
msgid "Loaded from the clipboard."
msgstr "Cargado desde el portapapeles."
#: jsoninspector.py:194
msgid "Not valid JSON!\n"
msgstr "JSON no válido!\n"
#: jsoninspector.py:210
msgid "Not valid JSON"
msgstr "JSON no válido"
#: jsoninspector.glade.h:1
msgid "Enter JSON Text"
msgstr "Introduzca texto JSON"
#: jsoninspector.glade.h:2
msgid "JSON Inspector"
msgstr "JSON Inspector"
#: jsoninspector.glade.h:3
msgid "_File"
msgstr "_Archivo"
#: jsoninspector.glade.h:4
msgid "Cop_y JSON"
msgstr "Cop_iar JSON"
#: jsoninspector.glade.h:5
msgid "_Help"
msgstr "A_yuda"
#: jsoninspector.glade.h:6
msgid "Node"
msgstr "Nodo"
#: jsoninspector.glade.h:7
msgid "Value"
msgstr "Valor"
#: jsoninspector.glade.h:8
msgid "Type"
msgstr "Tipo"
#: jsoninspector.glade.h:9
msgid "No JSON loaded"
msgstr "No se ha cargado JSON"

74
locale/messages.pot Normal file
View file

@ -0,0 +1,74 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-07-14 12:21+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: jsoninspector.py:81
msgid "Open JSON text file"
msgstr ""
#: jsoninspector.py:104
msgid "No JSON loaded."
msgstr ""
#: jsoninspector.py:152
msgid "Loaded from the clipboard."
msgstr ""
#: jsoninspector.py:194
msgid "Not valid JSON!\n"
msgstr ""
#: jsoninspector.py:210
msgid "Not valid JSON"
msgstr ""
#: jsoninspector.glade.h:1
msgid "Enter JSON Text"
msgstr ""
#: jsoninspector.glade.h:2
msgid "JSON Inspector"
msgstr ""
#: jsoninspector.glade.h:3
msgid "_File"
msgstr ""
#: jsoninspector.glade.h:4
msgid "Cop_y JSON"
msgstr ""
#: jsoninspector.glade.h:5
msgid "_Help"
msgstr ""
#: jsoninspector.glade.h:6
msgid "Node"
msgstr ""
#: jsoninspector.glade.h:7
msgid "Value"
msgstr ""
#: jsoninspector.glade.h:8
msgid "Type"
msgstr ""
#: jsoninspector.glade.h:9
msgid "No JSON loaded"
msgstr ""

Binary file not shown.

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<interface domain="jsoninspector">
<requires lib="gtk+" version="3.6"/>
<object class="GtkWindow" id="TextWindow">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Introducir texto JSON</property>
<property name="title" translatable="yes">Enter JSON Text</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="default_width">200</property>
@ -48,6 +48,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="onCopyJSONCancelClicked" swapped="no"/>
</object>
<packing>
@ -65,6 +66,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="onCopyJSONAcceptClicked" swapped="no"/>
</object>
<packing>
@ -246,7 +248,7 @@
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="resizable">True</property>
<property name="title">Nodo</property>
<property name="title" translatable="yes">Node</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort_column_id">0</property>
@ -255,14 +257,14 @@
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="resizable">True</property>
<property name="title">Valor</property>
<property name="title" translatable="yes">Value</property>
<property name="expand">True</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="resizable">True</property>
<property name="title">Tipo</property>
<property name="title" translatable="yes">Type</property>
<property name="expand">True</property>
</object>
</child>
@ -284,7 +286,7 @@
<object class="GtkLabel" id="StatusLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">No hay JSON cargado</property>
<property name="label" translatable="yes">No JSON loaded</property>
<attributes>
<attribute name="gravity" value="west"/>
</attributes>

View file

@ -2,17 +2,37 @@
# -*- coding: utf-8 -*-
from pkg_resources import resource_filename
from gi.repository import Gtk, Gdk, Gio
import json
from gi.repository import Gtk, Gdk, Gio
# Internationalization support
import gettext
import locale
APP = "jsoninspector"
DIR = "po"
locale.setlocale(locale.LC_ALL, '')
try:
gettext.bindtextdomain(APP, DIR)
locale.bindtextdomain(APP, DIR)
except:
gettext.bindtextdomain(APP, "../locale/")
locale.bindtextdomain(APP, "../locale/")
gettext.textdomain(APP)
_ = gettext.gettext
class MainWindowMethods(Gtk.Application):
"""
Main Application object with the main window signals
"""
def __init__(self, logic):
Gtk.Application.__init__(self, application_id = "apps.gnome.stevedore",
Gtk.Application.__init__(self, application_id = "apps.gnome.jsoninspector",
flags = Gio.ApplicationFlags.FLAGS_NONE)
# We store the reference to the app logic
@ -25,6 +45,7 @@ class MainWindowMethods(Gtk.Application):
Loads the MainWindow widgets, shows it up and starts the main loop
"""
self.builder = Gtk.Builder()
self.builder.set_translation_domain(APP)
self.builder.add_from_file(resource_filename(__name__,'jsoninspector.glade'))
self.builder.connect_signals(self)
@ -57,7 +78,7 @@ class MainWindowMethods(Gtk.Application):
User has pressed Open in the menu
"""
# Create the FileChooser Dialog
chooser = Gtk.FileChooserDialog("Open JSON text file", self.window,
chooser = Gtk.FileChooserDialog(_("Open JSON text file"), self.window,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
@ -80,7 +101,7 @@ class MainWindowMethods(Gtk.Application):
else:
label.set_text("No hay JSON cargado")
label.set_text(_("No JSON loaded."))
# We finish the dialog
chooser.destroy()
@ -128,7 +149,7 @@ class MainWindowMethods(Gtk.Application):
if self.logicObj.loadJSONText(jsonText):
status_label = self.builder.get_object("StatusLabel")
status_label.set_text("Cargado desde portapapeles.")
status_label.set_text(_("Loaded from the clipboard."))
self.logicObj.loadTree(treestore)
def onCopyJSONCancelClicked(self, widget):
@ -170,7 +191,7 @@ class LogicObject(object):
try:
self.json = json.loads(f.read())
except ValueError:
print "JSON no válido!\n"
print _("Not valid JSON!\n")
self.json = None
f.close()
@ -186,7 +207,7 @@ class LogicObject(object):
try:
self.json = json.loads(text)
except ValueError:
print "JSON no válido"
print _("Not valid JSON")
self.json = None
return False

5
util/gen_pot.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
intltool-extract --type="gettext/glade" *.glade
xgettext -k_ -kN_ -o messages.pot *.py *.h