diff --git a/frappe/__init__.py b/frappe/__init__.py index d997b967ce..7664ac4c61 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -49,7 +49,11 @@ class _dict(dict): return _dict(dict(self).copy()) def _(msg, lang=None, context=None): - """Returns translated string in current lang, if exists.""" + """Returns translated string in current lang, if exists. + Usage: + _('Change') + _('Change', context='Coins') + """ from frappe.translate import get_full_dict from frappe.utils import strip_html_tags, is_html diff --git a/frappe/tests/test_translate.py b/frappe/tests/test_translate.py index 02dbd46fa5..4dcaf3e979 100644 --- a/frappe/tests/test_translate.py +++ b/frappe/tests/test_translate.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe, unittest, os import frappe.translate +from frappe import _ dirname = os.path.dirname(__file__) translation_string_file = os.path.join(dirname, 'translation_test_file.txt') @@ -13,6 +14,11 @@ class TestTranslate(unittest.TestCase): data = frappe.translate.get_messages_from_file(translation_string_file) self.assertListEqual(data, expected_output) + def test_translation_with_context(self): + frappe.local.lang = 'fr' + self.assertEqual(_('Change'), 'Changement') + self.assertEqual(_('Change', context='Coins'), 'la monnaie') + expected_output = [ ('apps/frappe/frappe/tests/translation_test_file.txt', 'Warning: Unable to find {0} in any table related to {1}', 'This is some context', 2), ('apps/frappe/frappe/tests/translation_test_file.txt', 'Warning: Unable to find {0} in any table related to {1}', None, 4), diff --git a/frappe/translate.py b/frappe/translate.py index 70f96aad51..c3dbdfe7ea 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -232,7 +232,7 @@ def get_translation_dict_from_file(path, lang, app): for item in csv_content: if len(item)==3 and item[2]: - key = item[1] + ':' + item[2] + key = item[0] + ':' + item[2] translation_map[key] = strip(item[1]) elif len(item) in [2, 3]: translation_map[item[0]] = strip(item[1]) diff --git a/frappe/translations/fr.csv b/frappe/translations/fr.csv index a724f78552..bc7f22c4f5 100644 --- a/frappe/translations/fr.csv +++ b/frappe/translations/fr.csv @@ -4141,3 +4141,5 @@ Path,Chemin, Components,Composants, Verified By,Vérifié Par, Lead Conversion Time,Temps de conversion des prospects, +Change,Changement, +Change,la monnaie,Coins \ No newline at end of file