first commit

This commit is contained in:
Ichitux
2026-04-05 03:08:53 +02:00
commit 1082d36c12
28015 changed files with 3767672 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TranslationParserError = void 0;
class TranslationParserError extends Error {
constructor(message, position, translationString) {
super(message);
this.name = 'TranslationParserError';
this.position = position;
this.translationString = translationString;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, TranslationParserError);
}
}
}
exports.TranslationParserError = TranslationParserError;

View File

@@ -0,0 +1,218 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.decodeHtmlEntities = void 0;
const commonEntities = {
' ': '\u00A0',
'&': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&apos;': "'",
'&copy;': '©',
'&reg;': '®',
'&trade;': '™',
'&hellip;': '…',
'&ndash;': '',
'&mdash;': '—',
'&lsquo;': '\u2018',
'&rsquo;': '\u2019',
'&sbquo;': '\u201A',
'&ldquo;': '\u201C',
'&rdquo;': '\u201D',
'&bdquo;': '\u201E',
'&dagger;': '†',
'&Dagger;': '‡',
'&bull;': '•',
'&prime;': '',
'&Prime;': '″',
'&lsaquo;': '',
'&rsaquo;': '',
'&sect;': '§',
'&para;': '¶',
'&middot;': '·',
'&ensp;': '\u2002',
'&emsp;': '\u2003',
'&thinsp;': '\u2009',
'&euro;': '€',
'&pound;': '£',
'&yen;': '¥',
'&cent;': '¢',
'&curren;': '¤',
'&times;': '×',
'&divide;': '÷',
'&minus;': '',
'&plusmn;': '±',
'&ne;': '≠',
'&le;': '≤',
'&ge;': '≥',
'&asymp;': '≈',
'&equiv;': '≡',
'&infin;': '∞',
'&int;': '∫',
'&sum;': '∑',
'&prod;': '∏',
'&radic;': '√',
'&part;': '∂',
'&permil;': '‰',
'&deg;': '°',
'&micro;': 'µ',
'&larr;': '←',
'&uarr;': '↑',
'&rarr;': '→',
'&darr;': '↓',
'&harr;': '↔',
'&crarr;': '↵',
'&lArr;': '⇐',
'&uArr;': '⇑',
'&rArr;': '⇒',
'&dArr;': '⇓',
'&hArr;': '⇔',
'&alpha;': 'α',
'&beta;': 'β',
'&gamma;': 'γ',
'&delta;': 'δ',
'&epsilon;': 'ε',
'&zeta;': 'ζ',
'&eta;': 'η',
'&theta;': 'θ',
'&iota;': 'ι',
'&kappa;': 'κ',
'&lambda;': 'λ',
'&mu;': 'μ',
'&nu;': 'ν',
'&xi;': 'ξ',
'&omicron;': 'ο',
'&pi;': 'π',
'&rho;': 'ρ',
'&sigma;': 'σ',
'&tau;': 'τ',
'&upsilon;': 'υ',
'&phi;': 'φ',
'&chi;': 'χ',
'&psi;': 'ψ',
'&omega;': 'ω',
'&Alpha;': 'Α',
'&Beta;': 'Β',
'&Gamma;': 'Γ',
'&Delta;': 'Δ',
'&Epsilon;': 'Ε',
'&Zeta;': 'Ζ',
'&Eta;': 'Η',
'&Theta;': 'Θ',
'&Iota;': 'Ι',
'&Kappa;': 'Κ',
'&Lambda;': 'Λ',
'&Mu;': 'Μ',
'&Nu;': 'Ν',
'&Xi;': 'Ξ',
'&Omicron;': 'Ο',
'&Pi;': 'Π',
'&Rho;': 'Ρ',
'&Sigma;': 'Σ',
'&Tau;': 'Τ',
'&Upsilon;': 'Υ',
'&Phi;': 'Φ',
'&Chi;': 'Χ',
'&Psi;': 'Ψ',
'&Omega;': 'Ω',
'&Agrave;': 'À',
'&Aacute;': 'Á',
'&Acirc;': 'Â',
'&Atilde;': 'Ã',
'&Auml;': 'Ä',
'&Aring;': 'Å',
'&AElig;': 'Æ',
'&Ccedil;': 'Ç',
'&Egrave;': 'È',
'&Eacute;': 'É',
'&Ecirc;': 'Ê',
'&Euml;': 'Ë',
'&Igrave;': 'Ì',
'&Iacute;': 'Í',
'&Icirc;': 'Î',
'&Iuml;': 'Ï',
'&ETH;': 'Ð',
'&Ntilde;': 'Ñ',
'&Ograve;': 'Ò',
'&Oacute;': 'Ó',
'&Ocirc;': 'Ô',
'&Otilde;': 'Õ',
'&Ouml;': 'Ö',
'&Oslash;': 'Ø',
'&Ugrave;': 'Ù',
'&Uacute;': 'Ú',
'&Ucirc;': 'Û',
'&Uuml;': 'Ü',
'&Yacute;': 'Ý',
'&THORN;': 'Þ',
'&szlig;': 'ß',
'&agrave;': 'à',
'&aacute;': 'á',
'&acirc;': 'â',
'&atilde;': 'ã',
'&auml;': 'ä',
'&aring;': 'å',
'&aelig;': 'æ',
'&ccedil;': 'ç',
'&egrave;': 'è',
'&eacute;': 'é',
'&ecirc;': 'ê',
'&euml;': 'ë',
'&igrave;': 'ì',
'&iacute;': 'í',
'&icirc;': 'î',
'&iuml;': 'ï',
'&eth;': 'ð',
'&ntilde;': 'ñ',
'&ograve;': 'ò',
'&oacute;': 'ó',
'&ocirc;': 'ô',
'&otilde;': 'õ',
'&ouml;': 'ö',
'&oslash;': 'ø',
'&ugrave;': 'ù',
'&uacute;': 'ú',
'&ucirc;': 'û',
'&uuml;': 'ü',
'&yacute;': 'ý',
'&thorn;': 'þ',
'&yuml;': 'ÿ',
'&iexcl;': '¡',
'&iquest;': '¿',
'&fnof;': 'ƒ',
'&circ;': 'ˆ',
'&tilde;': '˜',
'&OElig;': 'Œ',
'&oelig;': 'œ',
'&Scaron;': 'Š',
'&scaron;': 'š',
'&Yuml;': 'Ÿ',
'&ordf;': 'ª',
'&ordm;': 'º',
'&macr;': '¯',
'&acute;': '´',
'&cedil;': '¸',
'&sup1;': '¹',
'&sup2;': '²',
'&sup3;': '³',
'&frac14;': '¼',
'&frac12;': '½',
'&frac34;': '¾',
'&spades;': '♠',
'&clubs;': '♣',
'&hearts;': '♥',
'&diams;': '♦',
'&loz;': '◊',
'&oline;': '‾',
'&frasl;': '',
'&weierp;': '℘',
'&image;': '',
'&real;': '',
'&alefsym;': 'ℵ'
};
const entityPattern = new RegExp(Object.keys(commonEntities).map(entity => entity.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'g');
const decodeHtmlEntities = text => text.replace(entityPattern, match => commonEntities[match]).replace(/&#(\d+);/g, (_, num) => String.fromCharCode(parseInt(num, 10))).replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
exports.decodeHtmlEntities = decodeHtmlEntities;

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _TranslationParserError = require("./TranslationParserError.js");
Object.keys(_TranslationParserError).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _TranslationParserError[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _TranslationParserError[key];
}
});
});
var _htmlEntityDecoder = require("./htmlEntityDecoder.js");
Object.keys(_htmlEntityDecoder).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _htmlEntityDecoder[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _htmlEntityDecoder[key];
}
});
});
var _tokenizer = require("./tokenizer.js");
Object.keys(_tokenizer).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _tokenizer[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _tokenizer[key];
}
});
});
var _renderTranslation = require("./renderTranslation.js");
Object.keys(_renderTranslation).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _renderTranslation[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _renderTranslation[key];
}
});
});

