Code L10N (Localization) By JavaScript
Desc This is a very useful script based on JavaScript and XML. You can use
it to the localization of the webpage.
Author Hpyer <hpyer@yahoo.cn>
Home http://www.hpyer.cn/codes/l10n-by-javascript
License GNU GENERAL PUBLIC LICENSE (GPL) <See License.txt>
History <See History.txt>
[USAGE]
1. Include the script.
<script src="l10n.js" language="JavaScript" type="text/javascript"></script>
2. Load language file (XML file).
<script type="text/javascript">
L10N.dir = 'languages';
L10N.language = 'zh_CN';
L10N.load();
</script>
3. Translate. There are two ways to do this.
Translate directly
<script type="text/javascript">
document.write(L10N.__('Words need to be translated.'));
</script>
Translate indirectly
First define a sentence need to be translated with HTML tag span.
<span domain="l10n">Words need to be translated.</span>
And then call function T_
<script type="text/javascript">
L10N.T_('l10n'); // Same to the domain attribute of span
</script>
4. A simple example
<html>
<head>
<title>A simple example</title>
<script src="l10n.js" language="JavaScript" type="text/javascript"></script>
<script type="text/javascript">
L10N.dir = 'languages';
L10N.language = 'zh_CN';
L10N.load();
</script>
</head>
<body>
<script type="text/javascript">
// Translate directly
document.write(L10N.__(*Words you want to translate.*));
</script>
<!每 Translate indirectly 每>
<span domain=§l10n§>Words you want to translate.</span>
<script type=§text/javascript§>
L10N.T_(*l10n*);
</script>
</body>
</html>
[ATTENTION]
If you want to translate the sentence before the webpage finish loading, you
must load language file before transfering, such as between <head> and </head>.
L10N By JavaScript
需积分: 10 183 浏览量
2008-04-15
20:48:40
上传
评论
收藏 34KB ZIP 举报
coolhpy
- 粉丝: 0
- 资源: 3
最新资源
- 奥迪A8D4仪表开机报文
- apache-skywalking-java-agent 8.8.0-9.2.0,一共12个版本
- DTS7001-VB一款SOT23封装P-Channel场效应MOS管
- ZTE-C300 OLT常用命令
- 6666666666666666
- DTS6410-VB一款SOT23封装N-Channel场效应MOS管
- SpyGlass-PowerVerifyMethodology-GuideWare2.0-UserGuide
- DTS6401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于树莓派、OpenCV及Python语言的人脸识别-i
- 游戏开发 UE蓝图 分支(Branch)节点和源码.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