简体   繁体   English

Web应用程序国际化,服务器端还是客户端?

[英]Web Application Internationalization, do it server-side or client-side?

We are looking to internationalize a web application. 我们希望将Web应用程序国际化。 Is it best to output translation Server-side (it is written in .net 4 C#) or Client-side (Javascript)? 是否最好输出翻译服务器端(用.net 4 C#编写)或客户端(Javascript)?

We have already begun carrying this out Client-side by creating a JS file which contains a single object containing English phrases as the Keys (so developers understand what each message means in context), with values that are the string which is shown to the client for any alerts and prompts. 我们已经开始通过创建一个JS文件来实现客户端,这个文件包含一个包含英语短语作为键的对象(因此开发人员了解每个消息在上下文中的含义),其值是显示给客户端的字符串任何警报和提示。 We are thinking of extending this to all wording throughout the front-end. 我们正考虑将其扩展到整个前端的所有措辞。

Is this a good idea or is it best to carry out this kind of work server-side? 这是一个好主意还是最好在服务器端执行这种工作?

Update: Incase it helps to sway the argument, we don't use server-side controls heavily in our web application, the majority of our controls are jQuery/JS based. 更新:包含它有助于摆脱争论,我们不会在我们的Web应用程序中大量使用服务器端控件,我们的大多数控件都是基于jQuery / JS的。

Update: This particular application is not publicly visible (apart from the login page) so SEO concerns are not applicable. 更新:此特定应用程序不公开可见(除了登录页面)因此SEO问题不适用。

SEO wise, I would recommend to do it server side and make the application available under a seperate url. SEO明智,我建议做服务器端,并使应用程序在单独的URL下可用。

for example: 例如:

www.application/en/ www.application / EN /

www.application/es/ ... www.application / es / ...

The first rule of I18n: follow the standard way. I18n的第一条规则:遵循标准方式。 Do not re-invent the wheel. 不要重新发明轮子。 In case of Asp.Net that means server-side Internationalization. 对于Asp.Net,这意味着服务器端国际化。

Well, sort of. 好吧,有点。 If you happen to have tons of dynamically created controls, you still need some Localization mechanism for client-side scripts. 如果碰巧有大量动态创建的控件,则仍需要一些客户端脚本的本地化机制。 You can centralize it, ie create one global array of translated strings and the model+controller, so you can ie populate it via AJAX call (although X would be best replaced by J for JSON...). 你可以集中它,即创建一个翻译字符串的全局数组和模型+控制器,所以你可以通过AJAX调用填充它(尽管X最好用J代替JSON ......)。
Anyway, your model should simply retrieve appropriate strings from resource files and controller should feed the JSON to the client side (good idea is to actually request smaller chunks, ie just the translation for given view/screen instead of translations for the whole application). 无论如何,你的模型应该只是从资源文件中检索适当的字符串,控制器应该将JSON提供给客户端(好主意是实际请求较小的块,即只是给定视图/屏幕的转换而不是整个应用程序的转换)。

As you can see, the best would be some mixed approach. 如你所见,最好的是一些混合方法。 For many reasons, one would be it is better to use one Localization model for the whole application, ie use only *.resx files. 由于许多原因,最好是为整个应用程序使用一个本地化模型,即仅使用* .resx文件。
Besides, there is much more to Internationalization than just plain string externalization... 此外,还有更多的不仅仅是简单的字符串外化到国际化...

If you are showing only static content to user then go by client side internationalization. 如果您只向用户显示静态内容,那么请通过客户端国际化。 and if you showing content/messages those are dynamic, you should use server-side. 如果你显示那些是动态的内容/消息,你应该使用服务器端。 but how are you detecting user locale? 但是你如何检测用户区域设置?

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

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