经典 ASP 的多语言支持

发布于 2024-12-08 11:17:31 字数 419 浏览 0 评论 0原文

我的一位客户今天早上打电话给我,要求我改造一个网站以提供多语言支持。该站点是一个经典的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海似她心 2024-12-15 11:17:31

我们使用基于 XML 的解决方案,我们的 XML 文件具有以下结构:

<?xml version="1.0" encoding="Windows-1252"?>
<resource>
    <language LCID="1043" name="nederlands">
        <label id="pageheader"><![CDATA[Over deze applicatie]]></label>
        <label id="warning"><![CDATA[]]></label>
    </language>
    <language LCID="2067" name="vlaams">
        <label id="pageheader">Over deze applicatie</label>
        <label id="warning"><![CDATA[]]></label>
    </language>
    <language LCID="2057" name="english (uk)">
        <label id="pageheader"><![CDATA[About this software]]></label>
        <label id="warning"><![CDATA[]]></label>
        <label id=""><![CDATA[]]></label>
    </language>
</resource>

我们选择让每个目录都有自己的 XML 文件,但如果您的站点中没有太多翻译,则可以在根目录中包含一个大的 XML。但这会影响你的表现。
我们编写了一个 WSC 来处理翻译,因此我们可以在每个 ASP 页面的顶部打开一个翻译 WSC,并使用如下方法进行翻译:

在每个页面的开头:

dim translate
set translate = GetObject("script:"&Server.MapPath("/~components/DLL/Translation.wsc"))
call translate.OpenWithLCID(session.LCID)

在 HTML 中:

<%= translate.label("systemerror") %>

在页面的末尾:

call translate.close()
set translate = nothing

对性能的影响很小;只需确保在您的函数中获取翻译、退出循环并在找到相应的 XML 节点后立即返回值。我们一开始就犯了这个错误,导致我们调用 Translate.label() 时处理了完整的 XML 文件。

我的解决方案可能意味着您必须了解如何在 ASP 中使用 WSC,但是一旦您开始使用它们,您就再也不想回去了。它完全解决了 ASp 中意大利面条式代码的问题,并实现了关注点分离和代码重用。

哈特哈,
埃里克
希望这有帮助

We use an XML based solution, we have XML files with the following structure:

<?xml version="1.0" encoding="Windows-1252"?>
<resource>
    <language LCID="1043" name="nederlands">
        <label id="pageheader"><![CDATA[Over deze applicatie]]></label>
        <label id="warning"><![CDATA[]]></label>
    </language>
    <language LCID="2067" name="vlaams">
        <label id="pageheader">Over deze applicatie</label>
        <label id="warning"><![CDATA[]]></label>
    </language>
    <language LCID="2057" name="english (uk)">
        <label id="pageheader"><![CDATA[About this software]]></label>
        <label id="warning"><![CDATA[]]></label>
        <label id=""><![CDATA[]]></label>
    </language>
</resource>

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:

dim translate
set translate = GetObject("script:"&Server.MapPath("/~components/DLL/Translation.wsc"))
call translate.OpenWithLCID(session.LCID)

In the HTML:

<%= translate.label("systemerror") %>

At the end of the page:

call translate.close()
set translate = nothing

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文