【问题标题】:How to set default language as 'en' in case language version is not created in sitecore如果未在 sitecore 中创建语言版本,如何将默认语言设置为“en”
【发布时间】:2015-06-12 07:17:06
【问题描述】:

在我的 sitecore 网站中,重定向有一个棘手的要求。 有一些外部重定向从 sharepoint 到 sitecore 项目再到一些外部重定向。 例如:/abc.aspx (sharepoint_URL) 到 /abc(站点核心项目)到 http://abc.ly(外部 URL)。

在 /abc (sitecore item) 我们只有英文版本的 item 而http://abc.ly 可以有多种语言版本。如果网站是用英文记录的,而不是正常工作,在其他语言中,它显示的 404 错误页面是真实的,因为版本计数是 0。

要求是如果没有其他语言版本的项目,它应该指向“en”版本,即全球。 限制是营销人员不能接受 sitecore 中项目的版本控制,我现在不想使用后备模块。我尝试的是:

Language currentLang = Sitecore.Context.Language;
                    Language LangEn= Language.Parse("en");
                    if(currentLang !=LangEn)
                    { currentLang =LangEn;
                    }
                    Item versionItem = Sitecore.Context.Database.GetItem(Context.Item.ID, currentLang);


                    if (versionItem.Versions.Count == 0){ // do something }`

请尽快提出建议

【问题讨论】:

  • 您为什么不简单地将重定向项上的字段设置为“共享”,然后它们将针对任何语言版本返回。
  • 相关重定向模板的所有字段都已在“共享”中勾选。但对我来说仍然失败。每当 (versionItem.Versions.Count == 0) 且计数为 0 时,它会发送到 404 响应页面。
  • 您发布了您的项目和模板吗?
  • 是的,检查了所有发布目标、索引和所有内容,它们工作正常

标签: redirect sitecore


【解决方案1】:

我认为您可能想研究语言后备。有一个module on the marketplace 可以帮助您做到这一点。

话虽如此,鉴于该字段是共享的,只需登录 Sitecore 并创建每种语言的版本所需的时间就会少得多。

如果这种情况经常发生,您可以创建一个命令模板,该模板将运行代码以创建所有语言的项目。这可能会为您的作者节省一些时间。

【讨论】:

  • 但他特别要求该项目的“en”版本,这就是后备模块所做的一切。奇怪的是该项目是空/无版本,因为他说该项目是用该语言创建的。
【解决方案2】:

我在这里得到了一个非常精确的解决方案 [http://www.roundedcube.com/Blog/2010/tackling-fallback-fields-and-values-in-sitecore],我只需要在配置中添加一个处理器并相应地创建一个类。它确实对我有用。

<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel" />
<processor type="YourAssemblyHere.Pipelines.HttpRequest.FallbackLanguageProcessor, YourAssemblyHere " />
<processor type="Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel" />

并将相应的类添加到您的项目中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YourAssemblyHere.Pipelines.HttpRequest
{
public class FallbackLanguageProcessor
{
public void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
{
Sitecore.Data.Items.Item contextItem = Sitecore.Context.Item;
if (contextItem == null || contextItem.Versions.Count > 0)
return;


Sitecore.Globalization.Language language = Sitecore.Context.Language;
if (Sitecore.Context.Language.Name != "en")
language = Sitecore.Globalization.Language.Parse("en");
Sitecore.Data.Database contextDatabase = Sitecore.Context.Database;
Sitecore.Context.Item = contextDatabase.GetItem(Sitecore.Context.Item.ID, language);
}
}
}

感谢您的建议,欢迎提供更多想法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-10
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多