我正在尝试为我的网站设置本地化的og元标记,因此当用户共享时,它将以en-US(默认)或fr-CA显示。我在我的视图中构建了元标记,如:
@if (Model.Culture.ToLower() == "fr-ca" || Model.ShowFrenchOgTags)
{
<meta property="fb:app_id" content="APPID" />
<meta property="og:site_name" content="SITENAME" />
<meta property="og:locale" content="fr_CA" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_CA" />
<meta property="og:title" content="French Title" />
<meta property="og:description" content="French Description" />
<meta property="og:url" content="http://url" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://urltoimage.jpg" />
<meta property = "og:image:secure_url" content = "https://urltoimage.jpg" />
}
else
{
<meta property="fb:app_id" content="APPID" />
<meta property="og:site_name" content="SITENAME" />
<meta property="og:locale" content="en_US" />
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_CA" />
<meta property="og:title" content="English Title" />
<meta property="og:description" content="English Description" />
<meta property="og:url" content="http://url" />
<meta property="og:type" content="website" />
<meta property="og:image" content="http://urltoimage.jpg" />
<meta property="og:image:secure_url" content="https://urltoimage.jpg" />
}
我在我的控制器中设置了Model.Culture和Model.ShowFrenchOgTags的属性,如:
public ActionResult FacebookShare()
{
var model = new DevViewModel();
model.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
if ((Request.QueryString["fb_locale"] != null && Request.QueryString["fb_locale"].ToLower() == "fr_ca")
|| (Request.QueryString["locale"] != null && Request.QueryString["locale"].ToLower() == "fr_ca")
|| (Request.Headers["X-Facebook-Locale"] != null && Request.Headers["X-Facebook-Locale"].ToLower().Trim() == "fr_ca"))
{
model.ShowFrenchOgTags = true;
}
return View(model);
}
由于某些原因,当我使用facebook开放图调试器时,它只返回英文内容,即使我点击解析后的响应中的一个语言链接。是否有一些我想要显示不同语言的东西?