Permalink
Browse files

from-to translating, ja-JP from babylscript.com

  • Loading branch information...
1 parent 9fa70d8 commit a02423254de3627b2b470f7a189e0ac55889a616 @kig committed Jul 29, 2012
Showing with 66 additions and 14 deletions.
  1. +66 −14 index.html
View
@@ -4,20 +4,25 @@
<meta charset="utf-8">
<style>
textarea {
- display: inline-block;
+ display: block;
width: 300px;
- height: 300px;
+ height: 400px;
+ }
+ .ib {
+ display: inline-block;
+ vertical-align: top;
}
</style>
</head>
<body>
- <select id="locale">
- <option>fi-FI</option>
- <option>en-US</option>
- <option>Custom</option>
- </select>
<div>
- <textarea id="source">
+ <div class="ib">
+ From <select id="locale">
+ <option>fi-FI</option>
+ <option>en-US</option>
+ <option>Custom</option>
+ </select>
+ <textarea id="source">
funktio f(x) {
jos (x % 2 == 0) {
palauta tosi;
@@ -46,9 +51,17 @@
joka (muu i johon tere) {
console.log(i);
}
-
- </textarea>
- <textarea id="javascript" disabled="disabled">JavaScript output</textarea>
+ </textarea>
+ </div>
+ <div class="ib">
+ To <select id="targetLocale">
+ <option>ja-JP</option>
+ <option>en-US</option>
+ <option>fi-FI</option>
+ <option>Custom</option>
+ </select>
+ <textarea id="javascript" disabled="disabled">Translation output</textarea>
+ </div>
</div>
<button id="run">Run</button>
<div>
@@ -58,6 +71,13 @@ <h3>Make your custom translation</h3>
</div>
<script src="esprima.js"></script>
<script>
+var invert = function(obj) {
+ var o = {};
+ for (var i in obj) {
+ o[obj[i]] = i;
+ }
+ return o;
+};
window.LocaleMappings = {
'en-US': {
'if': 'if',
@@ -118,6 +138,39 @@ <h3>Make your custom translation</h3>
'static': 'static'
},
+'ja-JP': invert({
+ 'function':'関数',
+ 'if':'もし',
+ 'else':'それ以外',
+ 'for':'なら',
+ 'while':'ながら',
+ 'return':'戻す',
+ 'do':'する',
+ 'true':'',
+ 'false':'',
+ 'var':'変数',
+ 'in':'',
+ 'let':'させ',
+ 'new':'',
+ 'try':'',
+ 'case':'ケース',
+ 'null':'ヌル',
+ 'this':'これ',
+ 'with':'',
+ 'break':'中断',
+ 'throw':'投げ',
+ 'catch':'受け',
+ 'switch':'スイッチ',
+ 'continue':'続け',
+ 'debugger':'デバッガ',
+ 'instanceof':'実例',
+ 'typeof':'属性',
+ 'void':'無効',
+ 'delete':'削除',
+ 'default':'デフォルト',
+ 'finally':'やっと'
+}),
+
'fi-FI': {
'jos':'if',
'johon':'in',
@@ -299,16 +352,15 @@ <h3>Make your custom translation</h3>
document.getElementById('run').onclick = function() {
var src = document.getElementById('source').value;
var locale = document.getElementById('locale').value;
+ var targetLocale = document.getElementById('targetLocale').value;
var js;
try {
if (locale === 'en-US') {
- js = localise(src, 'Custom');
- document.getElementById('javascript').value = js;
js = src;
} else {
js = delocalise(src, locale);
- document.getElementById('javascript').value = js;
}
+ document.getElementById('javascript').value = localise(js, targetLocale);
} catch(e) {
document.getElementById('javascript').value = "Parse error: " + e;
}

0 comments on commit a024232

Please sign in to comment.