core: i18n refactoring:

- _() is no more installed in __builtin__
    - instead, there is a new sat.core.i18n module
    - added D_() method for deferred translation
    - languageSwitch method allow to dynamically change translation language
    - import gettext is tested against ImportError, and dummy methods are used when not available (mainly useful for Libervia)
This commit is contained in:
Goffi 2013-12-29 17:06:01 +01:00
commit 5a00dc9503
75 changed files with 123 additions and 19 deletions

View file

@ -3,8 +3,11 @@ First of all, thank you for helping translating SàT :)
NOTE: *.po files are in i18n directory
To translate a file, you can use a dedicated tool as the excellent gtranslator:
- use the template .po file (e.g. sat.po) and name it to your translated language (e.g. fr.po for french); you can preferably generate a new template directly from the source with the following command (eventually adapted):
> xgettext -L python -d sat sat.tac tools/*py plugins/*py
- use the template .po file (e.g. sat.po) and name it to your translated language (e.g. fr.po for french); you can preferably generate a new template directly from the source with the following command (eventually adapted, the following command use zsh's globbing syntax), launched from root sat dir:
> xgettext -L python -d sat --keyword=D_ -p i18n **/*(.py|.tac|primitivus|wix|jp)(.)
- then to start a new translation, copy i18n/sat.po to your language file, e.g. cd i18n; cp sat.po fr.po
- use the choosed tool (a simple text editor can be sufficient) to edit the file: e.g. gtranslator fr.po
@ -19,9 +22,9 @@ To translate a file, you can use a dedicated tool as the excellent gtranslator:
and if everything is allright
> mv fr2.po fr.po
Don't forget that you can use the version-control system (mercurial, the "hg" command) to keep history of you translations.
Don't forget that you can (and should !) use the version-control system (mercurial, the "hg" command) to keep history of you translations.
You can check the fr.po file to see how it's done and to know what to put while you set up you translation tool.
Trank you again for you help, don't forget to give me your name and contact mail so I can credit you, and don't hesitate to contact me if you need help (goffi@goffi.org).
Trank you again for you help, don't forget to give me your name and contact email so I can credit you, and don't hesitate to contact me if you need help (goffi@goffi.org, or the sat XMPP room at sat@chat.jabberfr.org).

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from bridge_frontend import BridgeFrontend
import dbus
from logging import debug, error

View file

@ -18,10 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
try:
_("dummy")
except: # libervia doesn't allow to explicit the exception here
_ = lambda text: text
from sat.core.i18n import _
try:
from collections import OrderedDict # only available from python 2.7

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
from sat.core.i18n import _
#consts
name = u"jp"
@ -44,9 +45,6 @@ logging.basicConfig(level=logging.DEBUG,
format='%(message)s')
###
import gettext
gettext.install('jp', unicode=True)
import sys
import os
from os.path import abspath, basename, dirname

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from sat_frontends.tools.games import TarotCard

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from urwid_satext.files_management import FileDialog

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from sat_frontends.quick_frontend.quick_gateways import QuickGatewaysManager

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from urwid_satext.files_management import FileDialog

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext.sat_widgets import AdvancedEdit,Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame
from sat.tools.jid import JID

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
import copy
from urwid_satext import sat_widgets

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import urwid
from urwid_satext import sat_widgets
from logging import debug, info, warning, error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import sys
from logging import debug, info, warning, error
from sat.tools.jid import JID
@ -27,9 +28,6 @@ from optparse import OptionParser
from sat_frontends.quick_frontend.constants import Const
import gettext
gettext.install('sat_frontend', unicode=True)
class QuickApp(object):
"""This class contain the main methods needed for the frontend"""

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from sat.tools.jid import JID
from sat_frontends.quick_frontend.quick_utils import unescapePrivate

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from sat.tools.jid import JID
import pdb

View file

@ -20,6 +20,7 @@
from sat.core.i18n import _
class QuickGatewaysManager(object):

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import os.path, glob
import pdb

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import os.path
import time

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import sys
import os.path
import gettext

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import wx
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
from sat_frontends.wix.constants import Const

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import pdb
from xml.dom import minidom

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
from sat_frontends.quick_frontend.quick_app import QuickApp
import wx

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import pdb
from xml.dom import minidom

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import wx
import pdb
from logging import debug, info, error

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import pdb
from logging import debug, info, error

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import os.path, glob
import pdb

