eZ Community » Forums » General » How to hide a different language from...
expandshrink

How to hide a different language from the menu?

How to hide a different language from the menu?

Thursday 31 May 2012 12:17:57 pm - 4 replies

Hi, friends!
My site has 3 languages​​. But not all content is translated.
When I switch to another language, I see the menu items of the current locale, but the menu items other locales too.
How do I hide the menu items that do not belong to the current locale?
For example:
In the menu, the main language I want to see all 7 items
and in another language, I want to see only 3 of the menu item that I have translated.
I don't want to see the menu mixed with the phrases in different languages​​.
Why are the menu items are displayed to different locales, not just the current locale?

Thursday 31 May 2012 12:36:57 pm

Provided you have separate siteaccesses per language, and your ini files are set up appropriately; compare your current ContentObjectLocale with the available languages of every object/menu item.

{def $currentlanguage = ezini('RegionalSettings', 'ContentObjectLocale', 'site.ini')}
{if $menuitem.object.available_languages|contains($currentlanguage)}
    <li class="item"><a href={$menuitem.url|ezurl()}>{$menuitem.name|wash()}</a></li>
{/if}

Modified on Thursday 31 May 2012 12:37:40 pm by Hein Haraldson Berg

Thursday 31 May 2012 12:52:06 pm

In a fetch, it is also possible to only retrieve objects in a given language, and given what you write in your post, I think that is a better solution to your problem. Had you wanted to still display untranslated objects, but do something to them visually, you would go for a solution like the one in my previous answer.

{def
    $currentlanguage = ezini('RegionalSettings', 'ContentObjectLocale', 'site.ini')
    $menuitems = fetch('content', 'list', hash(
        'parent_node_id', 2,
        'depth', 1,
        'limit', 20,
        'class_filter_type', 'include',
        'class_filter_array', array('folder', 'link'),
        'sort_by', array('priority', true()),
        'language', $currentlanguage
    ))
}

Many roads lead to Rome, it is also possible to hide untranslated objects completely from a given siteaccess – this is settings/siteaccess/en/site.ini.append.php:

[RegionalSettings]
Locale=eng-GB
ContentObjectLocale=eng-GB
ShowUntranslatedObjects=disabled
SiteLanguageList[]
SiteLanguageList[]=eng-GB 

Modified on Monday 04 June 2012 11:14:11 pm by Hein Haraldson Berg

Sunday 08 June 2014 5:46:06 pm

Quote from Hein Haraldson Berg :

Many roads lead to Rome, it is also possible to hide untranslated objects completely from a given siteaccess – this is settings/siteaccess/en/site.ini.append.php:

[RegionalSettings]
Locale=eng-GB
ContentObjectLocale=eng-GB
ShowUntranslatedObjects=disabled
SiteLanguageList[]
SiteLanguageList[]=eng-GB 

Thank You very much!
I used site.ini.append.php

Friday 14 November 2014 1:43:04 pm

Hi there,

You could also use parameter "only_translated" in your list fetch, like this.

 

{def  $menuitems = fetch('content', 'list', hash(
        'parent_node_id', 2,
        'depth', 1,
        'limit', 20,
        'class_filter_type', 'include',
        'class_filter_array', array('folder', 'link'),
        'sort_by', array('priority', true()),
        'only_translated', true(),
    ))
}

Modified on Friday 14 November 2014 1:45:13 pm by Petter Arneson

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from