CodeIgniter Forums
Multi-language support - How to change language in the view? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Multi-language support - How to change language in the view? (/showthread.php?tid=73653)



Multi-language support - How to change language in the view? - yamahdico - 05-18-2019

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


RE: Multi-language support - How to change language in the view? - InsiteFX - 06-01-2019

Create a CMS using CodeIgniter 3

Build multi language website in codeigniter.

CI 4 Has language built-in so it maybe a little different then CI 3.

SEE:

CodeIgniter 4 User Guide - Localization


RE: Multi-language support - How to change language in the view? - yamahdico - 06-30-2019

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.


RE: Multi-language support - How to change language in the view? - InsiteFX - 06-30-2019

Best simple way of doing it is to use google translate.

How TO - Google Translate


RE: Multi-language support - How to change language in the view? - includebeer - 07-01-2019

(06-30-2019, 04: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.


RE: Multi-language support - How to change language in the view? - yamahdico - 07-01-2019

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/outgoing/localization.html?highlight=language#specifying-locale


RE: Multi-language support - How to change language in the view? - kilishan - 07-01-2019

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');