本文介绍了如何从存储在数据库中的翻译中本地化静态网站文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我需要为我的(可伸缩)Web应用程序中的静态文本设计一种翻译机制/策略 - 这些应用程序基于HTML,JQuery / JavaScript在ASP.NET环境中(但没有服务器端控件)从异步jQuery调用到http处理程序。 我已经使用 ResX 等效,如 jQuery本地化 / jQuery本地化 / jQuery-i18n-properties 方法,而是在类似于扩展资源提供者模型,它本地化ASP.NET控件(我没有),从数据库中获得翻译。 客户端方法:我只是偶然发现了 i18next的动态(非静态)资源路径,并试图解决我是否可以从http处理程序返回类似内容(并缓存在 JStorage / LawnChair )使用 jQuery功能填写占位符/标签或者采取类似的方法h 胡须或 服务器端方法:修改HTML之前的HTML它被服务,例如这个答案建议使用 HttpResponse.Filter 修改响应服务器端(参见本文)。由于缓冲区被分块,我必须按照建议捕获整个流这里,这会导致性能下降,但是,我希望我可以通过缓存每个(语言)版本的页面。 使用HTTP处理程序像这样看起来像更简单的方法,但我不太确定如何在此实例中缓存多个版本的页面。 有没有人否则有这些方法的经验,或者知道任何类似或最佳实践,以满足要求,特别是在性能,可扩展性和可维护性方面? 如果有什么不清楚的地方,请告诉我,我是网络开发新手。 :) 注意:这适用于在平板电脑/手持设备上运行的Web应用程序进行数据捕获,它不是CMS或静态网站以前的版本用于在.Net Compact Framework上运行5年左右,因此用户可以使用非Windows设备(如android和iPad)进行更新。解决方案服务器端翻译结果相当复杂。 我认为最简单的方法是使用 jQuery本地化来获取从数据库生成的语言脚本,但是这并没有增加任何价值,所以我只是使用ajax请求手动从服务器获取脚本(每种语言都有不同的生成脚本)。 我从服务器获得的脚本包含用于翻译的变量(变量与控件id相同),我将其作为一个对象数组传递 {id:'controlid',val:controlid} 应用于翻译的方法,所以当脚本被调用时,翻译页面。 这似乎并不是一个很好的最佳实践,我所做的并不复杂,但如果有一个库或插件,它会很好做了这一切。 Simlar对此答案。 I need to design a translation mechanism/strategy for the static text in my (scalable) web applications - which are based on HTML, JQuery/JavaScript in an ASP.NET environment (but no server side controls) with dynamic data loaded from asynchronous jQuery calls to http handlers.I have successfully localised numbers, dates, etc using Globalize, however now need to sort out the text translation.Translated text is stored appropriately in a database (maintained by native partners in another application), therefore, I do not want to use a file based ResX equivalent, like jQuery Localisation/jQuery Localize/jQuery-i18n-properties approaches, instead I am after a solution similar to extending the Resource-Provider Model that localises ASP.NET controls (which I don't have), to get the translation from the database.Client Side Approach: I just stumbled across i18next's dynamic (non-static) resouce route and am trying to work out if I can return something like that from a http handler (and caching in JStorage/LawnChair) to fill in place-holders/tags using the jQuery function or take a similar approach with Moustache or hogan.js templates.Server Side Approach:Modify the HTML before it is served, for example this answer suggests using the HttpResponse.Filter to modify the response server side (see this article). As the buffer is chunked, I'd have to capture the entire stream as suggested here, which does lead to a performance hit, however, I hope I can mitigate this by caching each (language) version of the page.Or use HTTP Handlers like this looks like simpler approach, though I am less sure how to cache multiple versions of the page in this instance.Does anyone else have experience with these approaches or know of anything similar or 'best practices' that meets the requirements especially in terms of performance, scalability and maintainability?If anything isn't clear, please let me know, I am new to web development. :)Note: This is for web applications running on tablets/hand-held devices for data capture, it isn't a CMS or static site (the previous incarnation used to run on the .Net Compact Framework, for about 5 years and it's time for an update so users can use non-windows devices such as android and IPad). 解决方案 Server side translation turned out to be rather convoluted. I thought the simplest approach is to use jQuery localisation to get language scripts generated from the database, however this didn't add any value, so I just get the script from the server manually using an ajax request (each language has a different generated script).The script I get from the server contains varibles for the translation (the varibles are the same name as control id), which I pass as an array of objects e.g. {id:'controlid', val:controlid} to a method that apply's the translation, so when the script is called, the page gets translated.It is a shame there doesn't seem to be a good best practice for this, what I have done isn't complex, but it would be nice if there was a library or plug in that did it all.Simlar to this answer. 这篇关于如何从存储在数据库中的翻译中本地化静态网站文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 04:28