I've built a simple component that sends an email. Inside that component I have my translations strings stored in the ini. Here is some sample code of what I do:
$body = $this->getDetails["name"]." ".JText::_('COM_MYCOMPNOTIFY_MAIL_BODY1')."
".
JText::_('COM_MYCOMPNOTIFY_MAIL_BODY2')." ".$this->getDetails["name"]."
".
JText::_('COM_MYCOMPNOTIFY_MAIL_BODY3')." http://".$this->getDetails["domain"]."
";
This directory structure I have for my component has
language
en-GB
en-GB.com_mycompnotify.ini
pt-BR
pt-BR.com_mycompnotify.ini
My install xml file has this:
<files folder="site">
<filename>index.html</filename>
...
<folder>helpers</folder>
<folder>language</folder>
</files>
This works fine for the en-GB
language. But I can't get it to translate for pt-BR
. I think the issue is that I have an external php file that calls my component. So it wouldn't know to load pt-BR language file (I think).
So I tried to force it to load:
$lang = JFactory::getLanguage();
$lang->load('com_mycompnotify', JPATH_BASE, 'pt-BR'); //also tried JPATH_SITE
But no matter what I try I always get English.
for specifying language files in component xml file you should add somthing like this :
<languages folder="admin">
<language tag="en-GB">language/en-GB/en-GB.com_NAME.ini</language>
<language tag="en-GB">language/en-GB/en-GB.com_NAME.sys.ini</language>
<language tag="pt-BR">language/pt-BR/pt-BR.com_NAME.ini</language>
<language tag="pt-BR">language/pt-BR/pt-BR.com_NAME.sys.ini</language>
</languages>
if you are developing a component Not just for administrator
side only, you can add site languages files like this :
<languages folder="site">
<language tag="en-GB">language/en-GB/en-GB.com_NAME.ini</language>
<language tag="en-GB">language/en-GB/en-GB.com_NAME.sys.ini</language>
<language tag="pt-BR">language/pt-BR/pt-BR.com_NAME.ini</language>
<language tag="pt-BR">language/pt-BR/pt-BR.com_NAME.sys.ini</language>
</languages>
and for joomla to use the language files which aren't english you should change site's language to your native language.You can download translations for many languages from joomla's official site.