Default language not set in JLanguage

368 views
Skip to first unread message

shumisha

unread,
Feb 21, 2012, 4:10:22 AM2/21/12
to Joomla! CMS Development
Hi all

Working on a multilingual site, I ran into an issue, but before
opening a tracker item, I'd like to get a second opinion from someone
familiar with language handling, which I'm definitely not.

Note that though I found this on a multilingulal site, I think it
applies the same to all sites.

So in short, if one changes a site default language site, this new
value is not stored by the CMS into the $default property of the
JLanguage object, thus resulting in the 'en-GB' hardcoded default
value to always be returned when JFactory::getLanguage()->getDefault()
is called.

Now I have found this doesn't cause so much trouble because in many
key parts of the CMS, getDefault() is not used, but instead the
language component params are read directly, as in:

$default_language = JComponentHelper::getParams('com_languages')-
>get('administrator'); // read the admin default language.

Now:

1 - this seems counterintuitive, as surely JLangage::getDefault()
should return the actual site default language
2 - on several other instances, code in the CMS do use getDefault()
(for instance when trying to load language files), and this will
return the wrong value.

A simple fix would be for the application object to store this value
on its OnAfterInitialise event handler, using JFactory::getLanguage()-
>setDefault(). Maybe it was assumed the platform initialise() method
would be doing that (don't think it should, that's really CMS stuff)

I'm missing something on what getDefault() should do?

Thanks and regards
Yannick

JM Simonet

unread,
Feb 21, 2012, 4:59:04 AM2/21/12
to joomla-...@googlegroups.com
I can't reproduce your issue.

In fact it is used all over the CMS under the form

