我正在尝试为我的网站设置本地化的 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 打开图形调试器时,即使我单击解析响应中的语言链接之一,它也只会返回英文内容。我是否缺少一些东西来显示不同的语言?