i18next: A Solution for Front End i18n Message
Purpose
This document is used to introduce a solution which can
support below features:
Ø
Support displaying i18n message in javascript
Ø
Support displaying message with parameters
Ø
Support display text for HTML elements
Ø
Support resource path custmization
Requirments
Jquery, i18next
, JSON, IE Browser
Implementation
Initiation
When we are trying to use the any message in the jsp or
javascript, we should make sure the javascript files which are needed should be
included in the jsp file:
<script src="./js/jquery.js"
type="text/javascript"></script>
<script
src="./js/i18next.js
"
type="text/javascript"></script>
<script src="./js/sample.js"
type="text/javascript"></script>
Take above sniplet as exame, if sample.js
is our customized javascript, we should make sure all the
initiation work should be included in $(document).ready() of this file:
$(document).ready(function(){
$.i18n.init(
{
lng:
'en',
ns:
'message',
resGetPath:
'resource/locales/__lng__/__ns__.json'
},
function()
{
//
save to use translation function as resources are fetched
$(".menu").i18n();
$(".translation").i18n();
$("#userName").i18n();
}
);
});
$.i18n.init()
is
the init method for i18next,
the
meanings of the variables used in this method is listed as following:
lng
: The locale
code for the browser, it can be mannually set, if it is not set manually, it
will use defalut value: dev.
ns
: name space,
name space means the prefix name of message file which will be loaded
resGetPath
: the
resource files path, in this case, the variable: __lng__ and __ns__ are used,
lng is en, ns is message, so the message file: 'resource/locales/en/message.json'
will be loaded.
$(".translation").i18n();
$("#userName").i18n();
These two lines means loading required properties in the
loaded message file.
If messages will be used in a container with the class name the same as the name in JSON
file,
It should be like: $(".translation").i18n();
If message will be used in a single element with the id the same as the name in JSON file
,
It should be like: $("#userName").i18n();
Display text for HTML elements
·
Display
text within a container with class attribute
Like privously mentioned, this container should have a class
attribute whose name should be the same
as the name in JSON file
.
e.g:
menu
is defined
in JSON file:
"menu": {
"firstName": "First Name:",
"familyName": "Family Name:"
},
When we use menu.firstName
and menu.familyName
, we shuld make sure menu
is a class name
of
the required container, the elements with in this container can use these two properties
by adding an extra attribute:
data-i18n
<table width="100%" border="0"
id="menu1" class="menu
">
<tr id="firstName">
<td
width="50%" data-i18n="menu.firstName
"></td>
<td
width="50%"><INPUT TYPE="text"
id="userFirstName" data-i18n
="[value]userFirstName"></td>
</tr>
<tr
id="familyName">
<td
width="50%" data-i18n="menu.familyName
"></td>
<td
width="50%"><INPUT TYPE="text"
id="userFamilyName" data-i18n
="[value]userFamilyName"></td>
</tr>
</table>
·
Display
text for an element with id attribute
The properties in JSON file should be defined as below:
"userFirstName":
"Ivar",
"userFamilyName": "Chen",
When we use userFirstName
and userFamilyName
, we shuld make sure userFirstName or userFamilyName
is the id of this element, then add
an extra attribute:
data-i18n
<INPUT TYPE="text" id="userFirstName
" data-i18n
="[value]userFirstName">
<INPUT TYPE="text" id="userFamilyName
" data-i18n
="[value]userFamilyName">
The value for added an extra attribute:
data-i18n
should be like: "[value]userFirstName”
[value]
means the
attribute of this element,
userFirstName
means
the key of used property.
Display i18n message with parameters in javascript
Firstly we need to define the properties in JSON files:
"messages":
{
"hello": "Hello,
__name__"
}
"hello": is
the key
"Hello, __name__
"
is the value
, __name__
is the parameter
,
multiple
paraters are supported.
In javascript, we can simply use method $.i18n.t()
to get the message:
$.i18n.t("messages.hello", { name: $("#userFirstName").val() + " " +
$("#userFamilyName").val() }
)
The second paramter should be written as this format: {param1: param1value, param2:param2value}
Resource path custmization
set resGetPath
in
$.i18n.init()
while initiation
分享到:
相关推荐
message called an RFNM (Request for Next Message). This arrangement limits the congestion one HOST can cause another if the sending HOST is attempting to send too much over one link. We note, ...
漫画作品与时间旅行题材
Spring Boot特点: 1、创建一个单独的Spring应用程序; 2、嵌入式Tomcat,无需部署WAR文件; 3、简化Maven配置; 4、自动配置Spring; 5、提供生产就绪功能,如指标,健康检查和外部配置; 6、绝对没有代码生成和XML的配置要求;第一章 绪 论 1 1.1背景及意义 1 1.2国内外研究概况 2 1.3 研究的内容 2 第二章 关键技术的研究 3 2.1 相关技术 3 2.2 Java技术 3 2.3 ECLIPSE 开发环境 4 2.4 Tomcat介绍 4 2.5 Spring Boot框架 5 第三章 系统分析 5 3.1 系统设计目标 6 3.2 系统可行性分析 6 3.3 系统功能分析和描述 7 3.4系统UML用例分析 8 3.4.1管理员用例 9 3.4.2用户用例 9 3.5系统流程分析 10 3.5.1添加信息流程 11 3.5.2操作流程 12 3.5.3删除信息流程 13 第四章 系统设计 14 4.1 系统体系结构 15 4.2 数据库设计原则 16 4.3 数据表 17 第五章 系统实现 18 5.1用户功能模块 18 5.2
内容概要:本文作为PyTorch的入门指南,首先介绍了PyTorch相较于TensorFlow的优势——动态计算图、自动微分和丰富API。接着讲解了环境搭建、PyTorch核心组件如张量(Tensor)、autograd模块以及神经网络的定义方式(如nn.Module),并且给出了详细的神经网络训练流程,包括前向传播、计算损失值、进行反向传播以计算梯度,最终调整权重参数。此外还简要提及了一些拓展资源以便进一步探索这个深度学习工具。 适用人群:初次接触深度学习技术的新学者和技术爱好者,有一定程序基础并希望通过PyTorch深入理解机器学习算法实现的人。 使用场景及目标:该文档有助于建立使用者对于深度学习及其具体实践有更加直观的理解,在完成本教程之后,读者应当能够在个人设备上正确部署Python环境,并依据指示独立创建自己的简易深度学习项目。 其他说明:文中所提及的所有示例均可被完整重现,同时官方提供的资料链接也可以方便有兴趣的人士对感兴趣之处继续挖掘,这不仅加深了对PyTorch本身的熟悉程度,也为未来的研究或者工程项目打下了良好的理论基础和实践经验。
古镇美食自驾游:舌尖上的历史韵味
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
漫画作品与神话传说融合
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
ADC推理软件AI程序
漫画作品与科幻元素融合
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
java-springboot+vue景区民宿预约系统实现源码(完整前后端+mysql+说明文档+LunW+PPT).zip
在智慧城市建设的大潮中,智慧园区作为其中的璀璨明珠,正以其独特的魅力引领着产业园区的新一轮变革。想象一下,一个集绿色、高端、智能、创新于一体的未来园区,它不仅融合了科技研发、商业居住、办公文创等多种功能,更通过深度应用信息技术,实现了从传统到智慧的华丽转身。 智慧园区通过“四化”建设——即园区运营精细化、园区体验智能化、园区服务专业化和园区设施信息化,彻底颠覆了传统园区的管理模式。在这里,基础设施的数据收集与分析让管理变得更加主动和高效,从温湿度监控到烟雾报警,从消防水箱液位监测到消防栓防盗水装置,每一处细节都彰显着智能的力量。而远程抄表、空调和变配电的智能化管控,更是在节能降耗的同时,极大地提升了园区的运维效率。更令人兴奋的是,通过智慧监控、人流统计和自动访客系统等高科技手段,园区的安全防范能力得到了质的飞跃,让每一位入驻企业和个人都能享受到“拎包入住”般的便捷与安心。 更令人瞩目的是,智慧园区还构建了集信息服务、企业服务、物业服务于一体的综合服务体系。无论是通过园区门户进行信息查询、投诉反馈,还是享受便捷的电商服务、法律咨询和融资支持,亦或是利用云ERP和云OA系统提升企业的管理水平和运营效率,智慧园区都以其全面、专业、高效的服务,为企业的发展插上了腾飞的翅膀。而这一切的背后,是大数据、云计算、人工智能等前沿技术的深度融合与应用,它们如同智慧的大脑,让园区的管理和服务变得更加聪明、更加贴心。走进智慧园区,就像踏入了一个充满无限可能的未来世界,这里不仅有科技的魅力,更有生活的温度,让人不禁对未来充满了无限的憧憬与期待。
边境自驾游异国风情深度体验
在智慧城市建设的大潮中,智慧园区作为其中的璀璨明珠,正以其独特的魅力引领着产业园区的新一轮变革。想象一下,一个集绿色、高端、智能、创新于一体的未来园区,它不仅融合了科技研发、商业居住、办公文创等多种功能,更通过深度应用信息技术,实现了从传统到智慧的华丽转身。 智慧园区通过“四化”建设——即园区运营精细化、园区体验智能化、园区服务专业化和园区设施信息化,彻底颠覆了传统园区的管理模式。在这里,基础设施的数据收集与分析让管理变得更加主动和高效,从温湿度监控到烟雾报警,从消防水箱液位监测到消防栓防盗水装置,每一处细节都彰显着智能的力量。而远程抄表、空调和变配电的智能化管控,更是在节能降耗的同时,极大地提升了园区的运维效率。更令人兴奋的是,通过智慧监控、人流统计和自动访客系统等高科技手段,园区的安全防范能力得到了质的飞跃,让每一位入驻企业和个人都能享受到“拎包入住”般的便捷与安心。 更令人瞩目的是,智慧园区还构建了集信息服务、企业服务、物业服务于一体的综合服务体系。无论是通过园区门户进行信息查询、投诉反馈,还是享受便捷的电商服务、法律咨询和融资支持,亦或是利用云ERP和云OA系统提升企业的管理水平和运营效率,智慧园区都以其全面、专业、高效的服务,为企业的发展插上了腾飞的翅膀。而这一切的背后,是大数据、云计算、人工智能等前沿技术的深度融合与应用,它们如同智慧的大脑,让园区的管理和服务变得更加聪明、更加贴心。走进智慧园区,就像踏入了一个充满无限可能的未来世界,这里不仅有科技的魅力,更有生活的温度,让人不禁对未来充满了无限的憧憬与期待。