mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
Enhance translation regex to support multiple default message formats
This commit is contained in:
@@ -6,7 +6,7 @@ const { getFiles } = require('./helpers');
|
|||||||
|
|
||||||
const readFilePromise = promisify(fs.readFile);
|
const readFilePromise = promisify(fs.readFile);
|
||||||
|
|
||||||
const translationRegex = /_t\(\s*['"]([^'"]+)['"]\s*,\s*\{\s*defaultMessage\s*:\s*['"]([^'"]+)['"]\s*\}/g;
|
const translationRegex = /_t\(\s*['"]([^'"]+)['"]\s*,\s*\{\s*defaultMessage\s*:\s*(?:'([^'\\]*(?:\\.[^'\\]*)*)'|"([^"\\]*(?:\\.[^"\\]*)*)"|\`([^`\\]*(?:\\.[^`\\]*)*(?:\{[^}]*\}[^`\\]*(?:\\.[^`\\]*)*)*)\`)(?:\s*,\s*[^}]*)*\s*\}/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} file
|
* @param {string} file
|
||||||
@@ -20,7 +20,8 @@ async function extractTranslationsFromFile(file) {
|
|||||||
let match;
|
let match;
|
||||||
|
|
||||||
while ((match = translationRegex.exec(content)) !== null) {
|
while ((match = translationRegex.exec(content)) !== null) {
|
||||||
const [_, key, defaultText] = match;
|
const [_, key, singleQuotedText, doubleQuotedText, templateLiteral] = match;
|
||||||
|
const defaultText = singleQuotedText || doubleQuotedText || templateLiteral;
|
||||||
translations[key] = defaultText;
|
translations[key] = defaultText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user