CodeIgniter Forums

Full Version: Multi-language support - How to change language in the view?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

I followed the instructions but cannot load languages in the view.
For example in page's result is shown 5 languages.

Example for one language lang('academic.article') but how we have do for 5 language?

Thanks all
Thanks for your reply but I'm still having this issue. Exclamation
It is intended to display on one page five languages simultaneously in the view.

Idea for example "$request->setLocale('ru')". This command only works in the control.

We need to run this command or same code in the view for switch languages concurrently.
Best simple way of doing it is to use google translate.

How TO - Google Translate
(06-30-2019, 05:20 AM)yamahdico Wrote: [ -> ]Thanks for your reply but I'm still having this issue. Exclamation
It is intended to display on one page five languages simultaneously in the view.

Idea for example "$request->setLocale('ru')". This command only works in the control.

We need to run this command or same code in the view for switch languages concurrently.

All the “hard work” should be done in the controller, never in the view. It can be done in a model or library but the final result should be fetched by the controller and passed to the view. 

If you want to get the same language string in five different languages, you can call setLocale for each languages, get the translated text string and store the result in an array, and then pass this array of text to the view so it can be displayed in the HTML document or used in JavaScript.
To display different currency, it is predesignated to be used in the view as the third parameter to the lang() method, but we want to return the string by the language key in many languages.

For example, similar to the currency as the third parameter:
https://codeigniter4.github.io/userguide...ing-locale
Can't you pass the the locale for the language you want as the third param of the `lang()` calls and get the results you want?

Code:
echo lang('foo.bar', [], 'en');
echo lang('foo.bar', [], 'fr');