Skip to content

Commit

Permalink
Merge pull request #2 from iron9light/i18n
Browse files Browse the repository at this point in the history
Support i18n and add translations for simplified Chinese
  • Loading branch information
David Pollak committed Aug 15, 2012
2 parents 615b7af + 9bbb30f commit 5b38f2b
Show file tree
Hide file tree
Showing 35 changed files with 1,470 additions and 54 deletions.
22 changes: 22 additions & 0 deletions build.sbt
@@ -0,0 +1,22 @@
seq(webSettings :_*)

organization := "Lift"

name := "seventhings"

version := "0.1"

scalaVersion := "2.9.1"

libraryDependencies ++= {
val liftVersion = "2.4"
Seq(
"net.liftweb" %% "lift-webkit" % liftVersion,
"net.liftweb" %% "lift-wizard" % liftVersion,
"org.mortbay.jetty" % "jetty" % "6.1.22" % "container; test",
"junit" % "junit" % "4.10" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.6",
"org.specs2" %% "specs2" % "1.11" % "test",
"com.h2database" % "h2" % "1.3.167"
)
}
10 changes: 1 addition & 9 deletions project/build.properties
@@ -1,9 +1 @@
#Project properties sbt.version=0.11.3
#Fri Apr 23 11:24:20 PDT 2010
project.organization=Lift
project.name=seventhings
sbt.version=0.7.4
project.version=0.1
def.scala.version=2.7.7
build.scala.versions=2.8.1
project.initialize=false
24 changes: 0 additions & 24 deletions project/build/LiftProject.scala

This file was deleted.

12 changes: 12 additions & 0 deletions project/plugins.sbt
@@ -0,0 +1,12 @@
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"

libraryDependencies <+= sbtVersion(v => v match {
case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
})

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0-RC1")

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")
2 changes: 1 addition & 1 deletion sbt
@@ -1 +1 @@
java -Xmx512M -Xss2M -XX:+CMSClassUnloadingEnabled -jar `dirname $0`/sbt-launcher.jar "$@" java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar `dirname $0`/sbt-launch.jar "$@"
Binary file added sbt-launch.jar
Binary file not shown.
Binary file removed sbt-launcher.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sbt.bat
@@ -1,2 +1,2 @@
set SCRIPT_DIR=%~dp0 set SCRIPT_DIR=%~dp0
java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -jar "%SCRIPT_DIR%\sbt-launcher.jar" %* java -Xmx512M -jar "%SCRIPT_DIR%sbt-launch.jar" %*
23 changes: 23 additions & 0 deletions src/main/resources/i18n/trans_zh_CN.properties
@@ -0,0 +1,23 @@
# Index
Home = \u9996\u9875
Lazy\ Loading = \u5EF6\u8FDF\u52A0\u8F7D
Parallel\ Rendering = \u5E76\u884C\u6E32\u67D3
# Wiring =
Designer\ Friendly\ Templates = \u8BBE\u8BA1\u53CB\u597D\u7684\u6A21\u677F\u7CFB\u7EDF
Wizard = \u5411\u5BFC\u7EC4\u4EF6
Security = \u5B89\u5168\u6027

# Chat
Welcome = \u6B22\u8FCE

# Wizard
First\ Name = \u59D3\u540D
Name\ Too\ Short = \u540D\u5B57\u592A\u77ED\u4E86
Name\ Too\ Long = \u540D\u5B57\u592A\u957F\u4E86
Age = \u5E74\u9F84
Too\ young = \u5E74\u9F84\u592A\u5C0F\u4E86
You\ should\ be\ dead = \u4F60\u662F\u795E\u4ED9\u5417
Mom\ or\ Dad's\ name = \u5988\u5988\u6216\u7238\u7238\u7684\u540D\u5B57
Pet's\ name = \u5BA0\u7269\u7684\u540D\u5B57
Thank\ you\ for\ registering\ your\ pet = \u611F\u8C22\u60A8\u6CE8\u518C\u60A8\u7684\u5BA0\u7269
your\ age = \u60A8\u7684\u5E74\u9F84
23 changes: 23 additions & 0 deletions src/main/resources/i18n/trans_zh_TW.properties
@@ -0,0 +1,23 @@
# Index
Home = \u9996\u9801
Lazy\ Loading = \u5EF6\u9072\u52A0\u8F09
Parallel\ Rendering = \u4E26\u884C\u6E32\u67D3
# Wiring =
Designer\ Friendly\ Templates = \u8A2D\u8A08\u53CB\u597D\u7684\u6A21\u677F\u7CFB\u7D71
Wizard = \u56AE\u5C0E\u7D44\u4EF6
Security = \u5B89\u5168\u6027

