safe check
This commit is contained in:
parent
9b0dc625fa
commit
60c05342b2
|
|
@ -1,3 +1,5 @@
|
||||||
|
var re_num = /^[.\d]+$/;
|
||||||
|
|
||||||
var original_lines = {};
|
var original_lines = {};
|
||||||
var translated_lines = {};
|
var translated_lines = {};
|
||||||
|
|
||||||
|
|
@ -11,6 +13,15 @@ function textNodesUnder(el) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canBeTranslated(node, text) {
|
||||||
|
if (!text) return false;
|
||||||
|
if (!node.parentElement) return false;
|
||||||
|
var parentType = node.parentElement.nodeName;
|
||||||
|
if (parentType == 'SCRIPT' || parentType == 'STYLE' || parentType == 'TEXTAREA') return false;
|
||||||
|
if (re_num.test(text)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function getTranslation(text) {
|
function getTranslation(text) {
|
||||||
if (!text) return undefined;
|
if (!text) return undefined;
|
||||||
|
|
||||||
|
|
@ -28,6 +39,9 @@ function getTranslation(text) {
|
||||||
|
|
||||||
function processTextNode(node) {
|
function processTextNode(node) {
|
||||||
var text = node.textContent.trim();
|
var text = node.textContent.trim();
|
||||||
|
|
||||||
|
if (!canBeTranslated(node, text)) return;
|
||||||
|
|
||||||
var tl = getTranslation(text);
|
var tl = getTranslation(text);
|
||||||
if (tl !== undefined) {
|
if (tl !== undefined) {
|
||||||
node.textContent = tl;
|
node.textContent = tl;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue