Skip to content

Commit 3f23fab

Browse files
heiskrCopilot
andauthored
Extend translation Liquid corruption fixes to {% if %} tags (#60579)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 157df28 commit 3f23fab

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/languages/lib/correct-translation-content.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ export function correctTranslatedContentStrings(
4444
)
4545
content = content.replaceAll('{{ glosario.term }}', '{{ glossary.term }}')
4646
content = content.replaceAll('{{ glosario.description }}', '{{ glossary.description }}')
47-
// Catch "o" and "y/o" between any plan names in ifversion/elsif tags
47+
// Catch "o" and "y/o" between any plan names in ifversion/elsif/if tags
4848
content = content.replace(
49-
/\{%-? (?:ifversion|elsif) [^%]*?(?:\by\/o\b|\bo\b)[^%]*?%\}/g,
49+
/\{%-? (?:ifversion|elsif|if) [^%]*?(?:\by\/o\b|\bo\b)[^%]*?%\}/g,
5050
(match) => {
5151
return match.replace(/ y\/o /g, ' or ').replace(/ o /g, ' or ')
5252
},
5353
)
54-
// Spanish "no" for "not" in ifversion tags
55-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?\bno\b[^%]*?%\}/g, (match) => {
54+
// Spanish "no" for "not" in ifversion/elsif/if tags
55+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?\bno\b[^%]*?%\}/g, (match) => {
5656
return match.replace(/ no /g, ' not ')
5757
})
5858
// Translated for-loop keywords
@@ -205,8 +205,8 @@ export function correctTranslatedContentStrings(
205205
content = content.replaceAll('{% %de dados reusables.', '{% data reusables.')
206206
content = content.replaceAll('{% %de dados variables.', '{% data variables.')
207207
content = content.replaceAll('{% %móvel }', '{% mobile %}')
208-
// Catch "ou" between any plan names in ifversion/elsif tags
209-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?ou [^%]*?%\}/g, (match) => {
208+
// Catch "ou" between any plan names in ifversion/elsif/if tags
209+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?ou [^%]*?%\}/g, (match) => {
210210
return match.replace(/ ou /g, ' or ')
211211
})
212212
}
@@ -225,8 +225,8 @@ export function correctTranslatedContentStrings(
225225
// Stray Chinese `,则为` ("then") merged with `{%` before HTML: `,则为 {%<tag>` → `<tag>`
226226
// The regex consumes the `<` to avoid producing a double `<<`.
227227
content = content.replace(/ \{%</g, '<')
228-
// Catch "或" between any plan names in ifversion/elsif tags
229-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?[^%]*?%\}/g, (match) => {
228+
// Catch "或" between any plan names in ifversion/elsif/if tags
229+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?[^%]*?%\}/g, (match) => {
230230
return match.replace(/ /g, ' or ')
231231
})
232232
}
@@ -267,8 +267,8 @@ export function correctTranslatedContentStrings(
267267
content = content.replaceAll('{% ifversion ghec или fpt %}', '{% ifversion ghec or fpt %}')
268268
content = content.replaceAll('{% ghes или ghec %}', '{% ifversion ghes or ghec %}')
269269
content = content.replaceAll('{% elsif ghec или ghes %}', '{% elsif ghec or ghes %}')
270-
// Catch remaining "или" between any plan names in ifversion/elsif tags
271-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?или[^%]*?%\}/g, (match) => {
270+
// Catch remaining "или" between any plan names in ifversion/elsif/if tags
271+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?или[^%]*?%\}/g, (match) => {
272272
return match.replace(/ или /g, ' or ')
273273
})
274274
content = content.replaceAll('{% endif _%}', '{% endif %}')
@@ -364,10 +364,14 @@ export function correctTranslatedContentStrings(
364364
content = content.replaceAll('{% %brut }', '{% raw %}')
365365
content = content.replaceAll('{% redessiner %}', '{% endraw %}')
366366
content = content.replaceAll('{% données ', '{% data ')
367-
// Catch remaining "ou" between any plan names in ifversion/elsif tags
368-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?ou [^%]*?%\}/g, (match) => {
367+
// Catch remaining "ou" between any plan names in ifversion/elsif/if tags
368+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?ou [^%]*?%\}/g, (match) => {
369369
return match.replace(/ ou /g, ' or ')
370370
})
371+
// French guillemets «/» → " inside if/ifversion/elsif tags
372+
content = content.replace(/\{%-?\s*(?:if|ifversion|elsif)\s[^%]*?[«»][^%]*?%\}/g, (match) => {
373+
return match.replace(/«\s*/g, '"').replace(/\s*»/g, '"')
374+
})
371375
// French decimal comma in version numbers: `3,16` → `3.16`
372376
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?%\}/g, (match) => {
373377
return match.replace(/(\d),(\d)/g, '$1.$2')
@@ -408,8 +412,8 @@ export function correctTranslatedContentStrings(
408412
content = content.replaceAll('{% 기타 %}', '{% else %}')
409413
content = content.replaceAll('{% 참고 %}', '{% note %}')
410414
content = content.replaceAll('{% 원시 %}', '{% raw %}')
411-
// Catch "또는" between any plan names in ifversion/elsif tags
412-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?[^%]*?%\}/g, (match) => {
415+
// Catch "또는" between any plan names in ifversion/elsif/if tags
416+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?[^%]*?%\}/g, (match) => {
413417
return match.replace(/ /g, ' or ')
414418
})
415419

