我应该如何本地化现有的JavaScript Web应用程序? [英] How should I go about localising an existing JavaScript web application?

查看:51
本文介绍了我应该如何本地化现有的JavaScript Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常棘手的任务:有一个现有的Web项目(2个HTML文件,一些插件和一个主要的JavaScript文件,大约有2000行代码),我现在必须进行本地化。毫无疑问,这应该早点考虑过,但他们只是错过了它。您将如何找到解决方案?

I have a really tricky task to do: there is an existing web project (2 HTML files, a few plugins, and one main JavaScript file with about 2000 lines of code) which I now have to localize. No question, this should have been considered earlier, but they just missed it. How would you go to find a solution for that?

有一些元素只有几个文本元素,这些元素在最初加载页面时存在。但是还有很多DOM元素和错误警报可以动态地附加和移除(使用jQuery)。

There are a few elements with just a few text elements which are exist when the page is initially loaded. But there are also a lot of DOM elements and error alerts which are dynamically appended and removed (using jQuery) on the fly.

我想我会有文字资源(哪种文件?)在服务器上具有唯一的名称/数字(即.NET / C#)。在加载网页时,我可以检测用户代理的语言,然后将其发送到服务器,以便它准备正确的资源。然后我应该有一个类似 getText(uniqueName)的方法,它通过AJAX从服务器请求正确的文本。但这会产生大量的AJAX请求。

I think I’m going to have text resources (which kind of files?) with unique names/numbers on the server (which is .NET/C#). While loading the webpage, I could detect the user-agent’s language and then send that to the server so that "it" prepares the right resources. And then I should have a method like getText(uniqueName) which requests the right text via AJAX from the server. But this would produce a whole lot of AJAX requests.

我只有一些想法,但根本没有什么真实。

I’ve only got a few thoughts, but nothing "real" at all yet.

你能帮忙解决一下想法吗?服务器必须处理什么,脚本将处理什么以及如何处理?

Could you please help around with ideas? What will the server have to handle, what will the script handle, and how?

Thx。

推荐答案

我使用单独的 .js 文件,例如 strings-en.js 。我根据用户数据库中的设置动态加载 .js 文件。

I use separate .js files like strings-en.js. I load the .js file dynamically based on settings in my user DB.

演示: http://jsfiddle.net/ ThinkingStiff / uUTkN /

strings-en.js:

strings-en.js:

var STRINGS = {

    "userLabel": "username",
    "userPlaceholder": "enter username..."

    //...

};

HTML:

<script src="strings-en.js"></script>

<label id="user-label" for="user"></label>
<input id="user" />

CSS:

#user-label::after
{
content: ":";  
}

脚本:

document.getElementById( 'user-label' ).textContent = STRINGS.userLabel;
document.getElementById( 'user' ).setAttribute( 'placeholder', STRINGS.userPlaceholder );

输出:

这篇关于我应该如何本地化现有的JavaScript Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