Jump to content

Language Icons


ChriWolf
 Share

Recommended Posts

Good morning,

I started to create a new website. This website must be multi-language.
I want to use icons to select the language. So i created a new fiel and added this to the language Template.

But now:

1. Select default Language (here english) alle Icons are shown

2. Select german language i only get the url of the german icon

<ul class="langList DropContent" style="background-color: #<?php echo $themecolor ?>">
<?php
foreach($languages as $language) {
echo '<a hreflang="'.$homepage->getLanguageValue($language, 'name').'" href="'.$page->localHttpUrl($language).'"><li>'.$language->title.'<img src="'.$language->lang_icon->url.'" alt="'.$language->title.'" /></li></a>';
}
?>
</ul>

lang_german.JPG

lang_english.JPG

Link to comment
Share on other sites

What are its contents inside the english and german languages?

What its the url that echo $language->lang_icon->url returns?

May be something in german language its causing the english flag to not having the right path

Link to comment
Share on other sites

Thanks a lot trying to help me....

i solved the problem. I deleted the field lang_icon an created a new one with a different name. renamed the images.  and it work. don't know why, maybe pw have problems with the fieldname or the filename.

Link to comment
Share on other sites

  • 2 years later...

Yes, an old post, but if you are having the same problems as @ChriWolf

with the primary icon not showing when you swap to the 2nd language.

It seem to fail when the field is called "language_icon", but works with the field called e.g. "flag_icon"...so omit the use of the word "language" for your image field name.

 

Link to comment
Share on other sites

  • 1 month later...

Sorry...this still wasn't working correctly, but this fixed it

$thumb = $language->getUnformatted('flag_icon')->first;

<?php
foreach($languages as $language) {
if(!$page->viewable($language)) continue; // is page viewable in this language?
if($language->id == $user->language->id) {
echo "<span class='currentlang'>";
} else {
echo "<span>";
}
$url = $page->localUrl($language); 
$hreflang = $homepage->getLanguageValue($language, 'name'); 
$thumb = $language->getUnformatted('flag_icon')->first;	                            
echo "<a hreflang='$hreflang' href='$url' title='$language->title'><img src='{$thumb->url}' alt='$language->title'/></a></span>";
}
?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...