def test_setupI18n(self): """Gui translations are working.""" myUntranslatedString = 'Show/hide InaSAFE dock widget' myExpectedString = 'Tampilkan/hilangkan widget InaSAFE' myParent = QWidget() myCanvas = QgsMapCanvas(myParent) myIface = QgisInterface(myCanvas) myPlugin = ISPlugin(myIface) myPlugin.setupI18n('id') myTranslation = myPlugin.tr(myUntranslatedString) myMessage = '\nTranslated: %s\nGot: %s\nExpected: %s' % ( myUntranslatedString, myTranslation, myExpectedString) assert myTranslation == myExpectedString, myMessage
def Xtest_Afrikaans(self): """Test that Afrikaans translations are working""" # Note this has really bad side effects - lots of tests suddenly start # breaking when this test is enabled....disabled for now, but I have # left the test here for now as it illustrates one potential avenue # that can be pursued if dynamically changing the language to unit test # different locales ever becomes a requirement. # Be sure nose tests all run cleanly before reintroducing this! # This is part test and part demonstrator of how to reload inasafe # Now see if the same function is delivered for the function # Because of the way impact plugins are loaded in inasafe # (see http://effbot.org/zone/metaclass-plugins.htm) # lang in the context of the ugettext function in inasafe libs # must be imported late so that i18n is set up already from common.utilities import ugettext as _ myUntranslatedString = 'Temporarily Closed' myExpectedString = 'Tydelik gesluit' # afrikaans myTranslation = _(myUntranslatedString) myMessage = '\nTranslated: %s\nGot: %s\nExpected: %s' % ( myUntranslatedString, myTranslation, myExpectedString) assert myTranslation == myExpectedString, myMessage myParent = QWidget() myCanvas = QgsMapCanvas(myParent) myIface = QgisInterface(myCanvas) # reload all inasafe modules so that i18n get picked up afresh # this is the part that produces bad side effects for myMod in sys.modules.values(): try: if ('storage' in str(myMod) or 'impact' in str(myMod)): print 'Reloading:', str(myMod) reload(myMod) except: pass myPlugin = ISPlugin(myIface) myPlugin.setupI18n('af') # afrikaans myLang = os.environ['LANG'] assert myLang == 'af' from impact_functions import getSafeImpactFunctions #myFunctions = getSafeImpactFunctions() #print myFunctions myFunctions = getSafeImpactFunctions('Tydelik gesluit') assert len(myFunctions) > 0
def test_ImpactFunctionI18n(self): """Library translations are working.""" # import this late so that i18n setup is already in place from common.utilities import ugettext as _ myUntranslatedString = 'Temporarily Closed' # Test indonesian too myParent = QWidget() myCanvas = QgsMapCanvas(myParent) myIface = QgisInterface(myCanvas) myPlugin = ISPlugin(myIface) myPlugin.setupI18n('id') # indonesian myExpectedString = 'Ditutup sementara' myTranslation = _(myUntranslatedString) myMessage = '\nTranslated: %s\nGot: %s\nExpected: %s' % ( myUntranslatedString, myTranslation, myExpectedString) assert myTranslation == myExpectedString, myMessage