mecodeninja / module-dynamic-translation
N/A
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- magento/framework: *
- magento/module-translation: 100.0.2
This package is not auto-updated.
Last update: 2024-12-17 15:54:42 UTC
README
Magento 2 module that allows a developer to flag rows in translation dictionaries to be added regardless of whether a instance of the string is matched or not.
Install
composer require mecodeninja/module-dynamic-translation
Usage
Append ,dynamic
to any translation which should be added to the dictionary (js-translation.json
).
Example
en_US.csv
"value1","translated value1",dynamic
"value2","translated value2",dynamic
"value3","value3",dynamic
Results in the following js-translation.json
response
{"value1":"translated value1","value2":"translated value2","value3":"value3"}
Scenario
This is helpful if a developer has a value which needs to be translated but the value is part of a dynamic output in a knockout template.
Willwright/Demo/view/frontend/web/template/demo.html
<ul data-bind="foreach: getValues()"> <li> <span data-bind="i18n: $data"></span> </li> </ul>
Willwright/Demo/view/frontend/web/js/demo.js
define(['jquery', 'uiComponent', 'ko'], function ($, Component, ko) { 'use strict'; return Component.extend({ initialize: function () { this._super(); }, getValues: function(){ return [ 'value1', 'value2', 'value3' ]; } }); } );
Normally the above values would not be translated. However, with this module and ,dynamic
added to the appropriate
rows the values will be translated.