diff --git a/assets/utils/h5p.js b/assets/utils/h5p.js index 58de630c..6cd6a715 100644 --- a/assets/utils/h5p.js +++ b/assets/utils/h5p.js @@ -994,37 +994,55 @@ function removeUntranslatables(field, name, parent, parentName) { function itemUntranslatable(property, value, parent) { switch (property) { case 'label': - return false; - break - case 'description': - return false; - break; case 'entity': - return false; - break; case 'explanation': + case 'example': return false; - break; + + case 'description': case 'placeholder': - return false; - break; + return value.trim().length === 0; + case 'default': if (typeof value !== 'string') { return true; } + // Remove empty strings. One example is Dictation, which has a space for + // a word separator setting. + if (value.trim().length === 0) { + return true; + } + // If this is a number, don't include it + if (!isNaN(value)) { + return true; + } if (!value.replaceAll(new RegExp(/<\/?[a-z][^>]*>/ig), '')) { // empty html tags return true; } - if (new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).test(value) === true || ['rgb(', 'hsv '].indexOf(value.substr(0, 4)) !== -1) { // color codes + + if ( + // 3 digit hex color codes + new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/).test(value) === true || + // 4 digit hex color codes incl. alpha channel + new RegExp(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/).test(value) === true || + // rgb(a) color codes, sloppy check + new RegExp(/^rgb(a)?(\()?[\d\s,\.\/%]+(\))?$/).test(value) === true || + // hsl(a) color codes, sloppy check + new RegExp(/^hsl(a)?(\()?[\d\s,\.\/%]+(\))?$/).test(value) === true || + // hwb color codes, sloppy check + new RegExp(/^hsv?(\()?[\d\s,\.\/%]+(\))?$/).test(value) === true || + // hwb color codes, sloppy check + new RegExp(/^hwb\([\w\d\s,\.\/%]+\)$/).test(value) === true + // Ignoring lab, oklab, lch, oklch, color() and other color spaces + ) { // color codes return true; } - if (languageCodes.indexOf(value.toLowerCase()) !== -1) { // language codes + if (languageCodes.indexOf(value) !== -1) { // language codes return true; } break default: return true; - break; } } diff --git a/assets/utils/utility/language-codes.js b/assets/utils/utility/language-codes.js index b892c6b1..0b1cab69 100644 --- a/assets/utils/utility/language-codes.js +++ b/assets/utils/utility/language-codes.js @@ -1 +1 @@ -module.exports = ["aa","ab","ae","af","ak","am","an","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de","dv","dz","ee","el","en","eo","es","et","eu","fa","ff","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","io","is","it","iu","ja","jv","ka","kg","ki","kj","kk","kl","km","kn","ko","kr","ks","ku","kv","kw","ky","la","lb","lg","li","ln","lo","lt","lu","lv","mg","mh","mi","mk","ml","mn","mr","ms","mt","my","na","nb","nd","ne","ng","nl","nn","no","nr","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt","qu","rm","rn","ro","ru","rw","sa","sc","sd","se","sg","si","sk","sl","sm","sn","so","sq","sr","ss","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh","zu","es-mx","pt-br","sma","sme","smj","zh-cn","zh-hans","zh-tw"]; +module.exports = ["aa","ab","ae","af","ak","am","an","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de","dv","dz","ee","el","en","eo","es","et","eu","fa","ff","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","io","is","it","iu","ja","jv","ka","kg","ki","kj","kk","kl","km","kn","ko","kr","ks","ku","kv","kw","ky","la","lb","lg","li","ln","lo","lt","lu","lv","mg","mh","mi","mk","ml","mn","mr","ms","mt","my","na","nb","nd","ne","ng","nl","nn","no","nr","nv","ny","oc","oj","om","os","pa","pi","pl","ps","pt","qu","rm","rn","ro","ru","rw","sa","sc","sd","se","sg","si","sk","sl","sm","sn","so","sq","sr","ss","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh","zu","es-mx","pt-br","sma","sme","smj","zh-cn","zh-hans","zh-tw"];