Is there a way to translate a single string with a language that is different from the default language?
(Google search did not lead me to a solution.) Example code that does not work:
// This shows in the default joomla language "en-GB" echo JText::_('COM_COMPONENT_TEXT'); // Now I load the second language into an language object $lang = JLanguage::getInstance('af-ZA'); // Now I translate the below string with "af-ZA" echo $lang->_('COM_COMPONENT_TRANSLATEDTEXT'); // Now the third text is again in default language "en-GB" echo JText::_('COM_COMPONENT_TEXT2');
I created the .ini files needed for the af-ZA translation. The below files were created for the task.
In my tests, I loaded the af-ZA language pack for Joomla. The JText translates correctly if I change my user profile to af-ZA, but then everything is translated to af-ZA -- not just the string I want translated.
My hope is to find a reliable Joomla technique that uses best practice. If it is not possible, I will write my own translation code.
I am building a component behind login on the front part of a client Joomla website. The logged in user can choose a language on an activity that will generate a unique URL with content; the unique URL must show the content in the correct language. The viewer of the content (receiver of the url) won't be logged in for me to get the user language. The rest of the website stays in the default language. I just want the content to be in the language specified in the url.