Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77e44b4

Browse files
author
Ram Vennam
committed
Add i18n for ja
1 parent 91cd12c commit 77e44b4

14 files changed

Lines changed: 1759 additions & 34 deletions

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EXPOSE 9080
1212
# docker run -p 9080:9080 --name myjavacontainer getstartedjava
1313
# Visit http://localhost:9080/GetStartedJava/
1414

15-
## Push container to Bluemix
15+
## Push container to IBM Cloud
1616
# Install cli and dependencies: https://console.ng.bluemix.net/docs/containers/container_cli_cfic_install.html#container_cli_cfic_install
1717
# docker tag getstartedjava:latest registry.ng.bluemix.net/<my_namespace>/getstartedjava:latest
1818
# docker push registry.ng.bluemix.net/<my_namespace>/getstartedjava:latest

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<version>1.0-SNAPSHOT</version>
1515
<packaging>war</packaging>
1616

17-
<name>Bluemix Getting Started</name>
17+
<name>IBM Cloud Getting Started</name>
1818
<url>https://bluemix.net</url>
1919

2020
<licenses>

src/main/java/wasdev/sample/rest/VisitorAPI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ public String getVisitors() {
9595
* @return The Visitor after it has been stored. This will include a unique ID for the Visitor.
9696
*/
9797
@POST
98-
@Produces("application/text")
98+
@Produces("application/json")
9999
@Consumes("application/json")
100100
public String newToDo(Visitor visitor) {
101101
if(store == null) {
102-
return String.format("Hello %s!", visitor.getName());
102+
return new Gson().toJson(visitor);
103103
}
104-
store.persist(visitor);
105-
return String.format("Hello %s! I've added you to the database.", visitor.getName());
104+
Visitor storedVisitor = store.persist(visitor);
105+
return new Gson().toJson(storedVisitor);
106106

107107
}
108108

src/main/java/wasdev/sample/store/CloudantVisitorStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static CloudantClient createClient() {
4848
String url;
4949

5050
if (System.getenv("VCAP_SERVICES") != null) {
51-
// When running in Bluemix, the VCAP_SERVICES env var will have the credentials for all bound/connected services
51+
// When running in IBM Cloud, the VCAP_SERVICES env var will have the credentials for all bound/connected services
5252
// Parse the VCAP JSON structure looking for cloudant.
5353
JsonObject cloudantCredentials = VCAPHelper.getCloudCredentials("cloudant");
5454
if(cloudantCredentials == null){
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# These properties are meant for local development only and will not be read when application is running in Bluemix.
2-
# When running in Bluemix, the credentials of bound services are available in the VCAP_SERVICES environment variable.
1+
# These properties are meant for local development only and will not be read when application is running in IBM Cloud.
2+
# When running in IBM Cloud, the credentials of bound services are available in the VCAP_SERVICES environment variable.
33
cloudant_url=

src/main/webapp/index.html

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html>
33

44
<head>
55
<meta charset="utf-8">
@@ -10,64 +10,107 @@
1010
<!-- Bootstrap -->
1111
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
1212
<link href="styles.css" rel="stylesheet">
13+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
14+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
15+
<!-- Include all compiled plugins (below), or include individual files as needed -->
16+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
17+
<script src="js/lib/jquery.i18n/jquery.i18n.js"></script>
18+
<script src="js/lib/jquery.i18n/jquery.i18n.messagestore.js"></script>
19+
<script src="js/lib/jquery.i18n/jquery.i18n.fallbacks.js"></script>
20+
<script src="js/lib/jquery.i18n/jquery.i18n.language.js"></script>
21+
<script src="js/lib/jquery.i18n/jquery.i18n.parser.js"></script>
22+
<script src="js/lib/jquery.i18n/jquery.i18n.emitter.js"></script>
23+
<script src="js/lib/jquery.i18n/jquery.i18n.emitter.bidi.js"></script>
24+
<script src="antixss.js" type="text/javascript"></script>
25+
26+
<script>
27+
$( document ).ready(function() {
28+
$.i18n().load( {
29+
en: {
30+
"welcome": "Welcome.",
31+
"name": "name",
32+
"what_is_your_name": "What is your name?",
33+
"hello": "Hello $1",
34+
"added_to_database": "Hello $1, I've added you to the database!",
35+
"database_contents": "Database contents: "
36+
},
37+
ja: {
38+
"welcome": "ようこそ。",
39+
"name": "名前",
40+
"what_is_your_name": "お名前を教えてください。",
41+
"hello": "こんにちは $1",
42+
"added_to_database": "こんにちは $1 さん、あなたをデータベースに追加しました。",
43+
"database_contents": "データベースの内容: "
44+
}
45+
} );
46+
$('body').i18n();
47+
$('#user_name').attr("placeholder", $.i18n('name') );
48+
});
49+
</script>
50+
1351
</head>
1452

1553
<body>
16-
<div class="container">
17-
<h1>Welcome.</h1>
54+
<div class="container" id="container">
55+
<h1 data-i18n="welcome"></h1> <!- Welcome ->
1856
<div id="nameInput" class="input-group-lg center-block helloInput">
19-
<p class="lead">What is your name?</p>
20-
<input id="user_name" type="text" class="form-control" placeholder="name" aria-describedby="sizing-addon1" value="" />
57+
<p class="lead" data-i18n="what_is_your_name"></p>
58+
<input id="user_name" type="text" class="form-control" aria-describedby="sizing-addon1" value="" />
2159
</div>
2260
<p id="response" class="lead text-center"></p>
2361

2462
<p id="databaseNames" class="lead text-center"></p>
2563
</div>
26-
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
27-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
28-
<!-- Include all compiled plugins (below), or include individual files as needed -->
29-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
30-
<script src="antixss.js" type="text/javascript"></script>
3164

32-
<script>
65+
</body>
66+
67+
68+
</html>
69+
70+
71+
<script>
3372
//Submit data when enter key is pressed
3473
$('#user_name').keydown(function(e) {
3574
var name = $('#user_name').val();
3675
if (e.which == 13 && name.length > 0) { //catch Enter key
37-
$('#nameInput').hide();
38-
$('#response').html("loading...");
3976
//POST request to API to create a new visitor entry in the database
4077
$.ajax({
4178
method: "POST",
4279
url: "./api/visitors",
4380
contentType: "application/json",
4481
data: JSON.stringify({name: name })
4582
})
46-
.done(function(data) {
47-
$('#response').html(AntiXSS.sanitizeInput(data));
83+
.done(function(data) {
84+
if(data && data.name){
85+
if(data.database)
86+
$('#response').html($.i18n('added_to_database', AntiXSS.sanitizeInput(data.name)));
87+
else
88+
$('#response').html($.i18n('hello', AntiXSS.sanitizeInput(data.name)));
89+
}
90+
else {
91+
$('#response').html(AntiXSS.sanitizeInput(data));
92+
}
93+
$('#nameInput').hide();
4894
getNames();
4995
});
5096
}
5197
});
52-
53-
//Retreive all the visitors from the database
98+
99+
//Retrieve all the visitors from the database
54100
function getNames(){
55101
$.get("./api/visitors")
56102
.done(function(data) {
57103
if(data.length > 0) {
58104
data.forEach(function(element, index) {
59105
data[index] = AntiXSS.sanitizeInput(element)
60106
});
61-
$('#databaseNames').html("Database contents: " + JSON.stringify(data));
107+
$('#databaseNames').html($.i18n('database_contents') + JSON.stringify(data));
62108
}
63109
});
64110
}
65-
111+
66112
//Call getNames on page load.
67113
getNames();
68-
69-
70-
</script>
71-
</body>
72114

73-
</html>
115+
116+
</script>

0 commit comments

Comments
 (0)