Skip to content

Commit 4345ec3

Browse files
heiskrCopilot
andauthored
fix(translations): add 6 Liquid corruption correction patterns (#62019)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62fd8e5 commit 4345ec3

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,42 @@ export function correctTranslatedContentStrings(
882882
'在{% data variables.product.prodname_dotcom_the_website %}或{% data variables.enterprise.data_residency_site %}{% endif %}上的企业{% ifversion ghec %}进行通信。',
883883
'的企业{% ifversion ghec %}在{% data variables.product.prodname_dotcom_the_website %}或{% data variables.enterprise.data_residency_site %}{% endif %}进行通信。',
884884
)
885+
886+
// [per-file] actions/azure-vnet-creating-network-configuration-prereqs.md:
887+
// `{% ifversion ghec%}` closes prematurely with `{% endif %}` before the
888+
// `{% else %}` branch, leaving `{% else %}` as an orphan. Reorder to:
889+
// `{% ifversion ghec %}...{% else %}...{% endif %}`.
890+
content = content.replaceAll(
891+
'可以{% ifversion ghec%}在企业或组织级别{% endif %}在组织级别{% else %}创建网络配置,从而将 Azure 虚拟网络 (VNET) 用于专用网络。',
892+
'可以{% ifversion ghec %}在企业或组织级别{% else %}在组织级别{% endif %}创建网络配置,从而将 Azure 虚拟网络 (VNET) 用于专用网络。',
893+
)
894+
895+
// [per-file] gated-features/ghas-ghec.md: `prodname_team` and `prodname_ghe_cloud`
896+
// escaped outside the `{% ifversion fpt or ghec %}` block, and the branches are
897+
// swapped. `{% endif %}` appears before `{% elsif ghes %}`. Restore structure:
898+
// `{% ifversion fpt or ghec %}...team...ghe_cloud{% elsif ghes %}...ghe_server{% endif %}`.
899+
content = content.replaceAll(
900+
'适用于{% data variables.product.prodname_team %}上的{% ifversion fpt or ghec %}账户以及{% data variables.product.prodname_ghe_server %}{% endif %}上的{% data variables.product.prodname_ghe_cloud %}{% elsif ghes %}账户。',
901+
'适用于{% ifversion fpt or ghec %}{% data variables.product.prodname_team %}和{% data variables.product.prodname_ghe_cloud %}上的账户{% elsif ghes %}{% data variables.product.prodname_ghe_server %}上的账户{% endif %}。',
902+
)
903+
904+
// [per-file] scim/after-you-configure-saml.md: `{% ifversion fpt or ghec %}` opener
905+
// was dropped before `{% data variables.product.github %}`, leaving `{% else %}` as
906+
// an orphan. The `{% ifversion %}` token was then misplaced after `{% endif %}`.
907+
content = content.replaceAll(
908+
'{% data variables.product.github %}{% else %}{% data variables.location.product_location_enterprise %}{% endif %} 上的{% ifversion fpt or ghec %}企业资源',
909+
'{% ifversion fpt or ghec %}{% data variables.product.github %} 上的企业资源{% else %}{% data variables.location.product_location_enterprise %}{% endif %}',
910+
)
911+
912+
// [per-file] enterprise_user_management/consider-usernames-for-external-authentication.md:
913+
// The second `{% ifversion ghec %}` opener (before `product.github`) was dropped,
914+
// leaving an orphan `{% elsif ghes %}` and a dangling `{% ifversion ghec %}` at end.
915+
// `企业中` ("in your enterprise") is GHEC-only in the source, so it belongs inside the
916+
// `{% ifversion ghec %}` branch, not before it.
917+
content = content.replaceAll(
918+
'企业中 {% data variables.product.github %}{% elsif ghes %} 上 {% data variables.location.product_location %}{% endif %} 上每个新个人帐户 {% ifversion ghec %} 的用户名。',
919+
'{% ifversion ghec %}企业中 {% data variables.product.github %}{% elsif ghes %} 上 {% data variables.location.product_location %}{% endif %} 上每个新个人帐户的用户名。',
920+
)
885921
}
886922

887923
if (context.code === 'ru') {
@@ -1104,6 +1140,14 @@ export function correctTranslatedContentStrings(
11041140
return match.replace(/(\d)\s*о/g, '$10').replace(/о\s*(\d)/g, '0$1')
11051141
})
11061142

