简体   繁体   English

多语言站点中的菜单 drupal

[英]menu drupal in multilingual site

I can't see any menu in the EN version of my drupal site with the following settings in my menu :我在我的菜单中使用以下设置在我的 Drupal 站点的 EN 版本中看不到任何菜单:

环境环境

When I select french all is ok but when I select english, nothing appears (I have content in both menu indeed)当我选择法语时一切正常,但当我选择英语时,什么也没有出现(我确实在两个菜单中都有内容)

菜单的 html 区域

In the blocks section, I see the two menus disabled.在块部分,我看到两个菜单被禁用。

Thanks to help me :-)感谢帮助我:-)

I would suggest using menu block contrib module.我建议使用菜单块contrib 模块。

This module will allow you to treat your menus as blocks.该模块将允许您将菜单视为块。

Create 2 blocks (1 for each menu), and in block administration page you can specify the language for each block.创建 2 个块(每个菜单 1 个),在块管理页面中您可以为每个块指定语言。

As there are usually several ways to reach a goal with drupal here is a proposal for a work around:由于通常有几种方法可以通过 drupal 实现目标,因此这里有一个解决方案:

  • Create two menus with no language settings.创建两个没有语言设置的菜单。
  • Try to put all menu items as neutral language so they show up in both languages.尝试将所有菜单项设为中性语言,以便它们以两种语言显示。 (test that) (测试一下)
  • Assign the menus as blocks to the right region.将菜单作为块分配到右侧区域。
  • Then use the i18n module to control the language specific display at the block level instead of the menu or menu item level.然后使用i18n 模块在块级别而不是菜单或菜单项级别控制特定于语言的显示。 (Note you need the i18n_block module to do that which is part of the i18n module) (请注意,您需要 i18n_block 模块来执行 i18n 模块的一部分)
  • If you need aditional settings for the blocks see the allready mentioned menu block module.如果您需要对块进行其他设置,请参阅前面提到的菜单块模块。
  • Also make sure you check the internationalisation documentation .还要确保检查国际化文档

I find that having two menus is always easier for multilingual websites.我发现对于多语言网站来说,拥有两个菜单总是更容易。 I also prefer to use different views pages for different languages so I don't run into problems.我也更喜欢为不同的语言使用不同的视图页面,这样我就不会遇到问题。 That way I can add the path to the corresponding menu easily.这样我就可以轻松地将路径添加到相应的菜单中。 Whenever I have tried to combine multilingual views and menus I have faced numerous problems.每当我尝试组合多语言视图和菜单时,我都会遇到许多问题。

In the screenshot you included I can see you have two menus.在您包含的屏幕截图中,我可以看到您有两个菜单。

First of all, I find it easier to name and title the menus according to their language because it's easy to get confused otherwise ie Main Menu English - main_menu_en.首先,我发现根据菜单的语言命名和标题更容易,因为否则很容易混淆,即主菜单英语 - main_menu_en。

Secondly, your french menu probably works because it's printed by your theme which is configured to render the main menu links in the specific region.其次,您的法语菜单可能有效,因为它是由您的主题打印的,该主题被配置为在特定区域呈现主菜单链接。 To get your English menu to work you'll have to either:要使您的英文菜单正常工作,您必须:

a) add the required code in your theme, or a)在您的主题中添加所需的代码,或

b) remove the code for the main menu in your theme and use 2 menu blocks placed in the desired region via the block admin page. b)删除主题中主菜单的代码,并通过块管理页面使用放置在所需区域的 2 个菜单块。 In the block settings for each block you can select which language they'll be displayed for.在每个块的块设置中,您可以选择它们将显示的语言。

As the others said, you'll need: menu_block正如其他人所说,你需要: menu_block

If you need help with adding or removing the menu from your theme, please tell us which theme you are using.如果您在主题中添加或删除菜单方面需要帮助,请告诉我们您使用的是哪个主题。

There is a Seven Steps to achieve :有七个步骤可以实现:

Step 1: Enable all modules步骤 1:启用所有模块

  • Content Translation (core module)内容翻译(核心模块)
  • Locale (core module)语言环境(核心模块)
  • Internationalization国际化
  • Variable多变的

optional:可选的:

  • Language Icons语言图标
  • Translation Overview翻译概述

Step 2: Add a language第 2 步:添加语言

Go to Configuration > Regional and Language > Languages转到配置 > 区域和语言 > 语言

The default language is English, and you can use the “ Add Language ” link to add either Predefined or custom languages.默认语言为英语,您可以使用“添加语言”链接添加预定义或自定义语言。

Step 3: Detection and Selection第 3 步:检测和选择

For this tutorial I've chosen to use the “ URL Prefix” setting.对于本教程,我选择使用“ URL Prefix”设置。 This tells Drupal to use domain.com/es for Spanish and domain.com/de for German.这告诉 Drupal 对西班牙语使用 domain.com/es,对德语使用 domain.com/de。

Step 4: Enable Multilingual Support for content types步骤 4:为内容类型启用多语言支持

Either create or edit an existing Content Type and click “ Publishing Options ”.创建或编辑现有的内容类型,然后单击“发布选项”。 Here you will see the option for enabling multilingual support.在这里您将看到启用多语言支持的选项。 Select “ Enabled, with translation .选择“已启用,有翻译 This will allow you to translate a node into multiple languages.这将允许您将节点翻译成多种语言。

Step 5: Create English Content第 5 步:创建英文内容

When you create your nodes, make sure you are using the correct language, not just “ Language neutral ”.创建节点时,请确保使用正确的语言,而不仅仅是“语言中性”。 This is important because when you create the URL alias and Menu link title it will know which menu to put the link in.这很重要,因为当您创建 URL 别名和菜单链接标题时,它会知道将链接放入哪个菜单。

Once you've created your node you should see a “ translate ” tab.创建节点后,您应该会看到“翻译”选项卡。 If you click this tab you'll be able to add a translation to this node.如果单击此选项卡,您将能够向该节点添加翻译。

Note that if you have the “ Translation Overview ” module installed (I highly suggest it) you'll get a nice little window that tells you which languages you've added, which require priority, etc.请注意,如果您安装了“翻译概览”模块(我强烈建议您安装),您将看到一个漂亮的小窗口,告诉您添加了哪些语言、哪些需要优先级等。

Step 6: Created the translated content第 6 步:创建翻译的内容

When you create your translation give it a translated menu link title, but give it the same url alias as the original node.当你创建你的翻译时,给它一个翻译的菜单链接标题,但给它与原始节点相同的 url 别名。 Because you have multilingual support installed, it won't give you any errors for having the same URL alias (remember, it's putting the Spanish nodes at domain.com/es and the German nodes at domain.com/de).因为您安装了多语言支持,所以它不会因为具有相同的 URL 别名而给您任何错误(请记住,它将西班牙语节点放在 domain.com/es 上,将德语节点放在 domain.com/de 上)。

Step 7: Add support for multilingual menus第 7 步:添加对多语言菜单的支持

Go to Structure > Menus > Main Menu.转到结构 > 菜单 > 主菜单。 Edit the menu and enable the “ Translate and Localize ” option.编辑菜单并启用“翻译和本地化”选项。 This will switch your menu items depending on what language the user has selected site-wide.这将根据用户在站点范围内选择的语言切换您的菜单项。

You'll see you have both the English menu items and the Spanish items.您会看到您同时拥有英文菜单项和西班牙文菜单项。 You can order these like you wish, but know that only the Spanish links will show up when Spanish is selected as the main menu (you'll know because the URL will say domain.com/es).您可以像您希望的那样订购这些,但知道只有西班牙语链接将在选中西班牙语作为主菜单时出现(因为URL会说Domain.com/ES)。

And your final product: In front end you can see it action .你的最终产品:在前端,你可以看到它的动作。

Also you can use i18n_menu_navigation_links function.您也可以使用i18n_menu_navigation_links功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM