UNPKG

@o3r/localization

Version:

This module provides a runtime dynamic language/translation support and debug tools.

52 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validators = void 0; exports.checkParentheses = checkParentheses; exports.checkOtherInPlural = checkOtherInPlural; /** * Check that the opened parentheses are correctly closed * @param str translation */ function checkParentheses(str) { const mapBrackets = { '[': ']', '{': '}', '(': ')' }; const closureBrackets = Object.keys(mapBrackets).map((k) => mapBrackets[k]); const stack = []; for (const ch of str) { if (mapBrackets[ch]) { stack.push(ch); } else if (closureBrackets.includes(ch)) { const tail = stack.pop(); if (!tail) { return false; } const closure = mapBrackets[tail]; if (closure !== ch) { return false; } } } return stack.length === 0; } /** * Check if the plural instruction always include an "other" case * @param str translation */ function checkOtherInPlural(str) { if (/{[^,]*, *plural *, *.*}/.test(str)) { return /{.*other.*}/.test(str); } return true; } /** * List of validators to apply to the translations */ exports.validators = [ checkParentheses, checkOtherInPlural ]; //# sourceMappingURL=validations.js.map