Skip to content

Commit

Permalink
Further progress on i18n consolidation to use only Qt translation fra…
Browse files Browse the repository at this point in the history
…mework and remove gettext. In progress.
  • Loading branch information
timlinux committed Dec 17, 2014
1 parent e71ad88 commit ce984bb
Show file tree
Hide file tree
Showing 109 changed files with 486 additions and 604 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ before_script:
- export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib

script:
- xvfb-run --server-args="-screen 0, 1024x768x24" nosetests -A 'not slow' -v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe_qgis safe_qgis
- xvfb-run --server-args="-screen 0, 1024x768x24" nosetests -v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe safe

notifications:
irc:
Expand Down
3 changes: 2 additions & 1 deletion 71-apt-cacher-ng
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# use apt-cacher in your image build out (and the
# Subsequent running container.

Acquire::http { Proxy "http://192.168.2.9:3142"; };
Acquire::http { Proxy "http://192.168.60.176:3142"; };
#Acquire::http { Proxy "http://192.168.2.9:3142"; };
#Acquire::http { Proxy "http://192.168.1.13:3142"; };
5 changes: 4 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ Authors ordered by date of first contribution:
* Ole Nielsen <ole.nielsen@aifdr.org>
* Ted Dunstone <ted@biometix.com>
* Ariel Nunez <ingenieroariel@gmail.com>
* Tim Sutton <tim@linfiniti.com>
* Tim Sutton <tim@kartoza.com>
* Ismail Sunni <imajimatika@gmail.com>
* Kristy Van Putten <Kristy.VanPutten@dfat.gov.au>
* Marco Bernasocchi <marco@opengis.ch>
* Oscar Kurniawan <misugijunz@gmail.com>
* Trevor Dhu <Trevor.Dhu@ausaid.gov.au>
* Gigih Aji Ibrahim <bungcip@gmail.com>
* Akbar Gumbira <akbargumbira@gmail.com>
* Dianne Bencito <diannebencito@essc.org.ph>
* Christian Christelis <christian@kartoza.com>
* Yewondwossen Assefa <assefay@gmail.com>


Other contributors who have provided input, testing, translations etc.
Expand Down
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ compile:
@echo "-----------------"
make -C safe/gui/ui

compress-images:
@echo
@echo "-----------------"
@echo "Compress images"
@echo "-----------------"
@scripts/compress-images.sh

#Qt .ts file updates - run to register new strings for translation in safe_qgis
update-translation-strings: compile
#update application strings
Expand Down Expand Up @@ -329,7 +322,7 @@ docker-test: testdata clean
@echo "Regression Test Suite for running in docker"
@echo " against QGIS 2.x"
@echo "----------------------------------"
@-export PYTHONPATH=`pwd`:$(PYTHONPATH); xvfb-run --server-args="-screen 0, 1024x768x24" nosetest s-v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe_qgis safe_qgis
@-export PYTHONPATH=`pwd`:$(PYTHONPATH); xvfb-run --server-args="-screen 0, 1024x768x24" nosetests -v --with-id --with-xcoverage --with-xunit --verbose --cover-package=safe_qgis safe_qgis


##########################################################
Expand Down
2 changes: 1 addition & 1 deletion realtime/sftp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(at your option) any later version.
"""
__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '0.5.0'
__date__ = '10/01/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
Expand Down
2 changes: 1 addition & 1 deletion realtime/sftp_shake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(at your option) any later version.
"""
__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '0.5.0'
__date__ = '14/01/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
Expand Down
4 changes: 0 additions & 4 deletions realtime/shake_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,10 +1834,6 @@ def setup_i18n(self):
TranslationLoadException
"""
locale_name = self.locale
# Also set the system locale to the user overridden local
# so that the inasafe library functions gettext will work
# .. see:: :py:func:`common.utilities`
os.environ['LANG'] = str(locale_name)

root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
translation_path = os.path.join(
Expand Down
2 changes: 1 addition & 1 deletion realtime/test/test_sftp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '0.5.0'
__date__ = '10/01/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
Expand Down
2 changes: 1 addition & 1 deletion realtime/test/test_sftp_shake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '0.5.0'
__date__ = '10/01/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
Expand Down
2 changes: 1 addition & 1 deletion realtime/update_latest_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '0.5.0'
__date__ = '21/02/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
Expand Down
104 changes: 50 additions & 54 deletions safe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
__date__ = '10/01/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')

import os

# Import the PyQt and QGIS libraries
Expand All @@ -30,56 +29,53 @@
QTranslator,
QCoreApplication,
QSettings)
from PyQt4.QtGui import QMessageBox

try:
# When upgrading, using the plugin manager, you may get an error when
# doing the following import, so we wrap it in a try except
# block and then display a friendly message to restart QGIS
# noinspection PyUnresolvedReferences
from exceptions import TranslationLoadError
except ImportError:
# Note we use translate directly but the string may still not translate
# at this early stage since the i18n setup routines have not been called
# yet.
# noinspection PyTypeChecker,PyArgumentList
myWarning = QCoreApplication.translate(
'InaSAFE', 'Please restart QGIS to use this plugin.')
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', myWarning)

# Setup internationalisation for the plugin.
#
# See if QGIS wants to override the system locale
# and then see if we can get a valid translation file
# for whatever locale is effectively being used.

override_flag = QSettings().value(
'locale/overrideFlag', True, type=bool)

if override_flag:
locale_name = QSettings().value('locale/userLocale', 'en_US', type=str)
else:
locale_name = QLocale.system().name()
# NOTES: we split the locale name because we need the first two
# character i.e. 'id', 'af, etc
locale_name = str(locale_name).split('_')[0]

# Also set the system locale to the user overridden local
# so that the inasafe library functions gettext will work
# .. see:: :py:func:`common.utilities`
os.environ['LANG'] = str(locale_name)

root = os.path.abspath(os.path.join(os.path.dirname(__file__)))
translation_path = os.path.abspath(os.path.join(
root, os.path.pardir, 'i18n', 'inasafe_' + str(locale_name) + '.qm'))

if os.path.exists(translation_path):
translator = QTranslator()
result = translator.load(translation_path)
if not result:
message = 'Failed to load translation for %s' % locale_name
raise TranslationLoadError(message)
# noinspection PyTypeChecker,PyCallByClass
QCoreApplication.installTranslator(translator)

from safe.common.exceptions import TranslationLoadError


def locale():
"""Find out the two letter locale for the current session.
See if QGIS wants to override the system locale
and then see if we can get a valid translation file
for whatever locale is effectively being used.
:returns: ISO two letter code for the users's preferred locale.
:rtype: str
"""
override_flag = QSettings().value(
'locale/overrideFlag', True, type=bool)
if override_flag:
locale_name = QSettings().value('locale/userLocale', 'en_US', type=str)
else:
locale_name = QLocale.system().name()
# NOTES: we split the locale name because we need the first two
# character i.e. 'id', 'af, etc
locale_name = str(locale_name).split('_')[0]
return locale_name


def translation_file():
"""Get the path to the translation file.
:returns: Path to the translation.
"""
locale_name = locale()
root = os.path.abspath(os.path.join(os.path.dirname(__file__)))
translation_path = os.path.abspath(os.path.join(
root, os.path.pardir, 'i18n', 'inasafe_' + str(locale_name) + '.qm'))
return translation_path


def load_translation():
"""Load the translation file preferred by the user."""
path = translation_file()
if os.path.exists(path):
translator = QTranslator()
result = translator.load(path)
if not result:
message = 'Failed to load translation for %s' % path
raise TranslationLoadError(message)
# noinspection PyTypeChecker,PyCallByClass
QCoreApplication.installTranslator(translator)

load_translation()
2 changes: 1 addition & 1 deletion safe/common/dynamic_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# for s in strings:
# names[s] = '_(%s)' % s

from safe.common.utilities import ugettext as tr
import PyQt4.QtCore.QObject.tr as tr


# Don't call this function
Expand Down
2 changes: 1 addition & 1 deletion safe/common/minimum_needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from collections import OrderedDict
import json
from safe.common.utilities import ugettext as tr
import PyQt4.QtCore.QObject.tr as tr
from os.path import exists, dirname
from os import remove

Expand Down
2 changes: 1 addition & 1 deletion safe/common/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
__project_name = 'inasafe-dev'
__filename = '__init__.py'
__date__ = '12/15/14'
__copyright__ = 'imajimatika@gmail.com'
__copyright__ = 'ismail@kartoza.com'
__doc__ = ''
2 changes: 1 addition & 1 deletion safe/common/test/test_resource_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(at your option) any later version.
"""
__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '3.0'
__revision__ = '$Format:%H$'
__date__ = '12/15/14'
Expand Down
2 changes: 1 addition & 1 deletion safe/common/test/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '1.1.1'
__revision__ = '$Format:%H$'
__date__ = '05/05/2014'
Expand Down
2 changes: 1 addition & 1 deletion safe/common/test/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(at your option) any later version.
"""
__author__ = 'imajimatika@gmail.com'
__author__ = 'ismail@kartoza.com'
__version__ = '2.2.0'
__revision__ = '$Format:%H$'
__date__ = '11/13/14'
Expand Down
27 changes: 1 addition & 26 deletions safe/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy
import zipfile
import platform
import gettext
from datetime import date
import getpass
from tempfile import mkstemp
Expand Down Expand Up @@ -63,26 +62,6 @@ def verify(statement, message=None):
raise VerificationError(message)


def ugettext(s):
"""Translation support."""
path = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.path.pardir,
os.path.pardir,
'i18n'))
if 'LANG' not in os.environ:
return s
if not s:
return s

lang = os.environ['LANG']
filename_prefix = 'inasafe'
t = gettext.translation(
filename_prefix, path, languages=[lang], fallback=True)
return t.ugettext(s)


def temp_dir(sub_dir='work'):
"""Obtain the temporary working directory for the operating system.
Expand Down Expand Up @@ -331,11 +310,7 @@ def format_int(x):
"""

# This is broken
# import locale
# locale.setlocale(locale.LC_ALL, '') # Broken, why?
# s = locale.format('%d', x, 1)
lang = os.getenv('LANG')

try:
s = '{0:,}'.format(x)
# s = '{0:n}'.format(x) # n means locale aware (read up on this)
Expand Down
8 changes: 5 additions & 3 deletions safe/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from PyQt4.QtCore import QSettings
from safe.common.resource_parameter import ResourceParameter
from safe.common.utilities import ugettext as tr
from utilities.i18n import tr


def define_defaults():
Expand Down Expand Up @@ -195,14 +195,15 @@ def default_provenance():


def disclaimer():
from safe.utilities.i18n import tr

"""Get a standard disclaimer.
:returns: Standard disclaimer string for InaSAFE.
:rtype: str
"""
# import tr here to avoid side effects with safe (see notes above in import
# section.
from safe.utilities.utilities import tr
text = tr(
'InaSAFE has been jointly developed by Indonesian '
'Government-BNPB, Australian Government-AIFDR and the World '
Expand Down Expand Up @@ -234,14 +235,15 @@ def default_north_arrow_path():


def limitations():
from safe.utilities.i18n import tr

"""Get InaSAFE limitations.
:return: All limitations on current InaSAFE.
:rtype: list
"""
# import tr here to avoid side effects with safe (see notes above in import
# section.
from safe.utilities.utilities import tr
limitation_list = list()
limitation_list.append(tr('InaSAFE is not a hazard modelling tool.'))
limitation_list.append(
Expand Down
11 changes: 6 additions & 5 deletions safe/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
"""

import numpy
from datetime import datetime
from socket import gethostname
import getpass

from safe.storage.projection import Projection
from safe.storage.projection import DEFAULT_PROJECTION
from safe.impact_functions.core import extract_layers
from safe.common.utilities import unique_filename, verify
from utilities import REQUIRED_KEYWORDS
from datetime import datetime
from socket import gethostname
from safe.common.utilities import ugettext as tr
import getpass
from safe.utilities.i18n import tr
from safe.engine.utilities import REQUIRED_KEYWORDS


# The LOGGER is intialised in utilities.py by init
import logging
Expand Down
Loading

0 comments on commit ce984bb

Please sign in to comment.