chg: merged parser code modified in antville app back into hopkit
This commit is contained in:
parent
0bf39c8f4b
commit
657f66c0ce
2 changed files with 441 additions and 399 deletions
|
@ -1,7 +1,6 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
// Copyright 2004 ORF Online und Teletext GmbH.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -14,13 +13,6 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
|
@ -103,7 +95,10 @@ Message.formatId = function(str, wrap) {
|
|||
* was found at
|
||||
*/
|
||||
Message.prototype.addLocation = function(filePath, lineNum) {
|
||||
this.locations.push(filePath + ":" + lineNum);
|
||||
const basePath = java.nio.file.Paths.get(java.io.File(app.dir).getCanonicalPath());
|
||||
const locationPath = java.nio.file.Paths.get(filePath);
|
||||
const relativePath = basePath.relativize(locationPath);
|
||||
this.locations.push(relativePath + ":" + lineNum);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -153,7 +148,8 @@ MessageParser.FUNCTION_NAMES = {
|
|||
"_": true,
|
||||
"gettext": true,
|
||||
"ngettext": true,
|
||||
"markgettext": true
|
||||
"markgettext": true,
|
||||
"cgettext": true
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -219,12 +215,12 @@ MessageParser.prototype.parse = function(file, encoding) {
|
|||
if ((dotIdx = fName.lastIndexOf(".")) > -1) {
|
||||
switch (String(fName.substring(dotIdx+1))) {
|
||||
case "skin":
|
||||
print("Parsing skin file " + file.getAbsolutePath() + "...");
|
||||
print("Parsing skin file " + file.getCanonicalPath() + "...");
|
||||
this.parseSkinFile(file, encoding);
|
||||
break;
|
||||
case "hac":
|
||||
case "js":
|
||||
print("Parsing function file " + file.getAbsolutePath() + "...");
|
||||
print("Parsing function file " + file.getCanonicalPath() + "...");
|
||||
this.parseFunctionFile(file, encoding);
|
||||
break;
|
||||
default:
|
||||
|
@ -287,6 +283,10 @@ MessageParser.prototype.parseFunctionFile = function(file, encoding) {
|
|||
for (var i=0;i<messages.length;i++) {
|
||||
msgParam = messages[i];
|
||||
if (msgParam.args && msgParam.args.length > 0) {
|
||||
if (msgParam.name === "cgettext" || msgParam.name === "markgettext") {
|
||||
msgParam.args[0] = cgettext.getKey(msgParam.args[0], msgParam.args[1]);
|
||||
delete msgParam.args[1];
|
||||
}
|
||||
key = Message.getKey(msgParam.args[0]);
|
||||
if (!(msg = this.messages[key])) {
|
||||
this.messages[key] = msg = new Message(msgParam.args[0], msgParam.args[1]);
|
||||
|
@ -294,7 +294,7 @@ MessageParser.prototype.parseFunctionFile = function(file, encoding) {
|
|||
if (!msg.pluralId && msgParam.args.length > 1) {
|
||||
msg.pluralId = msgParam.args[1];
|
||||
}
|
||||
msg.addLocation(file.getAbsolutePath(), msgParam.lineNr);
|
||||
msg.addLocation(file.getCanonicalPath(), msgParam.lineNr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,61 +313,111 @@ MessageParser.prototype.parseFunctionFile = function(file, encoding) {
|
|||
* @param {String} encoding The encoding to use
|
||||
*/
|
||||
MessageParser.prototype.parseSkinFile = function(file, encoding) {
|
||||
var content = readFile(file.getAbsolutePath(), encoding || "UTF-8");
|
||||
var macro, id, pluralId, params, key;
|
||||
while (macro = MessageParser.REGEX_MACRO.exec(content)) {
|
||||
while (params = MessageParser.REGEX_PARAM.exec(macro[3])) {
|
||||
if (macro[2] == MessageParser.MACRO_NAME) {
|
||||
if (params[1] == "text") {
|
||||
id = params[2];
|
||||
pluralId = null;
|
||||
} else if (params[1] == "plural") {
|
||||
pluralId = params[2];
|
||||
var self = this;
|
||||
var source = readFile(file.getAbsolutePath(), encoding || "UTF-8");
|
||||
|
||||
var checkNestedMacros = function(iterator) {
|
||||
var macros = [];
|
||||
while (iterator.hasNext()) {
|
||||
macro = iterator.next();
|
||||
if (macro && macro.constructor !== String) {
|
||||
macros.push(macro);
|
||||
}
|
||||
} else {
|
||||
if (params[1] == MessageParser.ATTRIBUTE_NAME) {
|
||||
id = params[2];
|
||||
pluralId = null;
|
||||
} else if (params[1] == "plural") {
|
||||
pluralId = params[2];
|
||||
}
|
||||
processMacros(macros);
|
||||
}
|
||||
|
||||
var processMacros = function(macros) {
|
||||
var re = gettext_macro.REGEX;
|
||||
var id, pluralId, name, args, param, key, msg;
|
||||
for each (var macro in macros) {
|
||||
id = pluralId = null;
|
||||
name = macro.getName();
|
||||
param = macro.getNamedParams();
|
||||
if (param) {
|
||||
checkNestedMacros(param.values().iterator());
|
||||
if (name === MessageParser.MACRO_NAME) {
|
||||
id = param.get("text");
|
||||
pluralId = param.get("plural");
|
||||
} else if (param.containsKey("message") === MessageParser.ATTRIBUTE_NAME) {
|
||||
id = param.get("message");
|
||||
pluralId = param.get("plural");
|
||||
}
|
||||
}
|
||||
args = macro.getPositionalParams();
|
||||
if (args) {
|
||||
checkNestedMacros(args.iterator());
|
||||
if (name === "gettext" || name === "markgettext") {
|
||||
id = cgettext.getKey(args.get(0), param && param.get("context"));
|
||||
} else if (name === "ngettext") {
|
||||
id = args.get(0);
|
||||
pluralId = args.get(1);
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
if (id.constructor !== String) {
|
||||
continue;
|
||||
}
|
||||
// create new Message instance or update the existing one
|
||||
id = id.replace(re, String.SPACE);
|
||||
pluralId && (pluralId = pluralId.replace(re, String.SPACE));
|
||||
key = Message.getKey(id);
|
||||
if (!(msg = this.messages[key])) {
|
||||
this.messages[key] = msg = new Message(id, pluralId, file.getAbsolutePath());
|
||||
if (!(msg = self.messages[key])) {
|
||||
self.messages[key] = msg = new Message(id, pluralId, file.getCanonicalPath());
|
||||
}
|
||||
msg.addLocation(file.getAbsolutePath(),
|
||||
MessageParser.getLineNum(content, macro.index));
|
||||
msg.addLocation(file.getCanonicalPath(), MessageParser.getLineNum(source, macro.start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var skin = createSkin(source);
|
||||
if (skin.hasMainskin()) {
|
||||
processMacros(skin.getMacros());
|
||||
}
|
||||
for each (var name in skin.getSubskinNames()) {
|
||||
var subskin = skin.getSubskin(name);
|
||||
processMacros(subskin.getMacros());
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a standard Header of a .po file
|
||||
* FIXME: Allow custom header (template?)
|
||||
* FIXME: why the hell is Plural-Forms ignored in poEdit?
|
||||
* @see http://drupal.org/node/17564
|
||||
*/
|
||||
MessageParser.prototype.getPotString = function() {
|
||||
var date = new Date;
|
||||
var buf = new java.lang.StringBuffer();
|
||||
buf.append('# SOME DESCRIPTIVE TITLE.\n');
|
||||
buf.append('# Copyright (C) YEAR THE PACKAGE\'S COPYRIGHT HOLDER\n');
|
||||
buf.append('# This file is distributed under the same license as the PACKAGE package.\n');
|
||||
buf.append('# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# The Antville Project\n');
|
||||
buf.append('# http://code.google.com/p/antville\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Copyright 2001-' + date.getFullYear() + ' by the Workers of Antville.\n');
|
||||
buf.append('#\n');
|
||||
buf.append("# Licensed under the Apache License, Version 2.0 (the ``License''\n");
|
||||
buf.append('# you may not use this file except in compliance with the License.\n');
|
||||
buf.append('# You may obtain a copy of the License at\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# http://www.apache.org/licenses/LICENSE-2.0\n');
|
||||
buf.append('#\n');
|
||||
buf.append('# Unless required by applicable law or agreed to in writing, software\n');
|
||||
buf.append("# distributed under the License is distributed on an ``AS IS'' BASIS,\n");
|
||||
buf.append('# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n');
|
||||
buf.append('# See the License for the specific language governing permissions and\n');
|
||||
buf.append('# limitations under the License.\n');
|
||||
buf.append('#\n\n');
|
||||
buf.append('#, fuzzy\n');
|
||||
buf.append('msgid ""\n');
|
||||
buf.append('msgstr ""\n');
|
||||
buf.append('"Project-Id-Version: PACKAGE VERSION\\n"\n');
|
||||
buf.append('"Report-Msgid-Bugs-To: \\n"\n');
|
||||
buf.append('"Project-Id-Version: Antville-' + Root.VERSION + '\\n"\n');
|
||||
buf.append('"Report-Msgid-Bugs-To: mail@antville.org\\n"\n');
|
||||
var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mmZ");
|
||||
buf.append('"POT-Creation-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
buf.append('"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"\n');
|
||||
buf.append('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"\n');
|
||||
buf.append('"Language-Team: LANGUAGE <LL@li.org>\\n"\n');
|
||||
buf.append('"PO-Revision-Date: ' + sdf.format(new java.util.Date()) + '\\n"\n');
|
||||
//buf.append('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"\n');
|
||||
buf.append('"Language-Team: The Antville People <mail@antville.org>\\n"\n');
|
||||
buf.append('"MIME-Version: 1.0\\n"\n');
|
||||
buf.append('"Content-Type: text/plain; charset=utf-8\\n"\n');
|
||||
buf.append('"Content-Transfer-Encoding: 8bit\\n"\n');
|
||||
|
@ -384,7 +434,7 @@ MessageParser.prototype.getPotString = function() {
|
|||
for (var i=0;i<keys.length;i++) {
|
||||
this.messages[keys[i]].write(buf);
|
||||
}
|
||||
return buf.toString();
|
||||
return new java.lang.String(buf);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//
|
||||
// Jala Project [http://opensvn.csie.org/traccgi/jala]
|
||||
//
|
||||
// Copyright 2004 ORF Online und Teletext GmbH
|
||||
// Copyright 2004 ORF Online und Teletext GmbH.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -14,13 +13,6 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $HeadURL$
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* @fileoverview
|
||||
|
@ -228,7 +220,8 @@ PoParser.prototype.writeToFile = function(output) {
|
|||
buf.append('/**\n');
|
||||
buf.append(' * Messages for locale "' + this.localeKey + '"\n');
|
||||
buf.append(' */\n');
|
||||
objPath += "." + this.localeKey;
|
||||
var fname = objPath + "." + this.localeKey + ".js";
|
||||
objPath += "['" + this.localeKey + "']";
|
||||
buf.append('global.' + objPath + ' = {\n');
|
||||
// write messages
|
||||
for (var i=0;i<this.messages.length; i++) {
|
||||
|
@ -238,10 +231,9 @@ PoParser.prototype.writeToFile = function(output) {
|
|||
buf.append('};\n');
|
||||
|
||||
// write the message catalog into the outFile
|
||||
var file = new java.io.File(output, objPath + ".js");
|
||||
var file = new java.io.File(output, fname);
|
||||
var writer = new java.io.FileWriter(file);
|
||||
writer.write(buf.toString());
|
||||
// writer.write(buf.toString().getBytes("UTF-8"));
|
||||
writer.write(new java.lang.String(buf.toString().getBytes("UTF-8")));
|
||||
writer.close();
|
||||
print("generated messages file " + file.getAbsolutePath());
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue