Skip to content

Commit

Permalink
Adding in initial support for Japanese.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ming Iu committed Apr 26, 2012
1 parent 38292bd commit 944734d
Show file tree
Hide file tree
Showing 7 changed files with 959 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/org/mozilla/javascript/BabylTokenizer.java
Expand Up @@ -599,6 +599,8 @@ protected int matchSymbol(int c) throws IOException
languageModeCodes.put("\u7b80\u4f53", TokenStream.LanguageMode.zh); languageModeCodes.put("\u7b80\u4f53", TokenStream.LanguageMode.zh);
languageModeCodes.put("hi", TokenStream.LanguageMode.hi); languageModeCodes.put("hi", TokenStream.LanguageMode.hi);
languageModeCodes.put("\u0939\u093f", TokenStream.LanguageMode.hi); languageModeCodes.put("\u0939\u093f", TokenStream.LanguageMode.hi);
languageModeCodes.put("ja", TokenStream.LanguageMode.ja);
languageModeCodes.put("\u65e5\u672c\u8a9e", TokenStream.LanguageMode.ja);
} }


private int scanLanguageMode() throws IOException private int scanLanguageMode() throws IOException
Expand Down
9 changes: 9 additions & 0 deletions src/org/mozilla/javascript/TokenStream.java
Expand Up @@ -53,6 +53,7 @@
import org.mozilla.javascript.babylscript.EnglishTokenizer; import org.mozilla.javascript.babylscript.EnglishTokenizer;
import org.mozilla.javascript.babylscript.FrenchTokenizer; import org.mozilla.javascript.babylscript.FrenchTokenizer;
import org.mozilla.javascript.babylscript.HindiTokenizer; import org.mozilla.javascript.babylscript.HindiTokenizer;
import org.mozilla.javascript.babylscript.JapaneseTokenizer;
import org.mozilla.javascript.babylscript.PortugueseTokenizer; import org.mozilla.javascript.babylscript.PortugueseTokenizer;
import org.mozilla.javascript.babylscript.RomanianTokenizer; import org.mozilla.javascript.babylscript.RomanianTokenizer;
import org.mozilla.javascript.babylscript.SpanishTokenizer; import org.mozilla.javascript.babylscript.SpanishTokenizer;
Expand Down Expand Up @@ -256,6 +257,7 @@ public static enum LanguageMode
en, en,
es, es,
fr, fr,
ja,
hi, hi,
pt, pt,
test, test,
Expand All @@ -276,6 +278,8 @@ else if ("fr".equals(str))
return LanguageMode.fr; return LanguageMode.fr;
else if ("hi".equals(str)) else if ("hi".equals(str))
return LanguageMode.hi; return LanguageMode.hi;
else if ("ja".equals(str))
return LanguageMode.ja;
else if ("pt".equals(str)) else if ("pt".equals(str))
return LanguageMode.pt; return LanguageMode.pt;
else if ("ro".equals(str)) else if ("ro".equals(str))
Expand Down Expand Up @@ -306,6 +310,9 @@ public void setLanguage(LanguageMode language)
case hi: case hi:
currentTokenizer = new HindiTokenizer(parser, in, this); currentTokenizer = new HindiTokenizer(parser, in, this);
break; break;
case ja:
currentTokenizer = new JapaneseTokenizer(parser, in, this);
break;
case pt: case pt:
currentTokenizer = new PortugueseTokenizer(parser, in, this); currentTokenizer = new PortugueseTokenizer(parser, in, this);
break; break;
Expand Down Expand Up @@ -335,6 +342,8 @@ public String getLastLanguageString()
return "fr"; return "fr";
case hi: case hi:
return "hi"; return "hi";
case ja:
return "ja";
case pt: case pt:
return "pt"; return "pt";
case ro: case ro:
Expand Down
92 changes: 92 additions & 0 deletions src/org/mozilla/javascript/babylscript/JapaneseTokenizer.java
@@ -0,0 +1,92 @@
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Rhino code, released
* May 6, 1999.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1997-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roger Lawrence
* Mike McCabe
* Igor Bukanov
* Ethan Hugg
* Bob Jervis
* Terry Lucas
* Milen Nankov
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which
* case the provisions of the GPL are applicable instead of those above. If
* you wish to allow use of your version of this file only under the terms of
* the GPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replacing
* them with the notice and other provisions required by the GPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* ***** END LICENSE BLOCK ***** */

package org.mozilla.javascript.babylscript;

import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

import org.mozilla.javascript.BabylTokenizer;
import org.mozilla.javascript.Parser;
import org.mozilla.javascript.TokenCharStream;
import org.mozilla.javascript.TokenStream;