View File

@@ -0,0 +1,114 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.renderTranslation = void 0;
var _react = _interopRequireDefault(require("react"));
var _TranslationParserError = require("./TranslationParserError.js");
var _tokenizer = require("./tokenizer.js");
var _htmlEntityDecoder = require("./htmlEntityDecoder.js");
const renderDeclarationNode = (declaration, children, childDeclarations) => {
const {
type,
props = {}
} = declaration;
if (props.children && Array.isArray(props.children) && childDeclarations) {
const {
children: _childrenToRemove,
...propsWithoutChildren
} = props;
return _react.default.createElement(type, propsWithoutChildren, ...children);
}
if (children.length === 0) {
return _react.default.createElement(type, props);
}
if (children.length === 1) {
return _react.default.createElement(type, props, children[0]);
}
return _react.default.createElement(type, props, ...children);
};
const renderTranslation = (translation, declarations = []) => {
if (!translation) {
return [];
}
const tokens = (0, _tokenizer.tokenize)(translation);
const result = [];
const stack = [];
const literalTagNumbers = new Set();
const getCurrentDeclarations = () => {
if (stack.length === 0) {
return declarations;
}
const parentFrame = stack[stack.length - 1];
if (parentFrame.declaration.props?.children && Array.isArray(parentFrame.declaration.props.children)) {
return parentFrame.declaration.props.children;
}
return parentFrame.declarations;
};
tokens.forEach(token => {
switch (token.type) {
case 'Text':
{
const decoded = (0, _htmlEntityDecoder.decodeHtmlEntities)(token.value);
const targetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
targetArray.push(decoded);
}
break;
case 'TagOpen':
{
const {
tagNumber
} = token;
const currentDeclarations = getCurrentDeclarations();
const declaration = currentDeclarations[tagNumber];
if (!declaration) {
literalTagNumbers.add(tagNumber);
const literalText = `<${tagNumber}>`;
const targetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
targetArray.push(literalText);
break;
}
stack.push({
tagNumber,
children: [],
position: token.position,
declaration,
declarations: currentDeclarations
});
}
break;
case 'TagClose':
{
const {
tagNumber
} = token;
if (literalTagNumbers.has(tagNumber)) {
const literalText = `</${tagNumber}>`;
const literalTargetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
literalTargetArray.push(literalText);
literalTagNumbers.delete(tagNumber);
break;
}
if (stack.length === 0) {
throw new _TranslationParserError.TranslationParserError(`Unexpected closing tag </${tagNumber}> at position ${token.position}`, token.position, translation);
}
const frame = stack.pop();
if (frame.tagNumber !== tagNumber) {
throw new _TranslationParserError.TranslationParserError(`Mismatched tags: expected </${frame.tagNumber}> but got </${tagNumber}> at position ${token.position}`, token.position, translation);
}
const element = renderDeclarationNode(frame.declaration, frame.children, frame.declarations);
const elementTargetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
elementTargetArray.push(element);
}
break;
}
});
if (stack.length > 0) {
const unclosed = stack[stack.length - 1];
throw new _TranslationParserError.TranslationParserError(`Unclosed tag <${unclosed.tagNumber}> at position ${unclosed.position}`, unclosed.position, translation);
}
return result;
};
exports.renderTranslation = renderTranslation;

View File

@@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.tokenize = void 0;
const tokenize = translation => {
const tokens = [];
let position = 0;
let currentText = '';
const flushText = () => {
if (currentText) {
tokens.push({
type: 'Text',
value: currentText,
position: position - currentText.length
});
currentText = '';
}
};
while (position < translation.length) {
const char = translation[position];
if (char === '<') {
const tagMatch = translation.slice(position).match(/^<(\d+)>/);
if (tagMatch) {
flushText();
tokens.push({
type: 'TagOpen',
value: tagMatch[0],
position,
tagNumber: parseInt(tagMatch[1], 10)
});
position += tagMatch[0].length;
} else {
const closeTagMatch = translation.slice(position).match(/^<\/(\d+)>/);
if (closeTagMatch) {
flushText();
tokens.push({
type: 'TagClose',
value: closeTagMatch[0],
position,
tagNumber: parseInt(closeTagMatch[1], 10)
});
position += closeTagMatch[0].length;
} else {
currentText += char;
position += 1;
}
}
} else {
currentText += char;
position += 1;
}
}
flushText();
return tokens;
};
exports.tokenize = tokenize;