View file

@ -19,6 +19,7 @@
from sat.core.i18n import _
import wx
import pdb
from xml.dom import minidom

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from bridge_frontend import BridgeFrontend
import dbus
from logging import debug, error

42
src/core/i18n.py Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# SAT: a jabber client
# Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program 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 Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
try:
import gettext
_ = gettext.translation('sat', 'i18n', fallback=True).ugettext
_translators = {None: gettext.NullTranslations()}
def languageSwitch(lang=None):
if not lang in _translators:
_translators[lang] = gettext.translation('sat', languages=[lang], fallback=True)
_translators[lang].install(unicode=True)
except ImportError:
print "WARNING: gettext support disabled"
_ = lambda msg: msg # Libervia doesn't support gettext
def languageSwitch(lang=None):
pass
D_ = lambda msg: msg # used for deferred translations

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from twisted.application import service
from twisted.internet import defer

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from twisted.internet import task, defer
from twisted.words.protocols.jabber import jid, xmlstream
from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
from sat.core.i18n import _
import os.path
import csv

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.enterprise import adbapi
from twisted.internet import defer

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.internet import protocol, defer, threads, reactor

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import jid
from twisted.internet import reactor, protocol

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from sat.core import exceptions
from twisted.internet import reactor, defer, protocol

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.internet import defer
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
import warnings
from twisted.internet import protocol, defer

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
import warnings
warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted') # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.internet import protocol, defer, threads, reactor

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.internet import reactor

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, warning, error
from twisted.words.protocols.jabber.jid import JID
from twisted.words.xish import domish

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
import warnings
from twisted.internet import protocol, defer

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from twisted.words.protocols.jabber import jid
from logging import debug, info, warning, error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _, D_
from logging import debug, info, error, warning
from wokkel import disco, pubsub
@ -28,7 +29,7 @@ from lxml.html import clean
import re
CATEGORY = "Composition"
CATEGORY = D_("Composition")
NAME = "Syntax"
_SYNTAX_XHTML = "XHTML"
_SYNTAX_CURRENT = "@CURRENT@"
@ -85,7 +86,7 @@ class TextSyntaxes(object):
params_data = {
'category_name': CATEGORY,
'category_label': _(CATEGORY), #FIXME: check that gettext can handle this
'category_label': _(CATEGORY),
'name': NAME,
'label': _(NAME),
'default': _SYNTAX_XHTML,

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.words.protocols.jabber.xmlstream import XmlStream
from twisted.words.xish import domish

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import client, jid
from twisted.words.xish import domish

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import logging
from sat.core import exceptions
from wokkel import disco, iwokkel

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.internet import defer
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import client as jabber_client, jid
from twisted.words.xish import domish

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import jid
from twisted.words.protocols.jabber import error as xmpp_error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.internet import threads
from twisted.internet.defer import inlineCallbacks, returnValue

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber.xmlstream import IQ
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from wokkel.pubsub import PubSubRequest
from wokkel import disco, pubsub

View file

@ -54,6 +54,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.internet import protocol, reactor
from twisted.internet import error as jab_error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from wokkel import disco, pubsub, iwokkel

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.words.protocols.jabber import jid
from twisted.words.protocols.jabber.xmlstream import IQ

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from sat.core import exceptions
from logging import info
from wokkel import disco, iwokkel

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.words.xish import domish
from twisted.internet import protocol

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.words.protocols.jabber import client as jabber_client, jid
from twisted.words.protocols.jabber import error as jab_error

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error, warning
from twisted.words.xish import domish
from twisted.words.protocols.jabber import client, jid, xmlstream

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error
from twisted.internet import protocol
from twisted.words.protocols.jabber import client, jid

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.xish import domish
from twisted.internet import protocol, defer

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, warning, error
from twisted.words.protocols.jabber import jid
from twisted.internet import defer

View file

@ -17,9 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gettext
gettext.install('sat', "i18n", unicode=True)
from twisted.application import service
from twisted.internet import glib2reactor
glib2reactor.install()

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
import __builtin__
from twisted.words.protocols.jabber.jid import JID
from wokkel.xmppim import RosterItem

View file

@ -19,6 +19,7 @@
"""Misc usefull classes"""
from sat.core.i18n import _
import sys
from logging import debug, warning

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from logging import debug, info, error, warning
from xml.dom import minidom
from wokkel import data_form