vue3-gettext
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -15,5 +15,2 @@ #!/usr/bin/env node | ||
var selector = require('gettext-extractor/dist/html/selector'); | ||
var content = require('gettext-extractor/dist/utils/content'); | ||
var parse5 = require('parse5'); | ||
var treeAdapter = require('parse5-htmlparser2-tree-adapter'); | ||
var typescript = require('typescript'); | ||
@@ -29,3 +26,2 @@ var child_process = require('child_process'); | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var treeAdapter__default = /*#__PURE__*/_interopDefaultLegacy(treeAdapter); | ||
@@ -79,3 +75,3 @@ var loadConfig = function (cliArgs) { | ||
validate.Validate.required.argument({ jsParser: jsParser }); | ||
return function (node, fileName, _, lineNumberStart) { | ||
return function (node, fileName, _, nodeLineNumberStart) { | ||
if (typeof node.tagName !== "string") { | ||
@@ -87,5 +83,6 @@ return; | ||
var _a, _b; | ||
var startLine = (_b = (_a = element.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.attrs[attr.name]) === null || _b === void 0 ? void 0 : _b.startLine; | ||
if (startLine) { | ||
lineNumberStart = lineNumberStart + startLine - 1; | ||
var lineNumberStart = nodeLineNumberStart; | ||
var attributeLineNumber = (_b = (_a = element.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.attrs[attr.name]) === null || _b === void 0 ? void 0 : _b.startLine; | ||
if (attributeLineNumber) { | ||
lineNumberStart += attributeLineNumber - 1; | ||
} | ||
@@ -99,16 +96,2 @@ jsParser.parseString(attr.value, fileName, { | ||
var getElementContent = function (element, options) { | ||
var content$1 = parse5.serialize(element, {}); | ||
// text nodes within template tags don't get serialized properly, this is a hack | ||
if (element.tagName === "template") { | ||
var docFragment_1 = treeAdapter__default["default"].createDocumentFragment(); | ||
element.content.childNodes.forEach(function (childNode) { | ||
treeAdapter__default["default"].appendChild(docFragment_1, childNode); | ||
}); | ||
content$1 = parse5.serialize(docFragment_1, {}); | ||
} | ||
// Un-escape characters that get escaped by parse5 | ||
content$1 = content$1.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); | ||
return content.normalizeContent(content$1, options); | ||
}; | ||
function embeddedJsExtractor(selector$1, jsParser) { | ||
@@ -124,14 +107,15 @@ validate.Validate.required.nonEmptyString({ selector: selector$1 }); | ||
if (selectors.anyMatch(element)) { | ||
var source = getElementContent(element, { | ||
trimWhiteSpace: false, | ||
preserveIndentation: true, | ||
replaceNewLines: false, | ||
var children = element.nodeName === "template" ? element.content.childNodes : element.childNodes; | ||
children.forEach(function (childNode) { | ||
var _a, _b; | ||
if (childNode.nodeName === "#text") { | ||
var currentNode = childNode; | ||
jsParser.parseString(currentNode.value, fileName, { | ||
scriptKind: typescript.ScriptKind.Deferred, | ||
lineNumberStart: ((_a = currentNode.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.startLine) | ||
? ((_b = currentNode.sourceCodeLocation) === null || _b === void 0 ? void 0 : _b.startLine) + lineNumberStart - 1 | ||
: lineNumberStart, | ||
}); | ||
} | ||
}); | ||
if (element.sourceCodeLocation && element.sourceCodeLocation.startLine) { | ||
lineNumberStart = lineNumberStart + element.sourceCodeLocation.startLine - 1; | ||
} | ||
jsParser.parseString(source, fileName, { | ||
scriptKind: typescript.ScriptKind.Deferred, | ||
lineNumberStart: lineNumberStart, | ||
}); | ||
} | ||
@@ -264,3 +248,7 @@ }; | ||
} | ||
else if (fp.endsWith(".js") || fp.endsWith(".ts") || fp.endsWith(".cjs") || fp.endsWith(".mjs")) { | ||
else if (fp.endsWith(".js") || | ||
fp.endsWith(".ts") || | ||
fp.endsWith(".cjs") || | ||
fp.endsWith(".mjs") || | ||
fp.endsWith(".tsx")) { | ||
jsParser.parseString(buffer, fp); | ||
@@ -267,0 +255,0 @@ } |
@@ -320,6 +320,11 @@ 'use strict'; | ||
} | ||
if (!arr[translationIndex]) { | ||
var str = arr[translationIndex]; | ||
if (!str) { | ||
// If the translation is empty, use the untranslated string. | ||
if (str === "") { | ||
return interp(untranslated, parameters); | ||
} | ||
throw new Error(msgid + " " + translationIndex + " " + language.current + " " + n); | ||
} | ||
return interp(arr[translationIndex], parameters); | ||
return interp(str, parameters); | ||
}; | ||
@@ -326,0 +331,0 @@ var getUntranslatedMsg = function () { |
{ | ||
"name": "vue3-gettext", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "Translate Vue 3 applications with gettext", | ||
@@ -26,4 +26,4 @@ "homepage": "https://jshmrtn.github.io/vue3-gettext/", | ||
"bin": { | ||
"vue-gettext-extract": "./dist/bin/gettext_extract.js", | ||
"vue-gettext-compile": "./dist/bin/gettext_compile.js" | ||
"vue-gettext-compile": "./dist/bin/gettext_compile.js", | ||
"vue-gettext-extract": "./dist/bin/gettext_extract.js" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106288
2182