Tuesday, February 15, 2022

[FIXED] cakePHP 3.3 internationalization

Issue

How can I set multiple language in case text is in array?

I know that if I use this

<?= __('username')?>

and in directory /src/Locale/de_DE/default.po I have written following

msgid "username"
msgstr "benutzer"

It's gonna change username to benutzer if I set language to de_DE (german)


But what to do if I have this

<?= $this->Form->input('password',['label' =>'Password']); ?>

and I would like to change label Password


Solution

Simple:

$this->Form->input('password', ['label' => __('Password')]);

The __() function simply returns the translated string (more info). In your example you used

<?= ... ?>

which is equivalent to

<?php echo ... ?>


Answered By - JvO

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.