This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

JimRed
JimRed

Hello,

I would like to use localization in my plugin components but I don't know how can I use localization in my default.htm file?
I've made lang folder and specified lang.php files and I tried to use the echo Lang::get('acme.blog::lang.app.name'); in my default.htm file but it did not work...

Could you please help my how could I translate my components?

Thank you!

maxDubovsky
maxDubovsky

Easy way is to use Translate plugin and then you can use {{ 'Welcome to our website!'|_ }} this syntax in your partial files like default.htm. If you want to get translations from /lang/en/ folder and lang files use:

public function init()
{
    $this->page['word_keywords'] = Lang::get('acme.demo::lang.word.keywords');
}

in default.htm you will output {{ wordkeywords }} ... you can probably run througn array and pass the whole array... I'm working on this now )))

uXMs
uXMs

another way if you do not want to depend Translate plugin and want to use lang.php files:

<?= e(trans('acme.demo::lang.word.keywords')) ?> use like this way in your .htm files

billyZduke
billyZduke

Tried using that e(trans()) with PHP tags in an .htm partial... Didn't think it would work, and it didn't.

uXMs
uXMs

Have you ever get a chance to take a look at the source codes of the system? Just only one example:

https://github.com/octobercms/october/blob/master/modules/cms/widgets/mediamanager/partials/_body.htm#L6

maybe you wrote wrong in partial. For example forgot echoing or not existent lang key? Have you enabled short php syntax? OctoberCMS uses syntaxes in partials <?= e(trans('acme.demo::lang.word.keywords')) ?> or <?php echo e(trans('acme.demo::lang.word.keywords')) ?> for easy use.

So, if you wouldn't think it works anyway, you should search other logical ways which you think it would work..

lunfel
lunfel

I was able to translate using {{ 'acme.demo::lang.app.keywords' | trans }} and having my french and english lang.php. But I think this method will only work for the component partials.

dev.mnr.j20762
dev.mnr.j20762

lunfel said:

I was able to translate using {{ 'acme.demo::lang.app.keywords' | trans }} and having my french and english lang.php. But I think this method will only work for the component partials.

This did work for me too! Thanks!!!

1-7 of 7

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.