how to get the default frontend language?

Joomla! Documentation Workgroup

Moderator: Documentation

Locked
User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

how to get the default frontend language?

Post by carsten888 » Thu Jan 24, 2008 3:07 pm

in the old days of Joomla 1.0.x we had this:

Code: Select all

$mosConfig_lang = 'dutch';
in configuration.php
but in Joomla 1.5 its not in the config, not in the languages xml-files... Where to get the default language?

(its such a shame all languages are now in .ini-files which one can't open, so we developers don't know which language-stuff we can use.)
Last edited by carsten888 on Thu Jan 24, 2008 3:35 pm, edited 1 time in total.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: how to get the default frontend language?

Post by Chris Davenport » Thu Jan 24, 2008 3:22 pm

Code: Select all

$this->language
will get you the ISO language code.

Why can't you read language ini files?

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: how to get the default frontend language?

Post by carsten888 » Thu Jan 24, 2008 3:35 pm

sorry, tried opening them in dreamweaver, which won't work. notepad works.  :-[

thanks.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: how to get the default frontend language?

Post by carsten888 » Thu Jan 24, 2008 3:43 pm

emme...

had no luck with the language.

Code: Select all

$mosConfig_lang
in joomla 1.5 still gives 'english' back.

I'm probably missing something completely, can't get

Code: Select all

$this->language
to return anything.
I did global $mainframe;
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: how to get the default frontend language?

Post by CirTap » Thu Jan 24, 2008 6:50 pm

Hi,

Try

Code: Select all

$config =& JFactory::getConfig();
$config->getValue('config.language');
for the current user's language:

Code: Select all

$user =& JFactory::getUser();
$user->getParam('admin_language'); // Back-end language
$user->getParam('language'); // Front-end language
anything starting with $mos is deprecated and it's availablity depends on the Legacy plugin being enabled.
$this refers to different objects depending on the context you call it; it's not related to $mainframe which is the Application object.
carsten888 wrote: emme...

had no luck with the language.

Code: Select all

$mosConfig_lang
in joomla 1.5 still gives 'english' back.

I'm probably missing something completely, can't get

Code: Select all

$this->language
to return anything.
I did global $mainframe;
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: how to get the default frontend language?

Post by CirTap » Thu Jan 24, 2008 6:59 pm

carsten888 wrote: sorry, tried opening them in dreamweaver, which won't work. notepad works.
no idea which version of Dreamweaver you use but MX/2004 works fine, so I suppose newer versions work as well.
It just doesn't display .ini files in the file open dialog by default. I presume you have Unicode fonts installed. Some "fixed width" fonts only come with the basic set. Try another font.

CirTap
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
dex
Joomla! Explorer
Joomla! Explorer
Posts: 337
Joined: Tue Oct 18, 2005 9:44 pm
Location: Sydney - Australia
Contact:

Re: how to get the default frontend language?

Post by dex » Thu Jan 24, 2008 8:30 pm

In Dreamweaver, add .ini to the list of file types that Dreamweaver will open: Go to Edit > Preferences > File Types / Editors and add .ini to the first line 'Open in Code View'.
Dex
Joomla implementor
http://www.spikesystems.com.au
http://www.joomla.org.au - Aussie Joomla user groups & events

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: how to get the default frontend language?

Post by carsten888 » Fri Jan 25, 2008 7:05 am

@cirtap
dreamweaver 8

anything starting with $mos is deprecated and it's availablity depends on the Legacy plugin being enabled.
I know, but if you want to make components backwards compatible you need to use de Legacy plugin. Else I would have to work with 2 versions and I will try to avoid that dreaded senario as long as I can.



@dex
thank youy very much, that was precisely what was needed.


@everybody

this code works:
$config =& JFactory::getConfig();
$config->getValue('config.language');
thowever it returns "en-GB".

the old code:

Code: Select all

$mosConfig_lang
returns "english"

I want to use this to refer to the apropriate frontend language-file for a component.If I name the dir "en-GB" it will work for 1.5, "english " will only work for 1.0.x. I think the wise thing would be to name such a dir "en-GB" and hope they don't change this again in Joomla 2.0.
But then to make it work in Joomla 1.0.x I would have to 'translate' the language-codes. like:

Code: Select all

if($language=='english'){//this for EVERY language? 
$language = 'en-GB';
}
include($path.'/language/'.$language.'.php');
Do you see my point? 'translating' the language var like this for every language is madness. So maybe there is a way to get $config =& JFactory::getConfig();
$config->getValue('config.language'); to return the language in another format like 'english".

