Set language in dynamic loaded content

General questions regarding the use of languages in Joomla! 3.x.

Moderators: infograf768, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
pepperoni
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu May 27, 2010 10:36 am

Set language in dynamic loaded content

Post by pepperoni » Wed Sep 04, 2019 11:28 am

Hi guys,

In a multilanguage site I have a modal window that brings content dynamically.

How can I make sure the content will be translated in the right language?

For example I use JTEXT for the modal title to display the title in the right language but it always gets translated to default language, which is english.

Is there a way to set the language for the JTEXT translations?

many thanks
Otto

harperlala
Joomla! Guru
Joomla! Guru
Posts: 680
Joined: Mon Aug 24, 2015 5:55 pm

Re: Set language in dynamic loaded content

Post by harperlala » Thu Sep 05, 2019 4:24 am

you must create all language text for that content.

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18872
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Set language in dynamic loaded content

Post by infograf768 » Thu Sep 05, 2019 7:01 am

Where do you store the language string for the modal title? In a specific en-GB.whatever.ini which you load? In an override?
Wherever it is stored, the similar string for other languages xx-XX.whatever.ini or override should also be stored.
At reading your post, not sure you also use an ini string for the content itself.
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

pepperoni
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu May 27, 2010 10:36 am

Re: Set language in dynamic loaded content

Post by pepperoni » Thu Sep 05, 2019 7:50 am

The translation strings are in the language override files. The location of these files are /language/ovverrides/xx-XX-.override.ini.

I have tried the following code to set language default:

Code: Select all

$language = JFactory::getLanguage();
$language->setDefault("it-IT");
Although this sets the default language to Italian, it has no effect on loading the override files.

I have also tried the following:

Code: Select all

$language->setLanguage("it-IT");
Although it does change the language metadata and few other bits, still no override change.

I have found this page though https://github.com/joomla/joomla-cms/issues/19183 which helped me solve the issue.

Code: Select all

JFactory::$language = JLanguage::getInstance("it-IT",false);
The above code does work, it loads the italian override file and JTEXT translations are good.

I decided to use the above code together with the setDefault.

If there is a better please let me know.

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 18872
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Set language in dynamic loaded content

Post by infograf768 » Thu Sep 05, 2019 8:14 am

I guess you do not need to add "false" as it is the default for JLanguage::getInstance()
also suggest to use single quotes

Code: Select all

JFactory::$language = JLanguage::getInstance('it-IT');
Jean-Marie Simonet / infograf · http://www.info-graf.fr
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

pepperoni
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Thu May 27, 2010 10:36 am

Re: Set language in dynamic loaded content

Post by pepperoni » Thu Sep 05, 2019 8:19 am

Yes you are right, I'll remove the "false" and take your suggestion to use single quotes.

Thank you infograf768


Post Reply

Return to “Language - Joomla! 3.x”