1143+
// `{% PLAN PLAN ifversion %}` — plan name duplicated before `ifversion`; word-order swap.
1144+
// The universal whitespace fix converts `{ % ghes ghes ifversion %}` to this form first.
1145+
// Collapse the duplicate plan name and swap to canonical `{% ifversion PLAN %}`.
1146+
content = content.replace(
1147+
/\{%(-?)\s*(fpt|ghec|ghes|ghae|ghecom)\s+\2\s+ifversion\s*(-?)%\}/g,
1148+
'{%$1 ifversion $2 $3%}',
1149+
)
1150+
11071151
// Word-order swap: translator placed plan name BEFORE `ifversion`, e.g.
11081152
// `{% ghes ifversion %}` → `{% ifversion ghes %}`,
11091153
// `{% ghes ifversion < 3,14 %}` → `{% ifversion ghes < 3.14 %}`
@@ -1777,6 +1821,13 @@ export function correctTranslatedContentStrings(
17771821
'auf selbst-gehosteten Runnern ausführen.{% data variables.product.prodname_dependabot %}',
17781822
'auf selbst-gehosteten Runnern ausführen.{% endif %}',
17791823
)
1824+
// [per-file] enterprise_installation/hardware-considerations-all-platforms.md:
1825+
// `{% ifversion ghes %}` opener was stripped before "200 GB", leaving `{% else %}`
1826+
// as an orphan. Restore the opener immediately before the "200 GB" text.
1827+
content = content.replaceAll(
1828+
'werden 200 GB auf dem Stammdateisystem verfügbar sein. Die verbleibenden 200GB{% else %}',
1829+
'werden {% ifversion ghes %}200 GB auf dem Stammdateisystem verfügbar sein. Die verbleibenden 200GB{% else %}',
1830+
)
17801831
}
17811832

17821833
// --- Generic fixes (all languages) ---

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,76 @@ describe('correctTranslatedContentStrings', () => {
577577
expect(fix('{%- 捕获 myvar -%}', 'zh')).toBe('{%- capture myvar -%}')
578578
expect(fix('{%- 捕获myvar %}', 'zh')).toBe('{%- capture myvar %}')
579579
})
580+
581+
test('[per-file] azure-vnet: premature endif leaves orphan else', () => {
582+
function fixAt(content: string, code: string, relativePath: string) {
583+
return correctTranslatedContentStrings(content, '', {
584+
code,
585+
relativePath,
586+
skipOrphanStripping: true,
587+
})
588+
}
589+
const path = 'data/reusables/actions/azure-vnet-creating-network-configuration-prereqs.md'
590+
const broken =
591+
'可以{% ifversion ghec%}在企业或组织级别{% endif %}在组织级别{% else %}创建网络配置,从而将 Azure 虚拟网络 (VNET) 用于专用网络。'
592+
const fixed =
593+
'可以{% ifversion ghec %}在企业或组织级别{% else %}在组织级别{% endif %}创建网络配置,从而将 Azure 虚拟网络 (VNET) 用于专用网络。'
594+
expect(fixAt(broken, 'zh', path)).toBe(fixed)
595+
// unchanged if already correct
596+
expect(fixAt(fixed, 'zh', path)).toBe(fixed)
597+
})
598+
599+
test('[per-file] ghas-ghec: scrambled ifversion with stray elsif after endif', () => {
600+
function fixAt(content: string, code: string, relativePath: string) {
601+
return correctTranslatedContentStrings(content, '', {
602+
code,
603+
relativePath,
604+
skipOrphanStripping: true,
605+
})
606+
}
607+
const path = 'data/reusables/gated-features/ghas-ghec.md'
608+
const broken =
609+
'适用于{% data variables.product.prodname_team %}上的{% ifversion fpt or ghec %}账户以及{% data variables.product.prodname_ghe_server %}{% endif %}上的{% data variables.product.prodname_ghe_cloud %}{% elsif ghes %}账户。'
610+
const fixed =
611+
'适用于{% ifversion fpt or ghec %}{% data variables.product.prodname_team %}和{% data variables.product.prodname_ghe_cloud %}上的账户{% elsif ghes %}{% data variables.product.prodname_ghe_server %}上的账户{% endif %}。'
612+
expect(fixAt(broken, 'zh', path)).toBe(fixed)
613+
expect(fixAt(fixed, 'zh', path)).toBe(fixed)
614+
})
615+
616+
test('[per-file] scim/after-you-configure-saml: ifversion opener dropped leaving orphan else', () => {
617+
function fixAt(content: string, code: string, relativePath: string) {
618+
return correctTranslatedContentStrings(content, '', {
619+
code,
620+
relativePath,
621+
skipOrphanStripping: true,
622+
})
623+
}
624+
const path = 'data/reusables/scim/after-you-configure-saml.md'
625+
const broken =
626+
'{% data variables.product.github %}{% else %}{% data variables.location.product_location_enterprise %}{% endif %} 上的{% ifversion fpt or ghec %}企业资源'
627+
const fixed =
628+
'{% ifversion fpt or ghec %}{% data variables.product.github %} 上的企业资源{% else %}{% data variables.location.product_location_enterprise %}{% endif %}'
629+
expect(fixAt(broken, 'zh', path)).toBe(fixed)
630+
expect(fixAt(fixed, 'zh', path)).toBe(fixed)
631+
})
632+
633+
test('[per-file] consider-usernames: ifversion ghec opener dropped leaving orphan elsif', () => {
634+
function fixAt(content: string, code: string, relativePath: string) {
635+
return correctTranslatedContentStrings(content, '', {
636+
code,
637+
relativePath,
638+
skipOrphanStripping: true,
639+
})
640+
}
641+
const path =
642+
'data/reusables/enterprise_user_management/consider-usernames-for-external-authentication.md'
643+
const broken =
644+
'企业中 {% data variables.product.github %}{% elsif ghes %} 上 {% data variables.location.product_location %}{% endif %} 上每个新个人帐户 {% ifversion ghec %} 的用户名。'
645+
const fixed =
646+
'{% ifversion ghec %}企业中 {% data variables.product.github %}{% elsif ghes %} 上 {% data variables.location.product_location %}{% endif %} 上每个新个人帐户的用户名。'
647+
expect(fixAt(broken, 'zh', path)).toBe(fixed)
648+
expect(fixAt(fixed, 'zh', path)).toBe(fixed)
649+
})
580650
})
581651