Other developers must have this same problem, but I can't find any solution in any of the Joomla 1.5-ready components I dowloaded so far.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: how to get the default frontend language?

Post by CirTap » Fri Jan 25, 2008 12:40 pm

Hi,

afaik all language names used in file paths are in english, their "labels" however may be translated into the native language, ie. in the Language Manager you may *see* things like "Deutsch", "Česky", or "Română" while their pathnames (1.0) remain "german", "czech" , "romanian".
The JLanguage object in 1.5 actually gives you the "old" name used in 1.0 from its XML file
  romanian
and if the Legacy plugin is installed the $mos variable will be based on that value.

To gather information of the current language in 1.5 use
$lang = &JFactory::getLanguage();

You may want to consult this documentation: http://api.joomla.org/li_Joomla-Framework.html

Have fun,
CirTap
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: how to get the default frontend language?

Post by carsten888 » Fri Jan 25, 2008 3:57 pm

@cirtap
I did not actually translate the language names, but converse from "en-GB" to "english". (sorry, no native speaker)

Code: Select all

$lang = &JFactory::getLanguage();
returns
Catchable fatal error: Object of class JLanguage could not be converted to string in C:\Documents and Settings\

Thanks for the link. I have in past months spent hours on that whole developer-area, but find it hard to work with. The way syntax of functions is explaned on php.net makes perfect sense to me, but this api-stuff I just can't find what I'm looking for most of the times. There's no search functionality. I don't mean to be dissing this, it's just very frustrating.

thanks for reply
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: how to get the default frontend language?

Post by Chris Davenport » Fri Jan 25, 2008 4:13 pm

I find the best way to search api.joomla.org is to use Google.  Enter your search term, add "site:api.joomla.org" and enjoy.  :)

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: how to get the default frontend language?

Post by CirTap » Fri Jan 25, 2008 4:52 pm

@carsten: I agree with the "lacking" search features; that's due to the simple fact that the API site is buit from static .html pages and not with J! or anything that'd provide the search.
carsten888 wrote: The way syntax of functions is explaned on php.net makes perfect sense to me, but this api-stuff I just can't find what I'm looking for most of the times.
we're working on that :-)
Chris Davenport wrote: Enter your search term, add "site:api.joomla.org" and enjoy.  :)
how 'bout adding a "Searchthis site with Google" form prominently placed on top of each API page -- or it's frontpage? I confess that despite I know this feature from google, I barely use it myself :-)

Have fun,
CirTap
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
Chris Davenport
Joomla! Ace
Joomla! Ace
Posts: 1370
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: how to get the default frontend language?

Post by Chris Davenport » Fri Jan 25, 2008 5:02 pm

CirTap wrote: how 'bout adding a "Searchthis site with Google" form prominently placed on top of each API page -- or it's frontpage? I confess that despite I know this feature from google, I barely use it myself :-)
Yeah, I had that working some months ago.  However, I had a problem with CSS in Internet Explorer that made the site almost unusable in that browser.  I confess I haven't had the time to get back to it and get it fixed.

Regards,
Chris.
Chris Davenport

Davenport Technology Services http://www.davenporttechnology.com/
Lion Coppice http://www.lioncoppice.org/

User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: how to get the default frontend language?

Post by carsten888 » Sat Jan 26, 2008 6:50 am

