Jfactory::getLanguage() do not return good language
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Jfactory::getLanguage() do not return good language
Hi all,
I have a multi-language web site and it seems that Joomla 3.2 don't return the good language in external script with this code :
<?php
// Protect from unauthorized access
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', '../');
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
// load language string definitions
$lang = JFactory::getLanguage();
$lang->load('ed3c_contrats');
echo($lang->getName()); return always GB ?
I have a multi-language web site and it seems that Joomla 3.2 don't return the good language in external script with this code :
<?php
// Protect from unauthorized access
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', '../');
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
// load language string definitions
$lang = JFactory::getLanguage();
$lang->load('ed3c_contrats');
echo($lang->getName()); return always GB ?
-
- Joomla! Enthusiast
- Posts: 130
- Joined: Sat Aug 06, 2011 3:40 am
Re: Jfactory::getLanguage() do not return good language
It is not clear what you are trying to achieve... Are you trying to load the language file 'ed3c_contrats' and it is not working properly? Or do you only want to get the language code and this is not working?
If you want the language code, try this, where every aspect of the language is elaborated
http://stackoverflow.com/questions/3352 ... la-website
In short, for the language code, you can use this
If you want the language code, try this, where every aspect of the language is elaborated
http://stackoverflow.com/questions/3352 ... la-website
In short, for the language code, you can use this
Code: Select all
$lang = JFactory::getLanguage();
$lang->getTag(); // returns 'en-GB' or 'en-US' for example
We come in peace, always!
http://www.quadrifolia.ch
http://www.quadrifolia.ch
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
Hi goedda,
In my script I would like to load he correct language file ed3c_contrats. I have one file en-GB.ed3c_contrats.ini in /languages/en-GB and this other fr-FR.ed3c_contrats.ini in /languages/fr-FR.
However it's always the en-GB file which is loaded. And the line echo(lang->getName()); return English (United Kingdom) even if I switch the site in French. By the way I noted that when the site is in English the url is http://..../en/index.php while in french I got http://..../index.php and not http://..../fr/index.php
Do you think it's normal ?
Philippe
In my script I would like to load he correct language file ed3c_contrats. I have one file en-GB.ed3c_contrats.ini in /languages/en-GB and this other fr-FR.ed3c_contrats.ini in /languages/fr-FR.
However it's always the en-GB file which is loaded. And the line echo(lang->getName()); return English (United Kingdom) even if I switch the site in French. By the way I noted that when the site is in English the url is http://..../en/index.php while in french I got http://..../index.php and not http://..../fr/index.php
Do you think it's normal ?
Philippe
-
- Joomla! Enthusiast
- Posts: 130
- Joined: Sat Aug 06, 2011 3:40 am
Re: Jfactory::getLanguage() do not return good language
It is normal for SEF-URLs since Joomla! 1.7.x or so.
http://multilingual.demojoomla.com/mult ... ml?start=8
You may try and disable SEF temporarily, check if it works then. This will cost you only a few minutes...
If that does not work, I would check, if you get a different result while being logged in frontend as administrator. This would be a hint that the language does not have a 'content'. You should be able to fix that by going backend to the 'Language Manager > Content' and create a content for the French language.
This should help doing that (just use the French code etc. instead)
[url deleted by Moderator as one has to pay to access this tutorial)
http://multilingual.demojoomla.com/mult ... ml?start=8
You may try and disable SEF temporarily, check if it works then. This will cost you only a few minutes...
If that does not work, I would check, if you get a different result while being logged in frontend as administrator. This would be a hint that the language does not have a 'content'. You should be able to fix that by going backend to the 'Language Manager > Content' and create a content for the French language.
This should help doing that (just use the French code etc. instead)
[url deleted by Moderator as one has to pay to access this tutorial)
We come in peace, always!
http://www.quadrifolia.ch
http://www.quadrifolia.ch
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
goedda wrote:It is normal for SEF-URLs since Joomla! 1.7.x or so.
http://multilingual.demojoomla.com/mult ... ml?start=8
You may try and disable SEF temporarily, check if it works then. This will cost you only a few minutes...
Disable SEF didn't work.
If that does not work, I would check, if you get a different result while being logged in frontend as administrator.
In administrator frontend same thing it's always the English page.
This would be a hint that the language does not have a 'content'. You should be able to fix that by going backend to the 'Language Manager > Content' and create a content for the French language.
This should help doing that (just use the French code etc. instead)
I have a content for both French and English languages.
[url deleted by Moderator as one has to pay to access this tutorial)
- infograf768
- Joomla! Master
- Posts: 19133
- Joined: Fri Aug 12, 2005 3:47 pm
- Location: **Translation Matters**
Re: Jfactory::getLanguage() do not return good language
Which type of extension is "ed3c_contrats"? How is it it has no extension type (com, plg, mod, tpl, lib..)?
Do you need to load that specific language file when the extension is used, or in another context?
Apart from this extension, is the multilanguage working as should, i.e. loading French or English when desired?
Please attach a screenshot of the multilanguage status module
( see http://community.joomla.org/blogs/commu ... odule.html )
Do you need to load that specific language file when the extension is used, or in another context?
Apart from this extension, is the multilanguage working as should, i.e. loading French or English when desired?
Please attach a screenshot of the multilanguage status module
( see http://community.joomla.org/blogs/commu ... odule.html )
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
ed3c_contrats.ini is not an extension it's the language file that the script load when it start.infograf768 wrote:Which type of extension is "ed3c_contrats"? How is it it has no extension type (com, plg, mod, tpl, lib..)?
Do you need to load that specific language file when the extension is used, or in another context?
The site works correctly with the two languages except when I run my own scripts. The problem is not the language files, the scripts do not recognize the selected language when the user click in the flag although all this other menus switch correctly to the language.Apart from this extension, is the multilanguage working as should, i.e. loading French or English when desired?
As I said the lines :
Jfactory::getLanguage();
echo $lang->getName();
return always English
You can have a look at this address : http://ed3c-essai.snv.jussieu.frPlease attach a screenshot of the multilanguage status module
( see http://community.joomla.org/blogs/commu ... odule.html )
On script is in the menu Contrats doctoraux -> recherche projets de thèse
- infograf768
- Joomla! Master
- Posts: 19133
- Joined: Fri Aug 12, 2005 3:47 pm
- Location: **Translation Matters**
Re: Jfactory::getLanguage() do not return good language
As we can't access to your custom script, I do not see how we can help.
http://ed3c-essai.snv.jussieu.fr/index. ... t-these-fr
(French version)
is loaded in a fr-fr document where JFactory::getLanguage would echo the correct language.
Therefore I guess your script has an error.
I suggest you enable language debug and see which precise language files are loaded as, even in English, the drop down options (Indifferente) is in French (Without the accent).
I also suggest you look better at the method in library/joomla/language/language.php
or at the method loadLanguage
To understand the way a language file is loaded.
You may have to use rather something like:
Where "dirname(__FILE__)" would be "JPATH_SITE" if your ini files are in language/en-GB/ and language/fr-FR/
http://ed3c-essai.snv.jussieu.fr/index. ... t-these-fr
(French version)
is loaded in a fr-fr document where JFactory::getLanguage would echo the correct language.
Code: Select all
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-fr" lang="fr-fr" dir="ltr" >
I suggest you enable language debug and see which precise language files are loaded as, even in English, the drop down options (Indifferente) is in French (Without the accent).
I also suggest you look better at the method in library/joomla/language/language.php
Code: Select all
public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null, $reload = false, $default = true)
To understand the way a language file is loaded.
You may have to use rather something like:
Code: Select all
$lang = JFactory::getLanguage();
$lang->load('ed3c_contrats' , dirname(__FILE__), $lang->getTag(), false, true);
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
Thanks for the information. Unfortunately the suggestion in code don't work. I have activated the langues debug and strangely the ed3c_contrats file are never loaded in the debug console.infograf768 wrote:As we can't access to your custom script, I do not see how we can help.
http://ed3c-essai.snv.jussieu.fr/index. ... t-these-fr
(French version)
is loaded in a fr-fr document where JFactory::getLanguage would echo the correct language.
Therefore I guess your script has an error.Code: Select all
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-fr" lang="fr-fr" dir="ltr" >
I suggest you enable language debug and see which precise language files are loaded as, even in English, the drop down options (Indifferente) is in French (Without the accent).
I also suggest you look better at the method in library/joomla/language/language.phpor at the method loadLanguageCode: Select all
public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null, $reload = false, $default = true)
To understand the way a language file is loaded.
You may have to use rather something like:Where "dirname(__FILE__)" would be "JPATH_SITE" if your ini files are in language/en-GB/ and language/fr-FR/Code: Select all
$lang = JFactory::getLanguage(); $lang->load('ed3c_contrats' , dirname(__FILE__), $lang->getTag(), false, true);
**Fichiers de langue chargés**
**Chargé** : JROOT/language/fr-FR/fr-FR.ini
**Chargé** : JROOT/administrator/language/fr-FR/fr-FR.plg_system_logout.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.lib_joomla.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.tpl_ed3c.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.com_wrapper.ini
**Chargé** : JROOT/administrator/language/en-GB/en-GB.com_rsform.ini
**Chargé** : JROOT/administrator/language/fr-FR/fr-FR.com_rsform.ini
**Chargé** : JROOT/administrator/language/fr-FR/fr-FR.plg_system_jcemediabox.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.mod_languages.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.mod_menu.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.mod_articles_news.ini
**Chargé** : JROOT/language/fr-FR/fr-FR.mod_breadcrumbs.ini
**Chargé** : JROOT/plugins/attachments/attachments_plugin_framework/language/fr-FR/fr-FR.plg_attachments_attachments_plugin_framework.ini
**Chargé** : JROOT/administrator/language/fr-FR/fr-FR.plg_system_debug.ini
here the code of the script :
//
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8'>
<title>Demande allocation</title>
<link rel="stylesheet" href="/templates/ed3c/css/ed3c.css" type="text/css">
<script type="text/javascript">
function showUnity(str)
{
if (str=="")
{
document.getElementById('txtHint').innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('txtHint').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/Contrats/Fiches/getunity.php?q="+str,true);
xmlhttp.send();
}
</script>
<script language="JavaScript" type="text/javascript" src="/includes/gen_validatorv4.js"></script>
</head>
<body style='background:#ffffff'>
<?php
// Protect from unauthorized access
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', '../../');
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
// load language string definitions
$lang = JFactory::getLanguage();
$lang->load('ed3c_contrats' , JPATH_SITE, $lang->getTag(), false, true);
//$lang->load('ed3c_contrats',JPATH_BASE);
.....
//
- infograf768
- Joomla! Master
- Posts: 19133
- Joined: Fri Aug 12, 2005 3:47 pm
- Location: **Translation Matters**
Re: Jfactory::getLanguage() do not return good language
What does the debug lang show when you are in en-GB?
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
Strangely the en-GB.ed3c_contrats.ini are not loadedinfograf768 wrote:What does the debug lang show when you are in en-GB?
**Parsing errors in language files**
**None**
**Language Files Loaded**
**Loaded** : JROOT/language/en-GB/en-GB.ini
**Loaded** : JROOT/administrator/language/en-GB/en-GB.plg_system_logout.ini
**Loaded** : JROOT/language/en-GB/en-GB.lib_joomla.ini
**Loaded** : JROOT/language/en-GB/en-GB.tpl_ed3c.ini
**Loaded** : JROOT/language/en-GB/en-GB.com_wrapper.ini
**Loaded** : JROOT/administrator/language/en-GB/en-GB.plg_system_jcemediabox.ini
**Loaded** : JROOT/language/en-GB/en-GB.mod_languages.ini
**Loaded** : JROOT/language/en-GB/en-GB.mod_menu.ini
**Loaded** : JROOT/language/en-GB/en-GB.mod_breadcrumbs.ini
**Loaded** : JROOT/plugins/attachments/attachments_plugin_framework/language/en-GB/en-GB.plg_attachments_attachments_plugin_framework.ini
**Loaded** : JROOT/administrator/language/en-GB/en-GB.plg_system_debug.ini
**Untranslated Strings**
**None**
- infograf768
- Joomla! Master
- Posts: 19133
- Joined: Fri Aug 12, 2005 3:47 pm
- Location: **Translation Matters**
Re: Jfactory::getLanguage() do not return good language
Your script is wrong somewhere...
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
Yes but where ?infograf768 wrote:Your script is wrong somewhere...
That I don't understood is that the translation works in English even the en-GB.ed3c_contrats.ini file is not loaded in the debug panel.
And why it didn't find the french file ?
- infograf768
- Joomla! Master
- Posts: 19133
- Joined: Fri Aug 12, 2005 3:47 pm
- Location: **Translation Matters**
Re: Jfactory::getLanguage() do not return good language
I would say first: why does it not display the English file in the debug?
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
I'm trying to bypass the Joomla language choice by forcing the language in my script reading the paramaters in the url, but it doesn't work :
// load language string definitions
$tag = $_GET['lang'];
echo ("Language: ".$_GET['lang']);
$lang = JFactory::getLanguage();
if ($tag == 'fr')
$lang->load('ed3c_contrats',JPATH_BASE,'fr-FR');
else
$lang->load('ed3c_contrats',JPATH_BASE,'en-GB');
$_GET['lang'] return an empty string. Note that I have disable the SEF in the server.
// load language string definitions
$tag = $_GET['lang'];
echo ("Language: ".$_GET['lang']);
$lang = JFactory::getLanguage();
if ($tag == 'fr')
$lang->load('ed3c_contrats',JPATH_BASE,'fr-FR');
else
$lang->load('ed3c_contrats',JPATH_BASE,'en-GB');
$_GET['lang'] return an empty string. Note that I have disable the SEF in the server.
-
- Joomla! Apprentice
- Posts: 10
- Joined: Mon May 05, 2014 9:19 am
Re: Jfactory::getLanguage() do not return good language
Hi,
Finally I found a other way (not so nice but) to get the current language. It seems that in Joomla 3 getLanguage() doesn't work from outside php scripts.
So I get the current language from the current url as :
Finally I found a other way (not so nice but) to get the current language. It seems that in Joomla 3 getLanguage() doesn't work from outside php scripts.
So I get the current language from the current url as :
Code: Select all
// load language string definitions in url
$app = JFactory::getApplication('site');
$app->initialise();
$lang = JFactory::getLanguage();
$url = getenv("HTTP_REFERER");
$choice_lg = strpos($url_lg, "/en/");
if ($choice_lg === false) $lg_tag = "fr-FR";
else $lg_tag = "en-GB";
$extension = 'ed3c_soutenance';
$base_dir = JPATH_SITE;
$lang->load($extension, $base_dir, $lg_tag, true);