582652
// ─── RUSSIAN (ru) ──────────────────────────────────────────────────
@@ -836,6 +906,17 @@ describe('correctTranslatedContentStrings', () => {
836906
'{% ifversion enterprise-licensing-language %}licenses{% else %}licensed seats{% endif %}',
837907
)
838908
})
909+
910+
test('fixes doubled plan name before ifversion (ghes ghes ifversion → ifversion ghes)', () => {
911+
// `{% ghes ghes ifversion %}` — plan name appears twice before `ifversion`;
912+
// collapses the duplicate and swaps to canonical `{% ifversion PLAN %}`.
913+
expect(fix('{% ghes ghes ifversion %}', 'ru')).toBe('{% ifversion ghes %}')
914+
expect(fix('{%- ghec ghec ifversion %}', 'ru')).toBe('{%- ifversion ghec %}')
915+
// Does not affect normal word-order swap (single plan name)
916+
expect(fix('{% ghes ifversion %}', 'ru')).toBe('{% ifversion ghes %}')
917+
// Unchanged when already correct
918+
expect(fix('{% ifversion ghes %}', 'ru')).toBe('{% ifversion ghes %}')
919+
})
839920
})
840921

841922
// ─── FRENCH (fr) ───────────────────────────────────────────────────
@@ -1399,6 +1480,24 @@ describe('correctTranslatedContentStrings', () => {
13991480
'{%- data variables.product.github %}',
14001481
)
14011482
})
1483+
1484+
test('[per-file] hardware-considerations-all-platforms: ifversion ghes opener stripped', () => {
1485+
function fixAt(content: string, code: string, relativePath: string) {
1486+
return correctTranslatedContentStrings(content, '', {
1487+
code,
1488+
relativePath,
1489+
skipOrphanStripping: true,
1490+
})
1491+
}
1492+
const path = 'data/reusables/enterprise_installation/hardware-considerations-all-platforms.md'
1493+
const broken =
1494+
'werden 200 GB auf dem Stammdateisystem verfügbar sein. Die verbleibenden 200GB{% else %}100GB sind auf dem Stammdateisystem verfügbar.'
1495+
const fixed =
1496+
'werden {% ifversion ghes %}200 GB auf dem Stammdateisystem verfügbar sein. Die verbleibenden 200GB{% else %}100GB sind auf dem Stammdateisystem verfügbar.'
1497+
expect(fixAt(broken, 'de', path)).toBe(fixed)
1498+
// unchanged if already correct
1499+
expect(fixAt(fixed, 'de', path)).toBe(fixed)
1500+
})
14021501
})
14031502

14041503
describe('Generic fixes (all languages)', () => {

0 commit comments

Comments
 (0)