2019-09-20 13:19:04 +02:00
|
|
|
"""
|
|
|
|
src/tr.py
|
|
|
|
=================================
|
|
|
|
"""
|
|
|
|
# pylint: disable=relative-import
|
2013-09-06 19:41:24 +02:00
|
|
|
import os
|
2013-06-24 21:51:01 +02:00
|
|
|
|
2018-04-16 09:00:23 +02:00
|
|
|
import state
|
2017-01-11 14:27:19 +01:00
|
|
|
|
2019-09-20 13:19:04 +02:00
|
|
|
"""This is used so that the translateText function can be used """
|
|
|
|
"""when we are in daemon mode and not using any QT functions."""
|
|
|
|
|
|
|
|
|
|
|
|
class translateClass: # pylint: disable=old-style-class, too-few-public-methods
|
|
|
|
"""
|
|
|
|
This is used so that the translateText function can be used when we are
|
|
|
|
in daemon mode and not using any QT functions.
|
|
|
|
"""
|
2013-06-24 21:51:01 +02:00
|
|
|
def __init__(self, context, text):
|
|
|
|
self.context = context
|
|
|
|
self.text = text
|
2019-09-20 13:19:04 +02:00
|
|
|
|
|
|
|
def arg(self, argument): # pylint: disable=unused-argument
|
|
|
|
"""Replace argument placeholders"""
|
2013-06-24 21:51:01 +02:00
|
|
|
if '%' in self.text:
|
2019-09-20 13:19:04 +02:00
|
|
|
return translateClass(self.context, self.text.replace('%', '', 1))
|
|
|
|
# This doesn't actually do anything with the arguments
|
|
|
|
# because we don't have a UI in which to display this information anyway.
|
|
|
|
return self.text
|
2013-06-24 21:51:01 +02:00
|
|
|
|
2019-09-20 13:19:04 +02:00
|
|
|
|
|
|
|
def _translate(context, text, disambiguation=None, encoding=None, n=None): # pylint: disable=unused-argument
|
2019-09-18 11:09:29 +02:00
|
|
|
return translateText(context, text, n)
|
|
|
|
|
|
|
|
# def _translate(context, text, disambiguation = None, encoding = None, n = None):
|
|
|
|
# return translateClass(context, text.replace('%','',1))
|
2013-06-24 21:51:01 +02:00
|
|
|
|
2019-09-20 13:19:04 +02:00
|
|
|
|
|
|
|
def translateText(context, text, n=None):
|
|
|
|
"""Translate text in context"""
|
2017-10-07 14:50:25 +02:00
|
|
|
try:
|
2018-04-16 09:00:23 +02:00
|
|
|
enableGUI = state.enableGUI
|
2017-10-07 14:50:25 +02:00
|
|
|
except AttributeError: # inside the plugin
|
2018-04-16 09:00:23 +02:00
|
|
|
enableGUI = True
|
2019-09-18 11:09:29 +02:00
|
|
|
if not state.kivy and enableGUI:
|
2013-06-24 21:51:01 +02:00
|
|
|
try:
|
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
except Exception as err:
|
2019-09-26 16:08:19 +02:00
|
|
|
print ('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API\
|
2019-09-20 13:19:04 +02:00
|
|
|
.You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download\
|
|
|
|
or by searching Google for \'PyQt Download\'.\
|
2019-09-26 16:08:19 +02:00
|
|
|
If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon')
|
|
|
|
print ('Error message:', err)
|
2019-09-20 13:19:04 +02:00
|
|
|
os._exit(0) # pylint: disable=protected-access
|
2016-04-27 09:48:53 +02:00
|
|
|
if n is None:
|
|
|
|
return QtGui.QApplication.translate(context, text)
|
2019-09-20 13:19:04 +02:00
|
|
|
return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, n)
|
2013-06-24 21:51:01 +02:00
|
|
|
else:
|
|
|
|
if '%' in text:
|
2019-09-20 13:19:04 +02:00
|
|
|
return translateClass(context, text.replace('%', '', 1))
|
|
|
|
return text
|