diff --git a/resources/report/bower.json b/resources/report/bower.json index d42c1f57..ff40aa52 100644 --- a/resources/report/bower.json +++ b/resources/report/bower.json @@ -33,6 +33,7 @@ "core-animated-pages": "Polymer/core-animated-pages#~0.5.1", "paper-toast": "Polymer/paper-toast#~0.5.1", "core-list": "WrinklyNinja/core-list#z-order-items", - "core-dropdown": "kysonic/core-dropdown#b2e3b0f37afec1f1447060d7988fb271f46566c2" + "core-dropdown": "kysonic/core-dropdown#b2e3b0f37afec1f1447060d7988fb271f46566c2", + "jed-gettext-parser": "~1.0.0" } } diff --git a/resources/report/js/jedGettextParser.js b/resources/report/js/jedGettextParser.js deleted file mode 100644 index 2bea67a0..00000000 --- a/resources/report/js/jedGettextParser.js +++ /dev/null @@ -1,210 +0,0 @@ -/* The text-encoding module is only strictly required for Node.js, and may not - be required in recent browsers, so don't specify it for them. */ -'use strict'; -(function(root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], factory); - } else if (typeof exports === 'object') { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = factory(require('text-encoding')); - } else { - // Browser globals - root.jedGettextParser = factory(); - } -}(this, function(textEncoding) { - /* Return what this module exports. */ - - if (textEncoding) { - var TextDecoder = textEncoding.TextDecoder; - } else { - var TextDecoder = window.TextDecoder; - } - - function Parser() { - this._littleEndian; - this._dataView; - this._encoding; - - this._originalOffset; - this._translationOffset; - } - Parser.prototype._MAGIC = 0x950412de; - - Parser.prototype._getEndianness = function() { - /* MO files can be big or little endian, independent of the source or current platform. Use DataView's optional get*** argument to set the endianness if necessary. */ - if (this._dataView.getUint32(0, true) == this._MAGIC) { - this._littleEndian = true; - } else if (this._dataView.getUint32(0, false) == this._MAGIC){ - this._littleEndian = false; - } else { - throw new Error('Not a gettext binary message catalog file.'); - } - } - - Parser.prototype._readTranslationPair = function(originalOffset, translationOffset) { - var length, position, idBytes, strBytes; - /* Get original byte array, that forms the key. */ - length = this._dataView.getUint32(originalOffset, this._littleEndian); - position = this._dataView.getUint32(originalOffset + 4, this._littleEndian); - try { - idBytes = new Uint8Array(this._dataView.buffer, position, length); - } catch(e) { - throw new Error('The given ArrayBuffer data is corrupt or incomplete.'); - } - - /* Get translation byte array, that forms the value. */ - length = this._dataView.getUint32(translationOffset, this._littleEndian); - position = this._dataView.getUint32(translationOffset + 4, this._littleEndian); - try { - strBytes = new Uint8Array(this._dataView.buffer, position, length); - } catch(e) { - throw new Error('The given ArrayBuffer data is corrupt or incomplete.'); - } - - return { - id: idBytes, - str: strBytes - }; - } - - Parser.prototype._parseHeader = function() { - /* Read translation header. This is stored as a msgstr where the msgid - is '', so it's the first entry in the translation block, since - strings are sorted. Assume that the header is in UTF-8. We only want - the language, encoding and plural forms values, which should all be - ASCII anyway. - */ - var msgBytes = this._readTranslationPair(this._originalOffset, this._translationOffset); - - var language, pluralForms; - if (msgBytes.id.byteLength == 0) { - var decoder = new TextDecoder(); - var str = decoder.decode(msgBytes.str); - - var headers = {}; - str.split("\n").forEach(function(line){ - /* Header format is like HTTP headers. */ - var parts = line.split(':'); - var key = parts.shift().trim(); - var value = parts.join(':').trim(); - headers[key] = value; - }); - - /* Get encoding if not given. */ - if (!this._encoding) { - var pos = headers['Content-Type'].indexOf('charset='); - - if (pos != -1 && pos + 8 < headers['Content-Type'].length) { - /* TextDecoder expects a lowercased encoding name. */ - this._encoding = headers['Content-Type'].substring(pos + 8).toLowerCase(); - } - if (!this._encoding) { - this._encoding = 'utf-8'; - } - } - - /* Get language from header. */ - language = headers['Language']; - - /* Get plural forms from header. */ - pluralForms = headers['Plural-Forms']; - } - - return { - '': { - 'domain': '', - 'lang': language, - 'plural_forms': pluralForms, - } - } - } - - Parser.prototype._splitPlurals = function(msgid, msgstr) { - /* Need to handle plurals. Don't need to handle contexts, because Jed - expects the context-msgid strings to be its keys. However, plural - translations must be split into an array of strings. Jed only wants - the first part of a plural as its key. */ - return { - id: msgid.split('\u0000')[0], - str: msgstr.split('\u0000') - } - } - - Parser.prototype.parse = function(buffer, encoding) { - - /* A mo file can be empty apart from its magic, revision, strings count, - offsets and hash table size, but fields for these must all exist, so - verify the file is large enough. */ - if (buffer.byteLength < 28) { - throw new Error('The given ArrayBuffer is too small to hold a valid .mo file.'); - } - - this._dataView = new DataView(buffer); - this._encoding = encoding; - - this._getEndianness(); - - /* Get size and offsets. Skip the revision and hash table, they're - unnecessary. */ - var stringsCount = this._dataView.getUint32(8, this._littleEndian); - this._originalOffset = this._dataView.getUint32(12, this._littleEndian); - this._translationOffset = this._dataView.getUint32(16, this._littleEndian); - - /* Parse header for info, and use it to create the Jed locale_data - object 'header'. */ - var jedLocaleData = this._parseHeader(); - - /* Create a TextDecoder for encoding conversion. */ - try { - var decoder = new TextDecoder(this._encoding); - } catch(e) { - throw new Error("The encoding label provided ('" + this._encoding + "') is invalid."); - } - - /* Now get translations. */ - var originalOffset = this._originalOffset + 8; - var translationOffset = this._translationOffset + 8; - for (var i = 1; i < stringsCount; ++i) { - var msgBytes = this._readTranslationPair(originalOffset, translationOffset); - var msg = this._splitPlurals( decoder.decode(msgBytes.id), decoder.decode(msgBytes.str) ); - - jedLocaleData[msg.id] = [].concat(msg.str); - - originalOffset += 8; - translationOffset += 8; - } - - return jedLocaleData; - } - - return { - - mo: { - parse: function(buffer, options) { - - /* Leave the encoding undefined if no options are given. */ - options = options || { domain: 'messages' }; - options.domain = options.domain || 'messages'; - - if (buffer && buffer.byteLength == 0) { - throw new Error('Given ArrayBuffer is empty.'); - } - - if (!buffer || Object.prototype.toString.call(buffer) != '[object ArrayBuffer]') { - throw new Error('First argument must be an ArrayBuffer.'); - } - - var parser = new Parser(); - var messages = parser.parse(buffer, options.encoding); - - messages[''].domain = options.domain; - var locale_data = {}; - locale_data[options.domain] = messages; - return locale_data; - } - } - }; -})); diff --git a/resources/report/js/l10n.js b/resources/report/js/l10n.js index 5ac74a78..3929463d 100644 --- a/resources/report/js/l10n.js +++ b/resources/report/js/l10n.js @@ -3,7 +3,7 @@ (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. - define(['bower_components/Jed/jed', 'js/jedGettextParser'], factory); + define(['bower_components/Jed/jed', 'bower_components/jed-gettext-parser/jedGettextParser'], factory); } else { // Browser globals root.amdWeb = factory(root.jed, root.jedGettextParser); diff --git a/src/archive.py b/src/archive.py index af3e8f40..858a28c6 100644 --- a/src/archive.py +++ b/src/archive.py @@ -134,12 +134,13 @@ def createAppArchive(archive_path): os.makedirs( os.path.join(temp_path, 'resources', 'report') ) os.makedirs( os.path.join(temp_path, 'resources', 'report', 'bower_components', 'marked', 'lib') ) os.makedirs( os.path.join(temp_path, 'resources', 'report', 'bower_components', 'Jed') ) + os.makedirs( os.path.join(temp_path, 'resources', 'report', 'bower_components', 'jed-gettext-parser') ) os.makedirs( os.path.join(temp_path, 'resources', 'report', 'js') ) shutil.copy( os.path.join('..', 'resources', 'report', 'index.html'), os.path.join(temp_path, 'resources', 'report') ) shutil.copy( os.path.join('..', 'resources', 'report', 'bower_components', 'marked', 'lib', 'marked.js'), os.path.join(temp_path, 'resources', 'report', 'bower_components', 'marked', 'lib') ) shutil.copy( os.path.join('..', 'resources', 'report', 'bower_components', 'Jed', 'jed.js'), os.path.join(temp_path, 'resources', 'report', 'bower_components', 'Jed') ) + shutil.copy( os.path.join('..', 'resources', 'report', 'bower_components', 'jed-gettext-parser', 'jedGettextParser.js'), os.path.join(temp_path, 'resources', 'report', 'bower_components', 'jed-gettext-parser') ) shutil.copytree( os.path.join('..', 'resources', 'report', 'fonts'), os.path.join(temp_path, 'resources', 'report', 'fonts') ) - shutil.copy( os.path.join('..', 'resources', 'report', 'js', 'jedGettextParser.js'), os.path.join(temp_path, 'resources', 'report', 'js') ) shutil.copy( os.path.join('..', 'resources', 'report', 'js', 'l10n.js'), os.path.join(temp_path, 'resources', 'report', 'js') ) shutil.copy( os.path.join('..', 'resources', 'report', 'js', 'plugin.js'), os.path.join(temp_path, 'resources', 'report', 'js') ) shutil.copy( os.path.join('..', 'resources', 'report', 'js', 'filters.js'), os.path.join(temp_path, 'resources', 'report', 'js') ) diff --git a/src/installer.nsi b/src/installer.nsi index 3af29aa0..0c08ee50 100644 --- a/src/installer.nsi +++ b/src/installer.nsi @@ -327,10 +327,11 @@ FunctionEnd File "..\resources\report\bower_components\marked\lib\marked.js" SetOutPath "$INSTDIR\resources\report\bower_components\Jed" File "..\resources\report\bower_components\Jed\jed.js" + SetOutPath "$INSTDIR\resources\report\bower_components\jed-gettext-parser" + File "..\resources\report\bower_components\jed-gettext-parser\jedGettextParser.js" SetOutPath "$INSTDIR\resources\report\fonts" File "..\resources\report\fonts\*" SetOutPath "$INSTDIR\resources\report\js" - File "..\resources\report\js\jedGettextParser.js" File "..\resources\report\js\l10n.js" File "..\resources\report\js\plugin.js" File "..\resources\report\js\filters.js" @@ -482,8 +483,8 @@ FunctionEnd Delete "$INSTDIR\resources\report\index.html" Delete "$INSTDIR\resources\report\bower_components\marked\lib\marked.js" Delete "$INSTDIR\resources\report\bower_components\Jed\jed.js" + Delete "$INSTDIR\resources\report\bower_components\jed-gettext-parser\jedGettextParser.js" RMDir /r "$INSTDIR\resources\report\fonts" - Delete "$INSTDIR\resources\report\js\jedGettextParser.js" Delete "$INSTDIR\resources\report\js\l10n.js" Delete "$INSTDIR\resources\report\js\plugin.js" Delete "$INSTDIR\resources\report\js\filters.js"