@chris
ok will devinately try the search by google option (why didn't I think of that myself!).

thanks all
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

User avatar
DarkBlaze
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Mon Jan 26, 2009 9:04 am
Contact:

Re: how to get the default frontend language?

Post by DarkBlaze » Thu May 29, 2014 11:45 am

I know the post is very old, but since I haven't found an answer - i went up digging...
The soultion is actually verry simple...

$frontLangTag = JComponentHelper::getParams('com_languages')->get('site','en-GB');
$backLangTag = JComponentHelper::getParams('com_languages')->get('administrator','en-GB');

Hope it helps some1, this was tested on J3.3, it should work just the same for all 1.5+ versions

tkuschel
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Wed May 30, 2012 2:22 pm
Location: Wien, Austria
Contact:

Re: how to get the default frontend language?

Post by tkuschel » Fri Jul 10, 2015 10:16 am

I often stumble over the language settings and presets. I'm using a multilingual site with languages:
  • * en-US set as default on backend,
    * en-GB is unpublished but still installed,
    * de-DE is installed and default frontend,
    * fr-FR is installed.
So I want to share my overview:

Code: Select all

		$lang = new stdClass();
		$lang->current_language = JFactory::getConfig()->get('language');  //OR:
		$lang->current_language2 = JFactory::getLanguage()->getTag();
		$lang->default_frontend_language = JComponentHelper::getParams('com_languages')->get('site','en-GB');
		$lang->default_backend_language = JComponentHelper::getParams('com_languages')->get('administrator','en-GB');
		$lang->default_Joomla_language = JFactory::getLanguage()->getDefault();
		$lang->user_backend_language = JFactory::getUser()->getParam('admin_language');
		$lang->user_frontend_language  = JFactory::getUser()->getParam('language');
		$lang->current_language_name = JFactory::getLanguage()->getName();
		$lang->current_language_tag = JFactory::getLanguage()->getTag();
		$lang->current_language_path = JFactory::getLanguage()->getLanguagePath();
		$lang->known_languages = JFactory::getLanguage()->getKnownLanguages();
		$lang->get_languages = JLanguageHelper::getLanguages('lang_code');
		$lang->current_language_sef = $lang->get_languages[$lang->current_language_tag]->sef;
		$lang->current_language_native = $lang->get_languages[$lang->current_language_tag]->title_native;
		var_dump ($lang);
My result on the frontend (switched to language French):

Code: Select all

object(stdClass)[2861]
  public 'current_language' => string 'fr-FR' (length=5)
  public 'current_language2' => string 'fr-FR' (length=5)
  public 'default_frontend_language' => string 'de-DE' (length=5)
  public 'default_backend_language' => string 'en-US' (length=5)
  public 'default_Joomla_language' => string 'en-GB' (length=5)
  public 'user_backend_language' => null
  public 'user_frontend_language' => null
  public 'current_language_name' => string 'French (fr-FR)' (length=14)
  public 'current_language_tag' => string 'fr-FR' (length=5)
  public 'current_language_path' => string '/workspace/joomla/j3/language' (length=43)
  public 'known_languages' => 
    array (size=100)
      'en-US' => 
        array (size=100)
          'name' => string 'English (USA)' (length=13)
          'tag' => string 'en-US' (length=5)
          'rtl' => string '0' (length=1)
          'locale' => string 'en_US.utf8, en_US.UTF-8, en_US, eng_US, en, english, english-us, us, usa, american, america, american, us, america, america' (length=123)
          'firstDay' => string '1' (length=1)
      'en-GB' => 
        array (size=100)
          'name' => string 'English (en-GB)' (length=15)
          'tag' => string 'en-GB' (length=5)
          'rtl' => string '0' (length=1)
          'locale' => string 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england, great britain, uk, united kingdom, united-kingdom' (length=141)
          'firstDay' => string '0' (length=1)
          'weekEnd' => string '0,6' (length=3)
      'de-DE' => 
[..]
  public 'get_languages' => 
    array (size=100)
      'de-DE' => 
        object(stdClass)[96]
          public 'lang_id' => string '4' (length=1)
          public 'lang_code' => string 'de-DE' (length=5)
          public 'title' => string 'German (Germany-Switzerland-Austria)' (length=36)
          public 'title_native' => string 'Deutsch' (length=7)
          public 'sef' => string 'de' (length=2)
          public 'image' => string 'de_de' (length=5)
          public 'description' => string '' (length=0)
          public 'metakey' => string '' (length=0)
          public 'metadesc' => string '' (length=0)
          public 'sitename' => string '' (length=0)
          public 'published' => string '1' (length=1)
          public 'access' => string '1' (length=1)
          public 'ordering' => string '1' (length=1)
          public 'link' => string '/' (length=1)
      'en-US' => 
        object(stdClass)[95]
          public 'lang_id' => string '2' (length=1)
[..]
  public 'current_language_sef' => string 'fr' (length=2)
  public 'current_language_native' => string 'Français' (length=9)
Important remarks:
As you can see, the JFactory::getLanguage()->getKnownLanguages(); returns all installed languages, also the disabled en-GB! On the other hand, the JLanguageHelper::getLanguages('lang_code'); returns only published languages.
The 'user_backend_language' and 'user_frontend_language' is Null, because the user hasn't set any language or the user is not logged-in.
With JFactory::getLanguage()->getDefault(); you only get the default language of Joomla! (always set to 'en-GB')!!


Locked

Return to “docs.joomla.org - Feedback/Information”