fix: Contextual translation key generation
This commit is contained in:
parent
c59418cadb
commit
981da526f9
4 changed files with 14 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
Loading…
Add table
Reference in a new issue