normally templates have a smarty function like this: {l s="string"}
while modules just use $this->l('string');
. On controllers the l() function seems not to be available, so qhat if I want to set up some text to be translated from backoffice?
Asked
Active
Viewed 3,206 times
2

Luca Reghellin
- 7,426
- 12
- 73
- 118
2 Answers
3
It is available in controllers You just need to add module object in play.
You should do this
$this->module->l('Your string to translate', 'file_name');
For example if you are in validation.php
your 'file_name'
should be just 'validation'
So full example looks like this
$this->module->l('Your string to translate', 'validation');

madeye
- 1,398
- 3
- 15
- 33
0
in both cases there is used methods from class Translate
e.g. for module translations Translate::getModuleTranslation(...)
, you can check classes/Transalte.php
and find there static method getAdminTranslation(...)
and in AdminController child classes available l()
method that use it.

Serge P
- 1,863
- 13
- 14
-
Mmm, but what about frontend controllers? – Luca Reghellin Nov 16 '15 at 07:50
-
I just not sure why you need to translate something in frontend controller, why not just e.g. assign needed "string" to smarty variable in controller and then `{l s="string"}` in template? by default I see no ways to do it – Serge P Nov 16 '15 at 08:34
-
1we developers always have a need, if we ask :) In this case, I need to programmatically build strings based on several variables and (only) then assign them to smarty vars. I don't see ways, just as you, though. I think you're right: we can't. But it's quite strange: I don't see the point in making l() function available for modules but not for frontend controllers. Both assign smarty vars, so both need it. Bah... – Luca Reghellin Nov 16 '15 at 09:58
-
yeah, just I do not saw full task. But again, if you really need it you can always write controllers `l()` yourself :) – Serge P Nov 16 '15 at 11:15
-
Yes, that's true, still quite annoying since I should also add a translation page to the backoffice. So instead, I'll fall back to dummy things like `if(current lang is x) do x`. Not so good (especially for my client..) but faster. :) – Luca Reghellin Nov 17 '15 at 11:51