I am using the internationalisation block for basic page translation between Spanish and English. By default the content is in Spanish. When I change the language to English the page content is translated, however the autonav appears blank. I have used page CID's to determine the language differences. In my header.php file for my theme I am using the follow statement:
if(!$c->getAttribute('english_menus')) {
$lh = Loader::helper('section', 'multilingual');
$lang = $lh->getLanguage();
$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPages = 'custom';
if ($lang == "en_EN"){
$bt->controller->displayPagesCID = 166; //English section cID
} else {
$bt->controller->displayPagesCID = 171; //Spanish section cID
}
$bt->controller->orderBy = 'display_asc';
$bt->render('templates/top_nav/view');
}
This displays the top level navigation fine. however when the country flag is selected the auto nav menu disappears and does not display in english
Many Thanks
Do you mean to have the
if (! $c->getAttribute('english_menus')) {
at the top?
It doesn't make much sense to me. Any chance your english page (or whatever page you land on after the country flag) has that attribute set to something?
Related
I try to display a field depending on joomla language
I tried many versions like this but didnt succeded.
<?php
$lang = JFactory::getLanguage();
if($lang == 'ro-ro') {
echo 'Current language is: ' . $lang->getTag();
}
?>
I need a code for 3 languages.When is romanian to display an message when is english another message , and on french 3rd different message.
Can anyone help me please?
Thank you
My website has two languages: English and Russian. These languages' database names are EN and RU.
I use an old php+smarty script. This script's default language selection codes like this:
if(!isset($_SESSION)){
define('LANGUAGE_ID', 'EN');
} else if ($_SESSION['language'] == '')
{
define('LANGUAGE_ID', 'EN');
}
When I want to see a page in Russian, I visit any page with language phrase (?language=RU) like this:
http://www.example.com/index.php?language=RU
But these pages doesn't load in Russian firstly. When I clicked another link or refresh the page, then page loading in Russian. After saved the cookies, then I can see the pages in Russian when first visit. But If I delete the cookies in browser, then I couldn't see in Russian when first visit.
I tried lots of combinations but I couldn't find any solution. Do you have any idea?
Thank you very much...
Edit:
I found some codes in main.class.php:
function __construct($dbh,$smartyBuild) {
$this->dbh = $dbh;
$this->sitevar = #$smartyBuild->FetchSiteVar();
$this->smartybuild = #$smartyBuild;
if($_REQUEST['language'] !='')
{
$_SESSION['language'] = $_REQUEST['language'];
}
else
{
$langaugeAlready = mysql_fetch_array(mysql_query("select value from ".TABLE_PREFIX."sitevars where array_key = 'default_language_feed'"));
if($_SESSION['language'] == '')
{
$_SESSION['language'] = $langaugeAlready['value'];
}
}
if($_SESSION['language'] !='' )
{
define('LANGUAGE_ID', $_SESSION['language']);
}
else
{
define('LANGUAGE_ID', 'EN');
$_SESSION['language'] = 'EN';
}
}
Is the problem related with these codes?
Like I say, without all the code we are guessing a bit at what the problem is but, here goes...
It seems like you're only checking the $_SESSION variable for the language and not the $_GET variable (which gets the language from the URL). Therefore the value only changes after you refresh the page.
Try this. I am assuming your intention is to show English as a default and only Russian if it is defined in the url, but once defined to keep that language until it is put in the URL again.
//start a session. must be called first on all pages you want it to work on
session_start();
//first check if there's a new language coming from the URL
if(isset($_GET['language']))
{
// if we have a new language setting from the URL, check which one and save it in the session.
// we check it is EN or RO before saving into the session since I don't know what you're using it for later. eg part of a DB query which would be a security risk if it is anything other than EN or RO.
if($_GET['language'] == 'EN')
{
$_SESSION['language'] = 'EN';
}
if($_GET['language'] == 'RO')
{
$_SESSION['language'] = 'RO';
}
}
//now check the session variable, which will have been updated above if changed
if(isset($_SESSION['language']))
{
// already have a language saved, so let's use it
define('LANGUAGE_ID', $_SESSION['language']);
}
else
{
// no language from URL and no language saved, so default to english
define('LANGUAGE_ID', 'EN');
}
This question already has answers here:
Detect Browser Language in PHP
(16 answers)
Closed 8 years ago.
I'm a designer with little coding knowledge outside of html/css. Reading on the 'net I find many references to some php using http_accept_language but cannot find a step-by-step "do this, do that" explanation and consequently I don't know what to do with / where to put the code that people present for the job.
I'm developing a site with an English main home page. There, users are presented with a choice of two branches. One branch will be only in English and the other in English plus 3 Scandinavian languages. The non-English pages are pre-translated, not created on the fly by Google.
I want that after arriving at the main home, a user who opts to go into the 4-language section will be initially served a page in the language of their browser (on all pages there will be always be a menu to manually select another language, if preferred).
Is this a job for php? If so I'd be grateful for some code and help in how to use it.
You can use HTTP_ACCEPT_LANGUAGE header. Save supported languages to array and then loop the header using foreach.
$languages = array('en', 'fi', 'sv', 'no');
$header = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach($header as $lang) {
if(in_array($lang, $languages)) {
header("Location: $lang.php"); // i.e. fi.php or se.php
break;
}
}
HTTP_ACCEPT_LANGUAGE contains something like this:
Accept-Language: en-gb,en;q=0.5
As you can see, there is multiple languages, en-gb and en. That's why it's clever to loop the header. If you prefer functions, here's one:
function get_user_lang() {
$languages = array('en', 'fi', 'sv', 'no');
$header = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach($header as $lang) {
if(in_array($lang, $languages)) {
return $lang; // i.e. fi.php or se.php
break;
}
}
}
echo 'Your language is ' . get_user_lang();
Step-by-step guide:
Create new files for each language. Name them like this: "fi.php" or "se.php".
Place the first code part to very top of your home page. That file must include .php ending, so it must be php file. If you don't understand, that should be where to place it:
<?php
$languages = array('en', 'fi', 'sv', 'no');
$header = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach($header as $lang) {
if(in_array($lang, $languages)) {
header("Location: $lang.php"); // i.e. fi.php or se.php
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
contents
</body>
</html>
Navigate to your home page in your browser. If your browser's language is english, it'll redirect to "en.php", if swedish; "se.php" and so on.
You can see all language codes from this link, swedish is "sv".
If you have the INTL extension you can use Locale::acceptFromHttp().
Here's the example from the PHP documentation.
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale;
$locale will be something like "en_US". If you only want the language and not the country, use something like this:
$locale = explode('_', Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']));
echo $locale[0];
My website has two languages: French and English. The solution I chose is working but is causing me trouble. I use session in order to keep a "clean" url which is the same in English and in France.
My solution:
To choose the language, I locate the user using IP, and if it is not in France, i set
$_SESSION['language'] = "ENG"
Otherwise,
$_SESSION['language'] = "FRA"
Then I includes my file words.php which contains all the text like this:
if( $_SESSION['language'] == "ENG")
{
$word1 = "hello"
$word2 = ....
}
else
{
$word1 = "bonjour"
$word2 = ....
}
Finally on my website, I have several echo $word1;.
To change language, I have a two links (one for each language) to a webpage language.php with a get parameter that just change the session variable and redirect to the webpage:
if($_GET['l']=="1")
{
$_SESSION['language'] = "FRA";
header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}
elseif($_GET['l']=="2")
{
$_SESSION['language'] = "ENG";
header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}
My problem:
My main problem is that Google is indexing my website only in English ( guess because the IP of crawler is not in France?). In google.fr and google.com, my website is in English.
What can I do to have the website indexed in both languages?
You must use additional folders for languages. You can use example.com/fr for French content and example.com/en for English content.
You can tell this website is multilingual and multiregional to Google crawler bots. Edit this html code for your purpose.
<link rel=”alternate” href=”http://example.com/en-gb” hreflang=”en-gb” />
<link rel=”alternate” href=”http://example.com/en-us” hreflang=”en-us” />
<link rel=”alternate” href=”http://example.com/en-au” hreflang=”en-au” />
<link rel=”alternate” href=”http://example.com/” hreflang=”x-default” />
How can I display a message only on the homepage of joomla?
I am interested in displaying it on site.com and not site.com/index.php/page or anything else then site.com.
I have tested the following:
<?php $app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();
if ($menu->getActive() == $menu->getDefault($lang->getTag())) : ?>this is the homepage
<?php endif; ?>
and this
<?php $menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo "this is the homepage";
}
?>
The problem is that I can still see the message "this is the homepage" on pages like http://site.com/index.php/category/id/78-article which clearly isn't the homepage. It seems that whenever there is index.php in the link, the above code thinks it belongs to the homepage.
This has nothing to do with the 'index.php' in the link. Instead it is related to the fact that the link at http://site.com/index.php/category/id/78-article does not have a menu item associated with it. To do exactly what you are wanting, you will probably need to get a little trickier with the code and check to make sure that the actual page's information matches the homepage information:
$jinput = JFactory::getApplication()->input;
$menu = & JSite::getMenu();
$active = $menu->getActive();
$default = $menu->getDefault();
if (
$active == $default &&
$jinput->get('option') == $default->query['option'] &&
$jinput->get('view') == $default->query['view'] &&
$jinput->get('id') == $default->query['id']
) {
echo "This is the homepage";
}
I am checking the default menu items option (which component) and view and id values against those set in the input.
http://site.com/index.php/category/id/78-article This link will set the id to 78 and likely change the view and option from what it is defined as in the menu for the homepage, so the trigger will not occur.
OK, just an idea but try:
if (preg_match('/index\.php$/',$_SERVER['PHP_SELF'])) {
echo "this is the homepage";
}
You should try this.
1. Check the menu in which has been assigned "Home"(This is the homepage) from the administrator section. Copy the link shown over there.
It would be something like
index.php?option=com_somecomponent&view=someview
Now Goto your index.php in template.
Write a condition there
if(JRequest::getVar('option')=='com_something' && JRequest::getVar('view')=='someview'){ //show message }
This should do the trick for you !! But keep in mind. If you change the menu of homepage, this will have to be changed accordingly.