summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-12-21 07:44:59 +0900
committerkali <kali@leap.se>2012-12-21 07:45:14 +0900
commit654b83db5f050a94f9637fb1ce80df5cb7ed5a38 (patch)
tree4621653d602c1951e4584c8c66f6607e5eceae4b
parentb0c3c9194447f20306111a31ee5a6d4828fed158 (diff)
updated "translate" to work in objects other than QObjects
-rw-r--r--data/leap_client.pro19
-rw-r--r--data/ts/en_US.ts39
-rw-r--r--docs/dev/internationalization.rst23
-rw-r--r--src/leap/base/exceptions.py34
4 files changed, 92 insertions, 23 deletions
diff --git a/data/leap_client.pro b/data/leap_client.pro
index 4c559029..3f76d6af 100644
--- a/data/leap_client.pro
+++ b/data/leap_client.pro
@@ -2,15 +2,16 @@
# is not there a f*** way of expanding this? other to template with python I mean...
-SOURCES += ../src/leap/gui/firstrun/intro.py
-SOURCES += ../src/leap/gui/firstrun/last.py
-SOURCES += ../src/leap/gui/firstrun/login.py
-SOURCES += ../src/leap/gui/firstrun/providerinfo.py
-SOURCES += ../src/leap/gui/firstrun/providerselect.py
-SOURCES += ../src/leap/gui/firstrun/providersetup.py
-SOURCES += ../src/leap/gui/firstrun/register.py
-SOURCES += ../src/leap/gui/firstrun/regvalidation.py
-SOURCES += ../src/leap/gui/firstrun/wizard.py
+SOURCES += ../src/leap/base/exceptions.py
+SOURCES += ../src/leap/gui/firstrun/intro.py
+SOURCES += ../src/leap/gui/firstrun/last.py
+SOURCES += ../src/leap/gui/firstrun/login.py
+SOURCES += ../src/leap/gui/firstrun/providerinfo.py
+SOURCES += ../src/leap/gui/firstrun/providerselect.py
+SOURCES += ../src/leap/gui/firstrun/providersetup.py
+SOURCES += ../src/leap/gui/firstrun/register.py
+SOURCES += ../src/leap/gui/firstrun/regvalidation.py
+SOURCES += ../src/leap/gui/firstrun/wizard.py
# where to generate ts files -- tx will pick from here
diff --git a/data/ts/en_US.ts b/data/ts/en_US.ts
index f6aadc5c..a802dd75 100644
--- a/data/ts/en_US.ts
+++ b/data/ts/en_US.ts
@@ -1,6 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
+ <name>Errors</name>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="57"/>
+ <source>Interface not found</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="64"/>
+ <source>Looks like your computer is not connected to the internet</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="72"/>
+ <source>Looks like there are problems with your internet connection</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="80"/>
+ <source>It looks like there is no internet connection.</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="88"/>
+ <source>Domain cannot be found</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="../src/leap/base/exceptions.py" line="95"/>
+ <source>The Encrypted Connection was lost. Shutting down...</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>IntroPage</name>
<message>
<location filename="../src/leap/gui/firstrun/intro.py" line="14"/>
@@ -216,4 +249,10 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>TestyClass</name>
+</context>
+<context>
+ <name>this is a cat</name>
+</context>
</TS>
diff --git a/docs/dev/internationalization.rst b/docs/dev/internationalization.rst
index e6b89dea..1a9af0be 100644
--- a/docs/dev/internationalization.rst
+++ b/docs/dev/internationalization.rst
@@ -38,21 +38,30 @@ tl;dr;::
self.tr('your string')
-for any string that you want to be translated.
+for any string that you want to be translated, as long as the instance derives from ``QObject``.
+
+If you have to translate something that it is not a ``QObject``, use the magic leap ``translate`` method:
+
+
+.. code-block:: python
+
+ from leap.util.translations import translate
+
+ class Foo(object):
+ bar = translate(<Context>, <string>, <comment>)
+
.. Note about this: there seems to be some problems with the .tr method
- on QObjects. Investigate this.
- I still believe we can use a generic _ method which is smart enough to
- fallback to QObject.tr methods or lookup our own tr implementation (for our
- multilungual objects, like in exceptions or provider labels that came from json objects).
+ so the translate method could actually be the preferred thing in all the cases.
+ Still missing what to do for language labels (json-based).
--kali
For i18n maintainers
^^^^^^^^^^^^^^^^^^^^
-You need ``pylupdate4`` for these steps. To get it, in debian::
+You need ``pylupdate4`` and ``lrelease`` for these steps. To get it, in debian::
- $ apt-get install python-qt4-utils
+ $ apt-get install pyqt4-dev-tools qt4-linguist-tools
If you do not already have it, install the ``transifex-client`` from the cheese shop::
diff --git a/src/leap/base/exceptions.py b/src/leap/base/exceptions.py
index 227da953..c5e56b76 100644
--- a/src/leap/base/exceptions.py
+++ b/src/leap/base/exceptions.py
@@ -14,6 +14,7 @@ Exception attributes and their meaning/uses
* usermessage: the message that will be passed to user in ErrorDialogs
in Qt-land.
"""
+from leap.util.translations import translate
class LeapException(Exception):
@@ -22,6 +23,7 @@ class LeapException(Exception):
sets some parameters that we will check
during error checking routines
"""
+
critical = False
failfirst = False
warning = False
@@ -46,32 +48,50 @@ class ImproperlyConfigured(Exception):
pass
-class NoDefaultInterfaceFoundError(LeapException):
- message = "no default interface found"
- usermessage = "Looks like your computer is not connected to the internet"
+# NOTE: "Errors" (context) has to be a explicit string!
class InterfaceNotFoundError(LeapException):
# XXX should take iface arg on init maybe?
message = "interface not found"
+ usermessage = translate(
+ "Errors",
+ "Interface not found")
+
+
+class NoDefaultInterfaceFoundError(LeapException):
+ message = "no default interface found"
+ usermessage = translate(
+ "Errors",
+ "Looks like your computer "
+ "is not connected to the internet")
class NoConnectionToGateway(CriticalError):
message = "no connection to gateway"
- usermessage = "Looks like there are problems with your internet connection"
+ usermessage = translate(
+ "Errors",
+ "Looks like there are problems "
+ "with your internet connection")
class NoInternetConnection(CriticalError):
message = "No Internet connection found"
- usermessage = "It looks like there is no internet connection."
+ usermessage = translate(
+ "Errors",
+ "It looks like there is no internet connection.")
# and now we try to connect to our web to troubleshoot LOL :P
class CannotResolveDomainError(LeapException):
message = "Cannot resolve domain"
- usermessage = "Domain cannot be found"
+ usermessage = translate(
+ "Errors",
+ "Domain cannot be found")
class TunnelNotDefaultRouteError(CriticalError):
message = "Tunnel connection dissapeared. VPN down?"
- usermessage = "The Encrypted Connection was lost. Shutting down..."
+ usermessage = translate(
+ "Errors",
+ "The Encrypted Connection was lost. Shutting down...")