# Chat
Welcome = \u6B61\u8FCE

# Wizard
First\ Name = \u59D3\u540D
Name\ Too\ Short = \u540D\u5B57\u592A\u77ED\u4E86
Name\ Too\ Long = \u540D\u5B57\u592A\u9577\u4E86
Age = \u5E74\u9F61
Too\ young = \u5E74\u9F61\u592A\u5C0F\u4E86
You\ should\ be\ dead = \u4F60\u662F\u795E\u4ED9\u55CE
Mom\ or\ Dad's\ name = \u5ABD\u5ABD\u6216\u7238\u7238\u7684\u540D\u5B57
Pet's\ name = \u5BF5\u7269\u7684\u540D\u5B57
Thank\ you\ for\ registering\ your\ pet = \u611F\u8B1D\u60A8\u8A3B\u518A\u60A8\u7684\u5BF5\u7269
your\ age = \u60A8\u7684\u5E74\u9F61
17 changes: 9 additions & 8 deletions src/main/scala/bootstrap/liftweb/Boot.scala
Expand Up @@ -22,13 +22,13 @@ class Boot {
// Build SiteMap // Build SiteMap
def sitemap = SiteMap( def sitemap = SiteMap(
Menu.i("Home") / "index", Menu.i("Home") / "index",
Menu("lazy", "Lazy Loading") / "lazy", Menu("lazy", S ? "Lazy Loading") / "lazy",
Menu("parallel", "Parallel Rendering") / "parallel", Menu("parallel", S ? "Parallel Rendering") / "parallel",
Menu("comet", "Comet & Ajax") / "comet", Menu("comet", S ? "Comet & Ajax") / "comet",
Menu("wiring", "Wiring") / "wiring", Menu("wiring", S ? "Wiring") / "wiring",
Menu("templates", "Designer Friendly Templates") / "templates", Menu("templates", S ? "Designer Friendly Templates") / "templates",
Menu("wizard", "Wizard") / "wizard", Menu("wizard", S ? "Wizard") / "wizard",
Menu("security", "Security") / "security") Menu("security", S ? "Security") / "security")


// set the sitemap. Note if you don't want access control for // set the sitemap. Note if you don't want access control for
// each page, just comment this line out. // each page, just comment this line out.
Expand All @@ -47,7 +47,8 @@ class Boot {


// Use HTML5 for rendering // Use HTML5 for rendering
LiftRules.htmlProperties.default.set((r: Req) => LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent)) new Html5Properties(r.userAgent))


