mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
🈯 fix: Accept Locale Count Placeholders in Locize Plural Forms (#17625)
This commit is contained in:
parent
a5cd61ef6e
commit
960f6daf6a
1 changed files with 13 additions and 3 deletions
|
|
@ -19,6 +19,7 @@ if (!baseDir || !currentDir) {
|
|||
|
||||
const errors = [];
|
||||
const placeholderPattern = /\{\{[^{}]+\}\}|\{[^{}]+\}|%[-+0-9.#]*[a-zA-Z]/g;
|
||||
const pluralSuffixPattern = /_(zero|one|two|few|many|other)$/;
|
||||
|
||||
async function jsonFiles(directory, relative = '') {
|
||||
const entries = await readdir(path.join(directory, relative), { withFileTypes: true });
|
||||
|
|
@ -51,8 +52,17 @@ function flatten(value, prefix = '', output = new Map()) {
|
|||
return output;
|
||||
}
|
||||
|
||||
function placeholders(value) {
|
||||
return (value.match(placeholderPattern) ?? []).sort().join('\u0000');
|
||||
/**
|
||||
* i18next passes `count` to every plural form, so a locale may spell it out where English
|
||||
* writes the number (`_one`: "1 chat") and omit it where its own grammar does not need it.
|
||||
*/
|
||||
function placeholders(value, key) {
|
||||
const matches = value.match(placeholderPattern) ?? [];
|
||||
const ignoreCount = pluralSuffixPattern.test(key);
|
||||
return matches
|
||||
.filter((match) => !ignoreCount || match.replace(/\s/g, '') !== '{{count}}')
|
||||
.sort()
|
||||
.join('\u0000');
|
||||
}
|
||||
|
||||
function boundaryWhitespace(value) {
|
||||
|
|
@ -102,7 +112,7 @@ if (currentSet.has(englishRelative)) {
|
|||
const baseline = baselineValuesByFile.get(relative)?.get(key);
|
||||
const changedSinceBaseline = baseline === undefined || baseline !== value;
|
||||
if (changedSinceBaseline && typeof source === 'string' && typeof value === 'string') {
|
||||
if (placeholders(source) !== placeholders(value)) {
|
||||
if (placeholders(source, key) !== placeholders(value, key)) {
|
||||
errors.push(`${relative}: placeholder mismatch with English for ${key}`);
|
||||
}
|
||||
if (value !== value.trim() && boundaryWhitespace(source) !== boundaryWhitespace(value)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue