Skip to content

A Magento 2 module [1] Adds translation data from [module or theme root]/i18n/Js/[locale].csv to frontend translation dictionary. [2] Enables Module to override Theme, Language Pack and DB translations by creating CSV file in specific location inside the Module.

License

OSL-3.0, Unknown licenses found

Licenses found

OSL-3.0
LICENSE.txt
Unknown
COPYING.txt
Notifications You must be signed in to change notification settings

wubinworks/magento2-module-translation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Story

(Everything talked here is for Magento 2.4. See Requirements Section.)

This module, which provides 2 features, is designed as a dependency for making other modules/themes.

  1. During deployment, Magento scans static .js and .html files and picks up translatable strings from them.
    Then Magento generates a js-traslation.json file.
    This file is a dictionary file used for frontend translation,
    For example: <!-- ko i18n: 'Translate Me!' --><!-- /ko -->
    Unfortunately, translatable strings in .phtml(and .php) files are not picked up by Magento(for some reasons).
    If $.mage.__('Some Text') is in .phtml files, it won't be translated.
    This module can force extra data from a separate file(i.e., [module or theme root]/i18n/Js/[locale].csv) to go to js-traslation.json.

  2. Magento loads translation data in the order below:

 |  Module translation: [module root]/i18n/[locale].csv
 |  Language Pack translation
 |  Theme translation: [theme root]/i18n/[locale].csv
\|/ Database translation

Then these translation data are merged and the merge rule is "LAST ONE WINS", which means Database translation overrides everything else.
However, In some cases, especially when doing local development to translate very general phrases in specific business field, the Module creator wants to override Language Pack and Theme translations without modifying those third party packages.
This module adds extra locations for translation files(CSV), so the loading order becomes:

 |  Module translation: [module root]/i18n/[locale].csv

 |  Language Pack translation

 |  Theme translation: [theme root]/i18n/[locale].csv

 |  Database translation

 |  Extra Module translation: [module root]/i18n/i18n/[locale].csv

\|/ Extra Theme translation: [theme root]/i18n/i18n/[locale].csv(last-one-wins)

This module works under Store Emulation, too.

Usage and Example

1. Append(merge) translation into js-traslation.json:
Create <module or theme root>/i18n/Js/<locale>.csv like a normal translation CSV file, then its content will go to js-traslation.json(even the phrase cannot be found as a translatable string in static files).

2. Override Language Pack or Theme translations:
Create [module or theme root]/i18n/i18n/[locale].csv like a normal translation CSV file, then it will work.

Check examples of this module inside the i18n folder.

i18n/ja_JP.csv

"###Translate Me!###","翻訳して!"

i18n/i18n/ja_JP.csv

"###Translate Me!###","翻訳してください!(Override)"

i18n/Js/ja_JP.csv

"###This phrase will go to js-translation.json anyway.###","このフレーズは必ずjs-translation.jsonに出現する。"
"###This phrase will be overridden.###","このフレーズはオーバーライドされる"

i18n/i18n/Js/ja_JP.csv

"###This phrase will be overridden.###","このフレーズをオーバーライドした"

Output:

###Translate Me!### -> 翻訳してください!(Override)

Output in js-translation.json:

###This phrase will go to js-translation.json anyway.### -> このフレーズは必ずjs-translation.jsonに出現する。
###This phrase will be overridden.### -> このフレーズをオーバーライドした

Requirements

Magento 2.4

Installation

composer require wubinworks/module-translation

About

A Magento 2 module [1] Adds translation data from [module or theme root]/i18n/Js/[locale].csv to frontend translation dictionary. [2] Enables Module to override Theme, Language Pack and DB translations by creating CSV file in specific location inside the Module.

Topics

Resources

License

OSL-3.0, Unknown licenses found

Licenses found

OSL-3.0
LICENSE.txt
Unknown
COPYING.txt

Stars

Watchers

Forks

Languages