Fallback languagestrings in com_config

19 views
Skip to first unread message

Bakual

unread,
May 23, 2013, 5:28:44 AM5/23/13
to joomla-de...@googlegroups.com
Hi

In my own component, I use the english language as fallback if the active language has some untranslated strings. I do this by first loading the english language file and afterwards the current active language using this:

$jlang = JFactory::getLanguage();
$jlang->load('com_sermonspeaker', JPATH_COMPONENT, 'en-GB', true);
$jlang->load('com_sermonspeaker', JPATH_COMPONENT, null, true);

This works very nice. Now it would be great if I could do that for the component options as well. But since those are processed by com_config, I can't do it the same way.
Is there an easy way for achieving the same thing in an extension options view? Someone did that already?

Websiteconcepts

unread,
May 23, 2013, 5:41:42 AM5/23/13
to joomla-de...@googlegroups.com
for your information i't already done in FOF, so perhaps look at the way Nico solved it

Ruud van Zuidam
M  DE :  +4915730448257 oder  NL : +31637170938





--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nikolaos K. Dionysopoulos

unread,
May 23, 2013, 5:47:51 AM5/23/13
to joomla-de...@googlegroups.com
It's an old solution. I had it in my components for 2-3 years before putting that in FOF, too. But, yep, that's pretty much how I do it:

if ($this->isBackend())
{
$paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR);
}
else
{
$paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT);
}

$jlang = JFactory::getLanguage();
$jlang->load($component, $paths[0], 'en-GB', true);
$jlang->load($component, $paths[0], null, true);
$jlang->load($component, $paths[1], 'en-GB', true);
$jlang->load($component, $paths[1], null, true);

Where $component is your component's name, e.g. $component = 'com_example';

Let me break it down for easier understanding. The first path ($paths[0]) is the other side of component; if we're in the back-end that's the front-end. The second path ($path[1]) is the path on this side of the component. So our code does the following:
- Load the en-GB (English) fall-back language from the other side
- Load the user preferred (or site default) language from the other side
- Load the en-GB (English) fall-back language from this side
- Load the user preferred (or site default) language from this side

The first two are particular to how my components work, sharing language keys between the front- and back-end. Most developers may want to skip them. The last two lines are those that implement the fall-back. Please remember that the fourth argument in the load() call must be true which means "overwrite existing translations with the ones we just loaded". Otherwise you'll end up with untranslated strings.

I hope that helps!

Nicholas K. Dionysopoulos

Bakual

unread,
May 23, 2013, 6:15:44 AM5/23/13
to joomla-de...@googlegroups.com
Maybe I was a bit unclear. I do this as well in my component and it works fine. But this solution doesn't work for language strings within the component options, because the options are done by com_config.
The only solution I see atm is to load the strings within a custom formfield, but maybe there is a more elegant solution?
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

Nikolaos K. Dionysopoulos

unread,
May 23, 2013, 6:26:52 AM5/23/13
to joomla-de...@googlegroups.com
These are the only language strings that cannot be loaded this way because it's Joomla! itself loading the language strings, not your code. You could do that with a special field, but it would have to be the very first field on your form. The drawback is that it would render a visibly blank row above your component's options form.

Nicholas K. Dionysopoulos

To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.

Allon Moritz

unread,
May 23, 2013, 6:32:25 AM5/23/13
to joomla-de...@googlegroups.com
What about a system plugin which loads the language? Not the best solution but it should work :-)

Thomas PAPIN

unread,
May 23, 2013, 7:48:36 AM5/23/13
to joomla-de...@googlegroups.com
When doing :

$jlang = JFactory::getLanguage();
$jlang->load($component, $paths[0], 'en-GB', true);
$jlang->load($component, $paths[0], null, true);
$jlang->load($component, $paths[1], 'en-GB', true);
$jlang->load($component, $paths[1], null, true);

What happen to the "overrides" in overrides/ directory.
Each time you load language, the override is reloaded ?
Or language string in the overrides files have some special properties than even if you reload the component language file, the overrive translation is kept.

I will check the code, but if someone knows already the answer :)


2013/5/23 Nikolaos K. Dionysopoulos <niko...@gmail.com>

Bakual

unread,
May 23, 2013, 7:55:59 AM5/23/13
to joomla-de...@googlegroups.com
$jlang->load() should take care of overrides. If an override is present, it will load this file instead of the original one. So this does work fine.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.

Bakual

unread,
May 23, 2013, 7:59:12 AM5/23/13
to joomla-de...@googlegroups.com
I will try to load the strings in a custom formfield then. Since I already have a custom one at first position, the blank row isn't an issue in my case, I just use this element.
Reply all
Reply to author
Forward
0 new messages