开发者

Multilingual Support for Classic ASP

I have a client who called me this morning to retrofit a site for multilingual support. The site is a Classic ASP applica开发者_JS百科tion, 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.


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


perhaps something like babelfish

http://babelfish.yahoo.com/free_trans_service

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