Skip to content

Commit 50aa71b

Browse files
docs-botCopilotheiskrCopilot
authored
Fix stray space after dot in \{\% data variables/reusables %} Liquid paths (#62897)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent fb18c68 commit 50aa71b

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ export function correctTranslatedContentStrings(
5858
'{%$1 data variables.$2$3',
5959
)
6060

61+
// Translators sometimes inserted a stray space right after a dot inside
62+
// a `{% data variables.X.Y %}` path (e.g. `{% data variables.product.
63+
// prodname_pages %}` or `{% data variables. product.prodname_pages %}`).
64+
// Liquid parses the space as ending the variable lookup early, breaking
65+
// the tag. Collapse the space back out. The English source never has
66+
// a space after a dot in a variable path, so this is safe globally.
67+
content = content.replace(
68+
/\{%(-?)\s*data\s+(?:variables|reusables)(?:\.\s*[A-Za-z0-9_-]+)+(?=\s*-?%\})/g,
69+
(path) => path.replace(/\.\s+/g, '.'),
70+
)
71+
6172
// The translation pipeline frequently splits Markdown bullet markers
6273
// (`*` and `-`) and table-cell pipes (`|`) onto their own line, with
6374
// the actual content pushed to the next line as deeply indented text.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,27 @@ describe('correctTranslatedContentStrings', () => {
16641664
expect(fix('{% data .reusables.foo.bar %}', 'zh')).toBe('{% data reusables.foo.bar %}')
16651665
})
16661666

1667+
test('fixes stray space after a dot inside {% data variables/reusables paths', () => {
1668+
// Translators sometimes inserted a stray space right after a dot in a
1669+
// multi-segment `variables.X.Y` / `reusables.X.Y` path (e.g. wrapping
1670+
// long lines mid-path). Liquid parses the space as ending the variable
1671+
// lookup early, breaking the tag. Confirmed in de-de, ja-jp, ru-ru.
1672+
expect(fix('{% data variables.product. prodname_pages %}', 'de')).toBe(
1673+
'{% data variables.product.prodname_pages %}',
1674+
)
1675+
expect(fix('{% data variables. product.prodname_pro %}', 'ja')).toBe(
1676+
'{% data variables.product.prodname_pro %}',
1677+
)
1678+
expect(fix('{% data variables.copilot. copilot_chat_short %}', 'ru')).toBe(
1679+
'{% data variables.copilot.copilot_chat_short %}',
1680+
)
1681+
expect(fix('{%- data reusables.foo. bar -%}', 'de')).toBe('{%- data reusables.foo.bar -%}')
1682+
// Already-correct input is left unchanged.
1683+
expect(fix('{% data variables.product.prodname_pages %}', 'de')).toBe(
1684+
'{% data variables.product.prodname_pages %}',
1685+
)
1686+
})
1687+
16671688
test('fixes singular variable / reusable in {% data paths', () => {
16681689
// `{% data variable.product.X %}` (singular) → `{% data variables.product.X %}`
16691690
expect(fix('{% data variable.product.prodname_container_registry %}', 'zh')).toBe(

0 commit comments

Comments
 (0)