This repository has been archived on 2024-12-19. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-19/src/tr.py

56 lines
1.9 KiB
Python
Raw Normal View History

2019-09-20 13:19:04 +02:00
"""
2019-10-22 16:24:52 +02:00
Translating text
2019-09-20 13:19:04 +02:00
"""
2013-09-06 19:41:24 +02:00
import os
import state
2019-09-20 13:19:04 +02:00
2019-12-30 13:10:02 +01:00
class translateClass(object):
2019-09-20 13:19:04 +02:00
"""
2019-10-22 16:24:52 +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.
2019-09-20 13:19:04 +02:00
"""
2019-12-30 13:10:02 +01:00
# pylint: disable=too-few-public-methods
def __init__(self, context, text):
self.context = context
self.text = text
2019-09-20 13:19:04 +02:00
2019-12-30 13:10:02 +01:00
def arg(self, _):
2019-09-20 13:19:04 +02:00
"""Replace argument placeholders"""
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
2019-09-20 13:19:04 +02:00
2019-12-30 13:10:02 +01:00
def _translate(context, text, disambiguation=None, encoding=None, n=None): # pylint: disable=unused-argument
return translateText(context, text, n)
2019-09-20 13:19:04 +02:00
def translateText(context, text, n=None):
"""Translate text in context"""
try:
enableGUI = state.enableGUI
except AttributeError: # inside the plugin
enableGUI = True
if not state.kivy and enableGUI:
try:
from PyQt4 import QtCore, QtGui
except Exception as err:
2019-12-30 13:10:02 +01: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\'.\
If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon')
2019-12-30 13:10:02 +01:00
print('Error message:', err)
os._exit(0) # pylint: disable=protected-access
2019-12-23 12:18:37 +01: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)
else:
if '%' in text:
2019-09-20 13:19:04 +02:00
return translateClass(context, text.replace('%', '', 1))
return text