经典 ASP 的多语言支持
我的一位客户今天早上打电话给我,要求我改造一个网站以提供多语言支持。该站点是一个经典的 ASP 应用程序,并且客户端没有意愿/预算将其重写为 ASP.NET(或其他任何内容......)。
我们讨论了这样做的困难,但大部分文本恰好是从数据库读取的短字符串,他会很高兴能够翻译这些文本。
如果这不是经典 ASP,我会使用基于 GNU gettext() 的解决方案。然而,我还没有找到经典 ASP 的等价物。
我可以在他的数据库中添加一个表来存储字符串翻译,然后只需查询它,但这也意味着创建一个管理界面,以便他可以编辑字符串(而不仅仅是编辑纯文本文件)。
我还可以创建自己的平面文件解决方案,可能基于 Scripting.Dictionary,但我真的不想在这里推出自己的解决方案。
这里有替代解决方案吗?谢谢。
I have a client who called me this morning to retrofit a site for multilingual support. The site is a Classic ASP application, and the client has no desire/budget to rewrite is as ASP.NET (or anything else...).
We talked about the difficulties with this, but much of the text happens to be short strings that are read from a database and he would be happy with just being able to translate this text.
If this were not Classic ASP, I would use a GNU gettext() based solution. However, I have not been able to find an equivalent for Classic ASP.
I could add a table to his database to store the string translations, and then just query this, but it would also mean making an admin interface so he can edit the strings (rather than just editing a plain text file).
I could also create my own flatfile solution, likely based around Scripting.Dictionary, but I would really prefer not to roll my own here.
Are there any alternates solutions here? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们使用基于 XML 的解决方案,我们的 XML 文件具有以下结构:
我们选择让每个目录都有自己的 XML 文件,但如果您的站点中没有太多翻译,则可以在根目录中包含一个大的 XML。但这会影响你的表现。
我们编写了一个 WSC 来处理翻译,因此我们可以在每个 ASP 页面的顶部打开一个翻译 WSC,并使用如下方法进行翻译:
在每个页面的开头:
在 HTML 中:
在页面的末尾:
对性能的影响很小;只需确保在您的函数中获取翻译、退出循环并在找到相应的 XML 节点后立即返回值。我们一开始就犯了这个错误,导致我们调用 Translate.label() 时处理了完整的 XML 文件。
我的解决方案可能意味着您必须了解如何在 ASP 中使用 WSC,但是一旦您开始使用它们,您就再也不想回去了。它完全解决了 ASp 中意大利面条式代码的问题,并实现了关注点分离和代码重用。
哈特哈,
埃里克
希望这有帮助
We use an XML based solution, we have XML files with the following structure:
We chose to have every directory to have its own XML file, but if there aren't many translations in your site you could have one big XML in the root. This will impact your performance though.
We wrote a WSC to handle translations so we can just open a translation WSC at the top of each ASP page, and use a method to translate like so:
At the start of each page:
In the HTML:
At the end of the page:
The impact on performance is minimal; just make sure that in your function to fetch a translation, to exit the loop and return the value as soon as you find the corresponding XML node. We made this mistake in the beginning, resulting in the complete XML file being processed when we called Translate.label().
My solution probably means you'll have to find out about using WSC's in ASP, but once you start using them, you'll never want to go back. It completely solves spaghetti code in ASp and enables separation of concerns and code re-use.
HTH,
Erik
Hope this helps
也许类似于 babelfish
http://babelfish.yahoo.com/free_trans_service
perhaps something like babelfish
http://babelfish.yahoo.com/free_trans_service