public class JapaneseTokenizer extends BabylGenericTokenizer
{
public JapaneseTokenizer(Parser p, TokenCharStream in, TokenStream ts)
{
super(p,
in,
ts,
new BabylTokenizer.DecimalNumberReader(),
BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Keywords", new Locale("ja")));
}

protected int matchSymbol(int c) throws IOException
{
// For single-character symbols, we'll substitute kanji symbols with
// their English equivalents

if (c == '\u3002')
c = '.';
else if (c == '\u3001')
c = ',';

return super.matchSymbol(c);
}

protected boolean isStringDelimiter(int ch)
{
return (ch == '\'' || ch == '\"' || ch == '\u300c'
|| ch == '\u300e');
}
protected int getMatchingStringDelimiter(int ch)
{
if (ch == '\'') return '\'';
if (ch == '\u300c') return '\u300d';
if (ch == '\u300e') return '\u300f';
return '\"';
}
}
Expand Up @@ -38,6 +38,9 @@ public class TranslatedNameBindings
EquivalentLanguageNames.put("hi", new String[] {"hi", "\u0939\u093f"}); EquivalentLanguageNames.put("hi", new String[] {"hi", "\u0939\u093f"});
EquivalentLanguageNames.put("\u0939\u093f", new String[] {"hi", "\u0939\u093f"}); EquivalentLanguageNames.put("\u0939\u093f", new String[] {"hi", "\u0939\u093f"});


EquivalentLanguageNames.put("ja", new String[] {"ja", "\u65e5\u672c\u8a9e"});
EquivalentLanguageNames.put("\u65e5\u672c\u8a9e", new String[] {"ja", "\u65e5\u672c\u8a9e"});

EquivalentLanguageNames = Collections.unmodifiableMap(EquivalentLanguageNames); EquivalentLanguageNames = Collections.unmodifiableMap(EquivalentLanguageNames);
} }


Expand All @@ -48,6 +51,7 @@ public class TranslatedNameBindings
static ResourceBundle chineseSimplified = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("zh")); static ResourceBundle chineseSimplified = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("zh"));
static ResourceBundle hindi = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("hi")); static ResourceBundle hindi = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("hi"));
static ResourceBundle spanish = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("es")); static ResourceBundle spanish = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("es"));
static ResourceBundle japanese = BabylscriptNoDefaultResourceBundle.getBundle("org/mozilla/javascript/babylscript/resources/Objects", new Locale("ja"));


static Map<String, ResourceBundle> langResourceMap = new HashMap<String, ResourceBundle>(); static Map<String, ResourceBundle> langResourceMap = new HashMap<String, ResourceBundle>();
static { static {
Expand All @@ -58,6 +62,7 @@ public class TranslatedNameBindings
langResourceMap.put("zh", chineseSimplified); langResourceMap.put("zh", chineseSimplified);
langResourceMap.put("hi", hindi); langResourceMap.put("hi", hindi);
langResourceMap.put("es", spanish); langResourceMap.put("es", spanish);
langResourceMap.put("ja", japanese);
} }


private static void fillTranslationsFromResourceBundle(Scriptable obj, String lang, ResourceBundle res, String[] english) private static void fillTranslationsFromResourceBundle(Scriptable obj, String lang, ResourceBundle res, String[] english)
Expand Down
@@ -0,0 +1,64 @@
#. Contributors = Yamakoshi Akihiro
# Made available under the terms of CC0

false = \u507d
debugger = \u30c7\u30d0\u30c3\u30ac
super = \u30b9\u30fc\u30d1\u30fc
int = \u6574\u6570
abstract = \u62bd\u8c61
float = \u5358\u7cbe\u5ea6\u6d6e\u52d5\u5c11\u6570\u70b9\u6570
private = \u30d7\u30e9\u30a4\u30d9\u30fc\u30c8
char = \u6587\u5b57
interface = \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9
boolean = \u30d6\u30fc\u30ea\u30a2\u30f3
static = \u9759\u7684
in = \u4e2d\u306b
null = \u30cc\u30eb\u6587\u5b57
if = \u3082\u3057
const = \u5b9a\u6570
synchronized = \u540c\u671f
for = \u306e\u305f\u3081
true = \u771f
while = \u305a\u3063\u3068
long = \u9577\u3044\u6574\u6570
class = \u30af\u30e9\u30b9
finally = \u6700\u7d42\u306b
protected = \u4fdd\u8b77\u3055\u308c\u305f
extends = \u62e1\u5f35
implements = \u5b9f\u88c5\u3059\u308b
var = \u5909\u6570
new = \u65b0\u3057\u3044
native = \u30cd\u30a4\u30c6\u30a3\u30d6
final = \u30d5\u30a1\u30a4\u30ca\u30eb
function = \u95a2\u6570
do = \u884c\u3046
return = \u623b\u308b
goto = \u306b\u884c\u304f
void = \u7121
enum = \u5217\u6319\u5b9a\u6570
else = \u4ed6
break = \u30d6\u30ec\u30fc\u30af
transient = \u4e00\u6642\u7684\u306a
let = \u662f\u975e
import = \u8f38\u5165
catch = \u30ad\u30e3\u30c3\u30c1
instanceof = \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9
byte = \u30d0\u30a4\u30c8
with = \u5171\u306b
throw = \u30b9\u30ed\u30fc
volatile = \u63ee\u767a\u6027
case = \u30b1\u30fc\u30b9
short = \u77ed\u3044\u6574\u6570
package = \u30d1\u30c3\u30b1\u30fc\u30b8
this = \u3053\u306e
double = \u500d\u7cbe\u5ea6\u6d6e\u52d5\u5c11\u6570\u70b9\u6570
yield = \u53ce\u7387
public = \u30d1\u30d6\u30ea\u30c3\u30af
try = \u8a66\u3059
default = \u30c7\u30d5\u30a9\u30eb\u30c8
switch = \u30b9\u30a4\u30c3\u30c1
continue = \u30b3\u30f3\u30c6\u30a3\u30cb\u30e5\u30fc
typeof = \u306e\u30bf\u30a4\u30d7
export = \u8f38\u51fa
throws = \u30b9\u30ed\u30fc
delete = \u30c7\u30ea\u30fc\u30c8

0 comments on commit 944734d

Please sign in to comment.