简体   繁体   English

如何使用FBJS获得用户的语言偏好?

[英]How to use FBJS to get the language preference of the user?

I'm modifying an existing FaceBook application. 我正在修改现有的FaceBook应用程序。 The FaceBook application is generated by another application, so I don't have much control over it. FaceBook应用程序是由另一个应用程序生成的,因此我对其没有太多控制。 I can only add html/javascript. 我只能添加html / javascript。

My goal is to use FBJS to detect the current language setting of the user and display a different message depending on their language. 我的目标是使用FBJS来检测用户的当前语言设置,并根据他们的语言显示不同的消息。

For example, if the user has their language setting set to Spanish, then I would like to show a message in Spanish on my FaceBook application. 例如,如果用户将其语言设置设置为西班牙语,那么我想在FaceBook应用程序中以西班牙语显示一条消息。

How can I do this? 我怎样才能做到这一点?

I don't think there's a way to do what you want with only HTML/JS changes. 我认为仅通过HTML / JS更改就无法实现所需的方法。

I think the fastest way to do this is to use AJAX in FBJS to callback to your server. 我认为最快的方法是在FBJS中使用AJAX回调到服务器。 Server-side, grab /me from the Graph API. 服务器端,从Graph API中获取/me There's a locale field that tells you the user's language setting. 有一个区域设置字段 ,可告诉您用户的语言设置。 Or do the Graph API server-side call when the page first loads and you can avoid AJAX altogether. 或在页面首次加载时执行Graph API服务器端调用,并且您可以完全避免使用AJAX。 The specifics of how you do this depend on what server-side language you're using. 具体操作方式取决于您使用的服务器端语言。

The "right" way to do this is to let the translation community translate your site for you. 实现此目的的“正确”方法是让翻译社区为您翻译您的网站。 Read this Internationalization doc for more info. 阅读此国际化文档以获取更多信息。 If you're using using FBJS it sounds like this is a FBML app so you'd use some of these internationalization FBML tags . 如果您使用的是FBJS,这听起来像是FBML应用程序,因此您将使用其中一些国际化FBML标签

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

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