diff --git a/tests/native/core/test_core.py b/tests/native/core/test_core.py
index 616469e..9e2623a 100644
--- a/tests/native/core/test_core.py
+++ b/tests/native/core/test_core.py
@@ -52,13 +52,14 @@ class TestNative(object):
def _get_tx(self, **kwargs):
mytx = TxNative()
- mytx.setup(languages=['en', 'el'], token='cds_token', **kwargs)
+ mytx.setup(source_language='en', languages=['en', 'el'],
+ token='cds_token', **kwargs)
return mytx
@patch('transifex.native.core.StringRenderer.render')
def test_translate_source_language_reaches_renderer(self, mock_render):
mytx = self._get_tx()
- mytx.translate('My String', 'en', is_source=True)
+ mytx.translate('My String', 'en')
mock_render.assert_called_once_with(
source_string='My String',
string_to_render='My String',
@@ -74,13 +75,13 @@ def test_translate_target_language_missing_reaches_renderer(self, mock_render,
mock_cache):
mock_cache.return_value = None
mytx = self._get_tx()
- mytx.translate('My String', 'en', is_source=False)
+ mytx.translate('My String', 'foo')
mock_cache.assert_called_once_with(
- generate_key(string='My String'), 'en')
+ generate_key(string='My String'), 'foo')
mock_render.assert_called_once_with(
source_string='My String',
string_to_render=None,
- language_code='en',
+ language_code='foo',
escape=True,
missing_policy=mytx._missing_policy,
params={},
@@ -89,7 +90,7 @@ def test_translate_target_language_missing_reaches_renderer(self, mock_render,
def test_translate_target_language_missing_reaches_missing_policy(self):
missing_policy = MagicMock()
mytx = self._get_tx(missing_policy=missing_policy)
- mytx.translate('My String', 'en', is_source=False)
+ mytx.translate('My String', 'foo')
missing_policy.get.assert_called_once_with('My String')
@patch('transifex.native.core.StringRenderer')
@@ -97,10 +98,10 @@ def test_translate_error_reaches_error_policy(self, mock_renderer):
error_policy = MagicMock()
mock_renderer.render.side_effect = Exception
mytx = self._get_tx(error_policy=error_policy)
- mytx.translate('My String', 'en', is_source=False)
+ mytx.translate('My String', 'en')
error_policy.get.assert_called_once_with(
- source_string='My String', translation=None, language_code='en',
- escape=True, params={},
+ source_string='My String', translation="My String",
+ language_code='en', escape=True, params={},
)
def test_translate_error_reaches_source_string_error_policy(
@@ -111,7 +112,7 @@ def test_translate_error_reaches_source_string_error_policy(
mock_missing_policy = MagicMock()
mock_missing_policy.get.side_effect = Exception
mytx = self._get_tx(missing_policy=mock_missing_policy)
- result = mytx.translate('My String', 'en', is_source=False)
+ result = mytx.translate('My String', 'en')
assert result == 'My String'
@patch('transifex.native.core.StringRenderer')
@@ -130,7 +131,7 @@ def test_source_string_policy_custom_text(
mytx = self._get_tx(
error_policy=error_policy
)
- result = mytx.translate('My String', 'en', is_source=False)
+ result = mytx.translate('My String', 'en')
assert result == 'my-default-text'
def test_translate_source_language_renders_icu(self):
@@ -138,7 +139,6 @@ def test_translate_source_language_renders_icu(self):
translation = mytx.translate(
u'{cnt, plural, one {{cnt} duck} other {{cnt} ducks}}',
'en',
- is_source=True,
params={'cnt': 1}
)
assert translation == '1 duck'
@@ -149,8 +149,7 @@ def test_translate_target_language_renders_icu(self, mock_cache):
mytx = self._get_tx()
translation = mytx.translate(
u'{cnt, plural, one {{cnt} duck} other {{cnt} ducks}}',
- 'en',
- is_source=False,
+ 'el',
params={'cnt': 1}
)
assert translation == u'1 παπί'
@@ -160,7 +159,6 @@ def test_translate_source_language_escape_html_true(self):
translation = mytx.translate(
u'',
'en',
- is_source=True,
escape=True,
params={'cnt': 1}
)
@@ -173,7 +171,6 @@ def test_translate_source_language_escape_html_false(self):
translation = mytx.translate(
u'',
'en',
- is_source=True,
escape=False,
params={'cnt': 1}
)
diff --git a/tests/native/django/test_templatetag.py b/tests/native/django/test_templatetag.py
index 1bb6ee9..a678ad5 100644
--- a/tests/native/django/test_templatetag.py
+++ b/tests/native/django/test_templatetag.py
@@ -6,6 +6,8 @@
from transifex.native import tx
from transifex.native.rendering import SourceStringPolicy
+tx.setup(source_language="en_US")
+
def do_test(template_str, context_dict=None, autoescape=True,
lang_code="en-us"):
diff --git a/transifex/native/core.py b/transifex/native/core.py
index 3e74837..9cec86f 100644
--- a/transifex/native/core.py
+++ b/transifex/native/core.py
@@ -101,7 +101,7 @@ def fetch_translations(self, language_code=None, force=False):
self._cache.update(translations)
def translate(
- self, source_string, language_code=None, is_source=False,
+ self, source_string, language_code=None,
_context=None, escape=True, params=None
):
"""Translate the given string to the provided language.
@@ -109,8 +109,6 @@ def translate(
:param unicode source_string: the source string to get the translation
for e.g. 'Order: {num, plural, one {A table} other {{num} tables}}'
:param str language_code: the language to translate to
- :param bool is_source: a boolean indicating whether `translate`
- is being used for the source language
:param unicode _context: an optional context that accompanies
the string
:param bool escape: if True, the returned string will be HTML-escaped,
@@ -129,8 +127,7 @@ def translate(
translation_template = self.get_translation(source_string,
language_code,
- _context,
- is_source)
+ _context)
return self.render_translation(translation_template,
params,
@@ -138,8 +135,7 @@ def translate(
language_code,
escape)
- def get_translation(self, source_string, language_code, _context,
- is_source=False):
+ def get_translation(self, source_string, language_code, _context):
""" Try to retrieve the translation.
A translation is a serialized source_string with ICU format
@@ -147,7 +143,7 @@ def get_translation(self, source_string, language_code, _context,
'{num, plural, one {Ένα τραπέζι} other {{num} τραπέζια}}'
"""
- if is_source:
+ if language_code == self.source_language_code:
translation_template = source_string
else:
pluralized, plurals = parse_plurals(source_string)
diff --git a/transifex/native/django/templatetags/transifex.py b/transifex/native/django/templatetags/transifex.py
index fb87e75..5e31147 100644
--- a/transifex/native/django/templatetags/transifex.py
+++ b/transifex/native/django/templatetags/transifex.py
@@ -2,7 +2,6 @@
from copy import copy
-from django.conf import settings
from django.template import Library, Node, TemplateSyntaxError
from django.template.base import (BLOCK_TAG_END, BLOCK_TAG_START,
COMMENT_TAG_END, COMMENT_TAG_START,
@@ -207,11 +206,9 @@ def render(self, context):
# ICU template. Then we perform ICU rendering against 'params'.
# Inbetween the two steps, if the tag used was 't' and not 'ut', we
# peform escaping on the ICU template.
- is_source = get_language() == settings.LANGUAGE_CODE
locale = to_locale(get_language()) # e.g. from en-us to en_US
translation_icu_template = tx.get_translation(
source_icu_template, locale, params.get('_context', None),
- is_source,
)
if self.tag_name == "t":
source_icu_template = escape_html(source_icu_template)
diff --git a/transifex/native/django/utils/__init__.py b/transifex/native/django/utils/__init__.py
index 76f06bd..8f1593a 100644
--- a/transifex/native/django/utils/__init__.py
+++ b/transifex/native/django/utils/__init__.py
@@ -1,4 +1,3 @@
-from django.conf import settings
from django.utils.translation import get_language, to_locale
from transifex.common.strings import LazyString
from transifex.native import tx
@@ -19,13 +18,11 @@ def translate(_string, _context=None, _escape=True, **params):
:return: the final translation in the current language
:rtype: unicode
"""
- is_source = get_language() == settings.LANGUAGE_CODE
locale = to_locale(get_language()) # e.g. from en-us to en_US
return tx.translate(
_string,
locale,
_context=_context,
- is_source=is_source,
escape=_escape,
params=params,
)