LiftRules.resourceNames ::= "i18n/trans"
} }
} }
2 changes: 1 addition & 1 deletion src/main/scala/net/liftweb/seventhings/comet/Chat.scala
Expand Up @@ -31,7 +31,7 @@ class Chat extends CometActor with CometListener {
* The chat server * The chat server
*/ */
object ChatServer extends LiftActor with ListenerManager { object ChatServer extends LiftActor with ListenerManager {
private var msgs = Vector("Welcome") // the private data private var msgs = Vector(S ? "Welcome") // the private data


// what we send to listeners on update // what we send to listeners on update
def createUpdate = msgs def createUpdate = msgs
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/net/liftweb/seventhings/snippet/MyWizard.scala
Expand Up @@ -44,9 +44,9 @@ object MyWizard extends Wizard {


// what to do on completion of the wizard // what to do on completion of the wizard
def finish() { def finish() {
S.notice("Thank you for registering your pet: "+ S.notice(S ? "Thank you for registering your pet" + ": "+
favoritePet.petName+ favoritePet.petName+
" your age * 3: "+nameAndAge.age * 3) " " + S ? "your age" + "* 3: "+nameAndAge.age * 3)
} }
} }


Expand Down
113 changes: 113 additions & 0 deletions src/main/webapp/comet_zh_CN.html
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Comet</title>
</head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<p>
<big>
<big>
Lift的一个关键功能就是对Comet(服务器推送)和相关连的Ajax的支持。
本页包含了一个多人聊天室应用,当任何人发送聊天消息时,会以Comet(服务器推送)更新浏览器。
用户可以通过页面的输入框发送一行信息到聊天室,信息会以异步请求的方式发送到服务器(页面在请求的时候不会重新加载)。
</big>
</big>
</p>

<div style="margin: 12px; border: 2px solid purple">
<ul class="lift:comet?type=Chat">
<li>Line 1</li>
<li class="clearable">Line 2</li>
<li class="clearable">Line 3</li>
</ul>

<form class="lift:Form.ajax">
<input class="lift:ChatIn" id="chat_in">
<input type="submit" value="Chat">
</form>
</div>

<big>
<big>
让我们看看应用的Comet(服务器推送聊天内容列表)部分的标记代码:
</big>
</big>
<pre class="lift:ShowCode?name=/comet.html;start=ul+;end=form">view code</pre>

<div>
<big>
<big>
我们只是简单的标记&lt;ul>标签为一个snippet调用,用来载入名为<tt>Chat</tt>的Comet组件。
让我们看看<tt>Chat</tt>组件。
</big>
</big>
</div>

<pre class="lift:ShowCode?name=/net/liftweb/seventhings/comet/Chat.scala;start=**;end=**">view code</pre>


<div>
<big>
<big>
再次证明,对于其他框架来说很难或者根本不可能的事情,对于Lift来说小菜一碟。
开发人员不用管浏览器是如何轮询(poll)最新的变化。
Lift默认使用long polling和合并多个comet组件到一个单独的long poll,当web socket标准化以后,Lift将会自动支持web socket而不影响你写的代码。
开发人员只用管“什么时候服务器端发生变化了,就更新组件”,Lift来完成剩下的工作。
</big>
</big>
</div>

<br>

<div>
<big>
<big>
请注意,你可以试试用<a href="http://en.wikipedia.org/wiki/Cross-site_scripting">cross site scripting</a>攻击来攻击本网站(例如,在聊天输入框输入<tt>&lt;script>alert('我黑了你的机器')&lt/script></tt>)。
你会发现在开发者没有做任何事情的情况下,Lift正确的转码了你输入的东西。
</big>
</big>
</div>

<br>

<div>
<big>
<big>
让我们来看看关于Ajax输入表单的标记代码:
</big>
</big>
</div>

<pre class="lift:ShowCode?name=/comet.html;start=form;end=div">view code</pre>

<div>
<big>
<big>
我们用<tt>Form.ajax</tt> snippet来指示这个<tt>form</tt>是一个Ajax表单。
文本输入触发<tt>ChatIn</tt> snippet。
来看看这个snippet:
</big>
</big>
</div>

<pre class="lift:ShowCode?name=/net/liftweb/seventhings/snippet/ChatIn.scala;start=**">view code</pre>

<div>
<big>
<big>
再次表明,我们不许要任何深入研究。
Lift负责行为(发送输入的<tt>String</tt><tt>ChatServer</tt>。)的关联。
我们没有设置routes或任何其他东西。
甚至这段代码可以抵抗replay攻击,因为这个自动生成的routes是动态、随机和不可预测的。
当你想用标准的REST访问来完成任务的时候,Lift提供<a href="http://www.assembla.com/wiki/show/liftweb/REST_Web_Services">非常棒的REST支持</a>
并且Lift支持数据或者HTML的Comet,所以你可也用Lift作为<a href="http://frothy.liftweb.net/capp">Cappuccino</a>、SproutCore、ExtJS等应用的服务端,并获得全面的Comet支持。
</big>
</big>
</div>


</div>
</body>
</html>

0 comments on commit 5b38f2b

Please sign in to comment.