$lang = JFactory::getLanguage();
[...]
$lang->load([...]$lang->getDefault()[...]

It always returns the current JPATH language if available, en-GB if
the specific ini file is not present.

See function
public function load($extension = 'joomla', $basePath = JPATH_BASE,
$lang = null, $reload = false, $default = true)

JM

>--
>You received this message because you are subscribed to the Google
>Groups "Joomla! CMS Development" group.
>To post to this group, send an email to joomla-...@googlegroups.com.
>To unsubscribe from this group, send email to
>joomla-dev-cm...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/joomla-dev-cms?hl=en-GB.


--
>Please keep the Subject wording in your answers
This e-mail and any attachments may be confidential. You must not
disclose or use the information contained in this e-mail if you are
not the
intended recipient. If you have received this e-mail in error, please
notify us immediately and delete the e-mail and all copies.
-----------------------------------------------------------
Jean-Marie Simonet / infograf768
Joomla Production Working group
Joomla! Translation Coordination Team

elin

unread,
Feb 21, 2012, 5:25:17 AM2/21/12
to joomla-...@googlegroups.com
 I think I had this issue too when working on some language issues in Smart Search.  

Elin

shumisha

unread,
Feb 22, 2012, 3:30:37 AM2/22/12
to Joomla! CMS Development
Hi

@Elin: as a matter of fact, com_finder is one of those extensions that
doesn't use getDefault() at all, but instead read default language
directly from com_languages params. This may have to do with that.

@Jean-Marie:
"It always returns the current JPATH language if available, en-GB if
the specific ini file is not present. "
Yes, but I think that behavior is wrong. If current language is not
found, it should not return en-GB but instead the site default
language.

Here is a simpler way to "view" this.

Setup an out of the box localized version of Joomla, the one from
joomla.fr will do fine. It has both en-GB and fr-FR installed and fr-
FR is the default language.

Now edit /components/com_content/content.php, and add near the top:

echo JFactory::getLanguage()->getDefault();

Visit any J! content page on the site (home page will do). I believe
this should display fr-FR, the site default language, but it displays
en-GB.

Yannick

JM Simonet

unread,
Feb 22, 2012, 5:58:07 AM2/22/12
to joomla-...@googlegroups.com
I understand now what you say.
You would like getDefault() to first try to
return the existing site language, then if not
found the site default language before falling
back to en-GB.
Right?
JM

>
>
>@Jean-Marie:
>"It always returns the current JPATH language if available, en-GB if
>the specific ini file is not present. "
>Yes, but I think that behavior is wrong. If current language is not
>found, it should not return en-GB but instead the site default
>language.
>
>Here is a simpler way to "view" this.
>
>Setup an out of the box localized version of Joomla, the one from
>joomla.fr will do fine. It has both en-GB and fr-FR installed and fr-
>FR is the default language.
>
>Now edit /components/com_content/content.php, and add near the top:
>
>echo JFactory::getLanguage()->getDefault();
>
>Visit any J! content page on the site (home page will do). I believe
>this should display fr-FR, the site default language, but it displays
>en-GB.
>
>Yannick
>
>
>On 21 fév, 11:25, elin <elin.war...@gmail.com> wrote:
>> I think I had this issue too when working on some language issues in Smart
>> Search.
>>
>> Elin
>

shumisha

unread,
Feb 22, 2012, 8:58:45 AM2/22/12
to Joomla! CMS Development
Hi

Well, I don't really "want" that. I think that's how it is supposed to
work - ie getDefault() should return default language, not some
arbitrary, hardcoded value.

What if en-GB is not installed on the site for instance?

In any case, if my site is spanish and german, and default is German,
I'm pretty sure getDefault() should not return en-GB at all.


Yannick

shumisha

unread,
Feb 22, 2012, 9:09:33 AM2/22/12
to Joomla! CMS Development
Jean-Marie, reading again your message, I think the issue I have is
one about what getDefault() is supposed to do.

In my mind, it's only purpose is to return whatever language has been
set as the default language for the site by the user. Whether the site
is multilngual or not.
So for instance on a French, mono-lingual site, getDefault() should
return fr-FR.

Now on a multi-lingual site, Default = German and other language =
Spanish, getDefault() should always return de-DE, regardless of the
language the current request is for. If displaying a page in spanish
on that page, getDefault() should still return de-DE. It is
JFactory::getLanguage() job to find an return the spanish language
object.

Do we agree on this expected behavior, or am I simply confused about
what getDefault() is supposed to do?

Thanks

Christophe Demko

unread,
Feb 23, 2012, 10:02:53 AM2/23/12
to Joomla! CMS Development
You can call $lang->setDefault('your language code') to overwrite the
'en-GB' value

elin

unread,
Feb 23, 2012, 6:25:00 PM2/23/12
to joomla-...@googlegroups.com
Okay so if I understand correctly there are two different ways that people are interpreting default. One is the site default in a mulitlingual site, the other is a default when there is no language defined at all, which is the fall back to en-GB. For  Search, for example, we would want to assume the language * is the site default language not English.  Other than that we don't care.  For other situations you want the en-GB value available.

Is that right?

Elin

JM Simonet

unread,
Feb 24, 2012, 3:47:28 AM2/24/12
to joomla-...@googlegroups.com
The site default language is a parameter applying to Multilingual sites as well as Monolanguage ones.

In multilingual sites its use is defined by the parameter  for new visitors set in the languagefilter plugin (concerning the language set as default in Language Manager=>Installed) as well as the language set as default by a registered user logged.
Otherwise a cookie is set and next visit from a user not logged will always load the last instance of the site, i.e in the last UI language.

In a monolanguage site, its value may change only if multiple language packs are installed and a user has set one of these as his site default language when logged (same as in 1.5).

As of now --- and without an important refactoring due to the large use of $default = false  in the function load(), (JModuleHelper, JComponentHelper, ...)-- getDefault() is always returning en-GB. It is used when an ini file is missing in the UI Target language.
It is defined in language.php
protected $default = 'en-GB';

A "normal" installation of Joomla shall not delete the en-GB language (it is protected in db).
No confusion should be done between the languages installed in Joomla, and the Content Languages defined in the Language Manager.
In fact our offical releases (which are monolingual), and their sample data, should not contain already the Content Language en-gb as this creates a confusion.

"*" (All Languages) is only used as a specific tag in multilingual site where it means "Display whatever the Content Language used in Front-end".
It is ignored in a monolanguage site, as any content language. It is not a default language.

Trying to solve SmartSearch issues by the use of language tags (Content Languages) is not the solution IMHO.
Not only because it would uselessly require creating Content Langages on a monolanguage site (also btw on a multilanguage one) but also because it will not solve the issue which is the one of a content containing text in different languages.

Hope this helps.

JM

Okay so if I understand correctly there are two different ways that people are interpreting default. One is the site default in a mulitlingual site, the other is a default when there is no language defined at all, which is the fall back to en-GB. For  Search, for example, we would want to assume the language * is the site default language not English.  Other than that we don't care.  For other situations you want the en-GB value available.

Is that right?

Elin
--

You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-cms/-/SIixbNqDTSsJ.

To post to this group, send an email to joomla-...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.

shumisha

unread,
Feb 24, 2012, 4:44:07 AM2/24/12
to Joomla! CMS Development
@Christophe, thks I'm well aware of that. The topic being is discussed
is why the CMS doesn't do that upon initilization, resulting in
getDefault() not returning the site default language, but instead
always en-GB.
@Jean-Marie,

@Elin: no this is not the issue. We are not talking specifically about
multilingual sites, as Jean-Marie rightly explained (though
getDefault() has the same surprising "behavior" on multilingual sites)

@Jean-Marie: Thanks for detailed answer. I understand the refactoring
issue, and possibly B/C issues that may arise, which is why I posted
here rather than opening a tracker item.

"In a monolanguage site, its value may change only if multiple
language packs are installed and a user has set one of these as his
site default language when logged (same as in 1.5)."

So we are talking about maybe more than 50% of all the Joomla sites in
the world - ie all sites running a localized versions of Joomla (ok, I
have no hard data to back this up!)

I have looked at the JModuleHelper code and could see that because of
the last param being false, changing getDefault() behavior at this
stage would probably break things on monolingual sites. Please note
that on Multilingual sites however, JModuleHelper (and probably
JComponentHelper and more) is already broken, as if a particular
language file is missing, it will fall back on the english file
instead of the site default language.

OK, I gather from the above it is not really practical to fix
getDefault() and make it return the site default language?

If so, maybe a note in the PHPDOC should be added, saying that
getDefault() will not return the default language but instead en-GB?
wait, JLanguage is in the platform, so they won't do that as this is a
CMS issue. And I guess we can't override it in the CMS just for that
either.

So maybe this should be documented on the developer wiki, similar to:

"
Until further notice, in the CMS, JFactory::getLanguage()-
>getDefault() does not return the site default language.
A site default language should be obtained with:
$frontendsiteDefaultLanguage =
JComponentHelper::getParams('com_languages')-
>get('site');
$backendDefaultLanguage =
JComponentHelper::getParams('com_languages')-
>get('administrator');
"

Probably something to keep in mind for 3.0

Yannick

elin

unread,
Feb 25, 2012, 6:58:54 PM2/25/12
to joomla-...@googlegroups.com
No, I wasn't talking about multilingual sites specifically but actually I do think that we should have a content language on all site, but that is a separate issue. So I really should have said there are three scenarios.

JM I'm not sure what you point about Smart Search is, but when any component reads a record with a language column (which all core components have) it should know how to interpret that column. If it is a * it should know that means the default (content) language for the site. If you have a site where you have  all of your content  in French, the default language should be French and Smart Search and everything else should know that. If your French pack is missing a file, yes of course it should fall back to en-GB which should still be there. But that's what I mean about there being two different meanings of default. 

First, what language do we assume something is written in given the absence of information about the content?
Second, what do we do when there are missing language files?

I think there is some confusion here in that people are conflating language packs with site content also. You  should be able to say you have site content in Tibetan even though we don't have a Tibetan language pack. 

Elin

shumisha

unread,
Feb 26, 2012, 9:44:29 AM2/26/12
to joomla-...@googlegroups.com
Hi Elin,



First, what language do we assume something is written in given the absence of information about the content?
Second, what do we do when there are missing language files?

I think those are different issues, and maybe they need to be tackled separately, or after the first one has been solved/reached a consensus.

The first issue, the one I raised, is: how do programmers/API consumers know about the site default language - which has nothing to do with the site content, as you correctly stated. One would expect jLanguage::getDefault() should be used, but it does not return the site default language.

My point is: once we know how one is supposed to know about the site default language, then we can talk about what to do if  "content is missing language information" or "some language files are missing" - as I guess the answer to both your later questions is going to be some variation on "use site default language".

What I've done is add an helper method to my extension, similar to
  public static function getSiteDefaultLanguage( $clientId = 0) {

    static $_defaultLanguage = null;

    if(is_null( $_defaultLanguage)) {
      jimport( 'joomla.application.component.helper');
      $params =  JComponentHelper::getParams('com_languages');
      jimport( 'joomla.application.helper');
      $client    = JApplicationHelper::getClientInfo( (int)$clientId);
      $_defaultLanguage = $params->get( $client->name, 'en-GB');
    }

    return $_defaultLanguage;
  }

Maybe a variation of that can be added to JLanguage, so as not to touch the current getDefault() for fear of B/C issues.

Cheers
Yannick

Reply all
Reply to author
Forward
0 new messages