voidlabs / mosaico

Mosaico - Responsive Email Template Editor
https://mosaico.io
GNU General Public License v3.0
1.71k stars 504 forks source link

Multilanguage support in templates ? #308

Closed emu42 closed 7 years ago

emu42 commented 7 years ago

Hello,

is there a way to internationalize a mosaico template? I mean labels and such like "Show Title" in the versafix template. I am aware of multilanguage support in the menus (by passing the respective resources to Mosaico on initialization), but without i18n support in templates this seems like an incomplete solution.

Or is the only way to currently achieve this, by copying and translating the template for each language?

Regards, Edmund

bago commented 7 years ago

At this time we think the best way is to provide translated templates. Given strings are defined in templates you can't expect them to be part of a "language pack for the library".

BTW, if you want to make mosaico try to translate those strings like the UI strings then you can create a viewModel plugin like this:

templateLanguagePlugin = function(viewModel) {
  viewModel.ut = function(category, key) {
    return viewModel.tt(key);
  };
};

viewModel.ut function is called for most template labels.

emu42 commented 7 years ago

Hello Bago,

I tried this solution, but so far it's not working. Eg. I added "Image position": "Bild Position" to mosaico-de.json, but the label still shows as "Image position".

I did some debugging and it seems the viewModel.tt(key) call always returns the original key. The plugin is registered and it does get called. Also, I double-checked the initialization parameters and the "Image position" key definitely gets passed to Mosaico along with the other German language resources (which show up just fine in the menus etc.). I have not (as yet) debugged the viewModel.tt(..) method and I hope you can spare me the trouble. ;)

emu42 commented 7 years ago

Ah, nevermind. I just figured out that I need to call viewModel.t(..) instead of .tt(..).