tr quality fixes

This commit is contained in:
lakshyacis 2019-10-22 19:54:52 +05:30
parent fda5d23c2d
commit 58e5fac6d7
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB

View File

@ -1,22 +1,36 @@
"""
Translating text
"""
import os import os
import state import state
# 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: class translateClass:
"""
This is used so that the translateText function can be used
when we are in daemon mode and not using any QT functions.
"""
# pylint: disable=old-style-class,too-few-public-methods
def __init__(self, context, text): def __init__(self, context, text):
self.context = context self.context = context
self.text = text self.text = text
def arg(self,argument):
def arg(self, _):
"""Replace argument placeholders"""
if '%' in self.text: if '%' in self.text:
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. # This doesn't actually do anything with the arguments
else: # because we don't have a UI in which to display this information anyway.
return translateClass(self.context, self.text.replace('%', '', 1))
return self.text return self.text
def _translate(context, text, disambiguation = None, encoding = None, n = None):
def _translate(context, text, disambiguation=None, encoding=None, n=None): # pylint: disable=unused-argument
return translateText(context, text, n) return translateText(context, text, n)
def translateText(context, text, n = None):
def translateText(context, text, n=None):
"""Translate text in context"""
try: try:
enableGUI = state.enableGUI enableGUI = state.enableGUI
except AttributeError: # inside the plugin except AttributeError: # inside the plugin
@ -25,15 +39,17 @@ def translateText(context, text, n = None):
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
except Exception as err: except Exception as err:
print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' print 'PyBitmessage requires PyQt unless you want to run it as a daemon'\
' and interact with it using the API.'\
' You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download'\
' or by searching Google for \'PyQt Download\'.'\
' If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon'
print 'Error message:', err print 'Error message:', err
os._exit(0) os._exit(0) # pylint: disable=protected-access
if n is None: if n is None:
return QtGui.QApplication.translate(context, text) return QtGui.QApplication.translate(context, text)
else:
return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, n) return QtGui.QApplication.translate(context, text, None, QtCore.QCoreApplication.CodecForTr, n)
else: else:
if '%' in text: if '%' in text:
return translateClass(context, text.replace('%','',1)) return translateClass(context, text.replace('%', '', 1))
else:
return text return text