@@ -431,8 +435,8 @@ export function correctTranslatedContentStrings(
431435
content = content.replaceAll('{%-Daten-variables', '{%- data variables')
432436
content = content.replaceAll('{%- ifversion fpt oder ghec %}', '{%- ifversion fpt or ghec %}')
433437
content = content.replaceAll('{% ifversion fpt oder ghec %}', '{% ifversion fpt or ghec %}')
434-
// Catch remaining "oder" between any plan names in ifversion/elsif tags
435-
content = content.replace(/\{%-? (?:ifversion|elsif) [^%]*?oder [^%]*?%\}/g, (match) => {
438+
// Catch remaining "oder" between any plan names in ifversion/elsif/if tags
439+
content = content.replace(/\{%-? (?:ifversion|elsif|if) [^%]*?oder [^%]*?%\}/g, (match) => {
436440
return match.replace(/ oder /g, ' or ')
437441
})
438442
// Translated block tags

src/languages/tests/correct-translation-content.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ describe('correctTranslatedContentStrings', () => {
270270
expect(fix('{%- elsif fpt ou ghec %}', 'pt')).toBe('{%- elsif fpt or ghec %}')
271271
})
272272

273+
test('fixes ou → or in if tags', () => {
274+
expect(fix('{% if condition ou other %}', 'pt')).toBe('{% if condition or other %}')
275+
})
276+
273277
test('fixes fully translated reutilizáveis reusables path', () => {
274278
// `reutilizáveis` is Portuguese for "reusables"
275279
expect(fix('{% dados reutilizáveis.repositórios.reaction_list %}', 'pt')).toBe(
@@ -501,6 +505,19 @@ describe('correctTranslatedContentStrings', () => {
501505
expect(fix('{%- elsif fpt ou ghec %}', 'fr')).toBe('{%- elsif fpt or ghec %}')
502506
})
503507

508+
test('fixes ou → or in if tags', () => {
509+
expect(
510+
fix('{% if query.apiVersion == nil ou "2026-03-10" <= query.apiVersion %}', 'fr'),
511+
).toBe('{% if query.apiVersion == nil or "2026-03-10" <= query.apiVersion %}')
512+
})
513+
514+
test('fixes French guillemets « » → " in if/ifversion tags', () => {
515+
expect(
516+
fix('{% if query.apiVersion == nil ou « 2026-03-10 » <= query.apiVersion %}', 'fr'),
517+
).toBe('{% if query.apiVersion == nil or "2026-03-10" <= query.apiVersion %}')
518+
expect(fix('{% ifversion « ghec » %}', 'fr')).toBe('{% ifversion "ghec" %}')
519+
})
520+
504521
test('fixes translated block tags', () => {
505522
expect(fix('{% remarque %}', 'fr')).toBe('{% note %}')
506523
expect(fix('{%- remarque %}', 'fr')).toBe('{%- note %}')

0 commit comments

Comments
 (0)