feat(message-compiler): support escape sequence#2394
Conversation
📝 WalkthroughWalkthroughThis PR adds backslash-based escape sequence support for special characters ({, }, @, |, \) across the message compiler (tokenizer, parser, grammar) and updates documentation (EN/JP/ZH) and tests; escape sequences are supported from v12 onward. Changes
Sequence DiagramsequenceDiagram
participant Input as Message Input
participant Tokenizer
participant Parser
participant TextProc as Text Processing
Input->>Tokenizer: Raw message with escapes (e.g., "foo\@bar")
Note over Tokenizer: Detect backslash + special char
Tokenizer->>Tokenizer: Consume escape as single token
Tokenizer->>Parser: Emit token stream
Parser->>TextProc: Process TEXT tokens
Note over TextProc: Apply fromTextEscapeSequence mapping (\@ → @)
TextProc-->>Input: Rendered text output (e.g., "foo@bar")
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying vue-i18n-next with
|
| Latest commit: |
850eea1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://21561a96.vue-i18n-next.pages.dev |
| Branch Preview URL: | https://feat-at-mark-support.vue-i18n-next.pages.dev |
Size ReportBundles
Usages
|
@intlify/core
@intlify/core-base
@intlify/devtools-types
@intlify/message-compiler
petite-vue-i18n
@intlify/shared
vue-i18n
@intlify/vue-i18n-core
commit: |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/jp/guide/essentials/number.md`:
- Around line 50-52: Update the broken link in
docs/jp/guide/essentials/number.md: replace the target
../../../api/vue/interfaces/ComponentCustomProperties.md#n with
../../../api/v11/injection.md#n (the anchor `#n` is correct and comes from the
heading "### $n(value)"); ensure the markdown link surrounding `$n` now points
to ../../../api/v11/injection.md#n and verify the destination file exists and
the heading generates the same anchor.
- Around line 167-168: Replace the broken API reference link found in the note
block that mentions `i18n-n` (the `[!NOTE]` paragraph) so it points to the
DefineNumberFormat anchor in the v11 API general documentation instead of the
non-existent type-aliases path; update the link target to reference the
DefineNumberFormat section using the `#definenumberformat` anchor in the API v11
general doc.
In `@docs/jp/guide/essentials/syntax.md`:
- Around line 337-343: The table row for the pipe escape is inconsistent: the
escape column shows `\|` but the result column also shows `\|`, while the
rendered example should be a literal pipe `|`. Update the table row that uses
the escape symbol `\|` so its result cell is `|` (and keep the description
"リテラルのパイプ"), ensuring the escape→result mapping reads "`\|` → `|`".
In `@docs/zh/guide/advanced/composition.md`:
- Line 65: The API link for the Composer reference is incorrect: update the
markdown link in the sentence referencing useI18n/Composer to point to
../../../api/v11/composition.md instead of
../../../api/general/interfaces/Composer.md, and ensure the anchors for t, d,
and n (e.g., ../../../api/v11/composition.md#t, `#d`, `#n`) are used where
appropriate so the Composer (useI18n) API, including t/d/n examples, resolves
correctly.
In `@docs/zh/guide/essentials/syntax.md`:
- Around line 337-343: The table row for the pipe escape is inconsistent: the
"结果" column currently shows `\|` but the example renders a literal `|`; update
the table row so the result column is `|` (no backslash) to match rendered
behavior, i.e., edit the row containing `\|` in the diff so its second cell is
`|` and keep the first cell as `\|` to show the escape sequence.
| > [!TIP] | ||
| > `$n` にはいくつかのオーバーロードがあります。これらのオーバーロードについては、[API リファレンス](../../api/vue/interfaces/ComponentCustomProperties.md#n) を参照してください。 | ||
| > `$n` にはいくつかのオーバーロードがあります。これらのオーバーロードについては、[API リファレンス](../../../api/vue/interfaces/ComponentCustomProperties.md#n) を参照してください。 | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, locate the ComponentCustomProperties.md file
fd -t f "ComponentCustomProperties.md"Repository: intlify/vue-i18n
Length of output: 42
🏁 Script executed:
# Once located, examine the file for headings related to $n
cat -n docs/api/vue/interfaces/ComponentCustomProperties.md | head -100Repository: intlify/vue-i18n
Length of output: 144
🏁 Script executed:
# Search for ComponentCustomProperties anywhere in the repo
fd -t f "ComponentCustomProperties"Repository: intlify/vue-i18n
Length of output: 42
🏁 Script executed:
# Check the api directory structure
find docs/api -type d | head -20Repository: intlify/vue-i18n
Length of output: 81
🏁 Script executed:
# Search for files with similar patterns
fd -t f ".*\.md$" docs/api | head -30Repository: intlify/vue-i18n
Length of output: 212
🏁 Script executed:
# Search for $n references in API docs
rg -n '\$n' docs/api/v11/Repository: intlify/vue-i18n
Length of output: 2088
🏁 Script executed:
# Check the injection.md file since it was mentioned in the learning
head -100 docs/api/v11/injection.mdRepository: intlify/vue-i18n
Length of output: 2675
🏁 Script executed:
# Check the actual file being reviewed
cat -n docs/jp/guide/essentials/number.md | sed -n '45,60p'Repository: intlify/vue-i18n
Length of output: 643
Fix the broken link path and verify the anchor.
The link targets a non-existent file path. The correct path should be ../../../api/v11/injection.md#n (not ../../../api/vue/interfaces/ComponentCustomProperties.md#n). The API documentation is structured under docs/api/v11/, and $n overloads are documented in injection.md. The anchor #n is correct for that file, as VitePress generates it from the heading ### $n(value).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/jp/guide/essentials/number.md` around lines 50 - 52, Update the broken
link in docs/jp/guide/essentials/number.md: replace the target
../../../api/vue/interfaces/ComponentCustomProperties.md#n with
../../../api/v11/injection.md#n (the anchor `#n` is correct and comes from the
heading "### $n(value)"); ensure the markdown link surrounding `$n` now points
to ../../../api/v11/injection.md#n and verify the destination file exists and
the heading generates the same anchor.
| > [!NOTE] | ||
| > サポートされているスコープ付きスロットの完全なリストおよびその他の `i18n-n` プロパティは、[API リファレンス](../../api/general/type-aliases/NumberFormat.md) にあります。 | ||
| > サポートされているスコープ付きスロットの完全なリストおよびその他の `i18n-n` プロパティは、[API リファレンス](../../../api/general/type-aliases/NumberFormat.md) にあります。 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm the file exists and inspect headings for anchor correctness.
ls -la docs/api/general/type-aliases/NumberFormat.md
rg -n -C2 '^#{1,6}\s' docs/api/general/type-aliases/NumberFormat.mdRepository: intlify/vue-i18n
Length of output: 238
🏁 Script executed:
#!/bin/bash
# Search for NumberFormat in the docs directory
fd -t f 'NumberFormat' docs/ 2>/dev/null | head -20
# Explore the api directory structure
echo "=== docs/api directory structure ==="
find docs/api -type d | head -20
# Search for files that mention NumberFormat
echo "=== Files mentioning NumberFormat ==="
rg -l 'NumberFormat' docs/ | head -20Repository: intlify/vue-i18n
Length of output: 792
🏁 Script executed:
#!/bin/bash
# List files in docs/api/v11
echo "=== docs/api/v11 structure ==="
find docs/api/v11 -type f | sort
# Search for NumberFormat in docs/api/v11
echo "=== Files in docs/api/v11 mentioning NumberFormat ==="
rg -l 'NumberFormat' docs/api/v11/Repository: intlify/vue-i18n
Length of output: 424
🏁 Script executed:
#!/bin/bash
# Find the NumberFormat heading in general.md
rg -n -C3 'NumberFormat' docs/api/v11/general.md | head -40
# Also check for any headings near NumberFormat
echo "=== Headings in general.md ==="
rg -n '^#{1,6}\s' docs/api/v11/general.mdRepository: intlify/vue-i18n
Length of output: 4146
🏁 Script executed:
#!/bin/bash
# Search for NumberFormat headings
rg -n '^##\s.*NumberFormat' docs/api/v11/general.md
# Get context around DefineNumberFormat heading
echo "=== Context around DefineNumberFormat ==="
rg -n -A5 '^## DefineNumberFormat' docs/api/v11/general.md
# Check if there's a base NumberFormat heading anywhere
rg -n '^##\s+NumberFormat$' docs/api/v11/general.mdRepository: intlify/vue-i18n
Length of output: 243
🏁 Script executed:
#!/bin/bash
# Search for NumberFormat type definitions across API docs
rg -n 'interface NumberFormat|type NumberFormat|export.*NumberFormat' docs/api/v11/
# Also check the Japanese version to see if there's a pattern
echo "=== Japanese API docs ==="
rg -n 'NumberFormat' docs/jp/api/v11/general.md | head -10Repository: intlify/vue-i18n
Length of output: 5436
🏁 Script executed:
#!/bin/bash
# Check current links in the Japanese number.md file
echo "=== Current links in docs/jp/guide/essentials/number.md ==="
rg '\[.*\]\(' docs/jp/guide/essentials/number.md | head -10
# Verify the relative path calculation
echo "=== Verifying path structure ==="
echo "From: docs/jp/guide/essentials/number.md"
echo "To: docs/api/v11/general.md"
echo "Relative path should be: ../../../api/v11/general.md"
# Check if there are any NumberFormat-related links in other docs
echo "=== NumberFormat links in other documentation ==="
rg 'api/v11.*NumberFormat|general\.md.*NumberFormat' docs/Repository: intlify/vue-i18n
Length of output: 894
Fix broken API reference link path.
The link at lines 167-168 points to a non-existent file path. The docs/api/general/type-aliases/ directory does not exist; API documentation is located under docs/api/v11/. The correct link should be ../../../api/v11/general.md#definenumberformat (targeting the DefineNumberFormat section).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/jp/guide/essentials/number.md` around lines 167 - 168, Replace the
broken API reference link found in the note block that mentions `i18n-n` (the
`[!NOTE]` paragraph) so it points to the DefineNumberFormat anchor in the v11
API general documentation instead of the non-existent type-aliases path; update
the link target to reference the DefineNumberFormat section using the
`#definenumberformat` anchor in the API v11 general doc.
| | エスケープ | 結果 | 説明 | | ||
| |-----------|------|------| | ||
| | `\{` | `{` | リテラルの開き波括弧 | | ||
| | `\}` | `}` | リテラルの閉じ波括弧 | | ||
| | `\@` | `@` | リテラルのアットマーク | | ||
| | `\|` | `\|` | リテラルのパイプ | | ||
| | `\\` | `\` | リテラルのバックスラッシュ | |
There was a problem hiding this comment.
Escape table row for \| should likely render |.
The example output shows a literal pipe, but the table lists \| as the result. Consider aligning the table with the actual render.
✅ Suggested doc fix
-| `\|` | `\|` | リテラルのパイプ |
+| `\|` | `|` | リテラルのパイプ |📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| | エスケープ | 結果 | 説明 | | |
| |-----------|------|------| | |
| | `\{` | `{` | リテラルの開き波括弧 | | |
| | `\}` | `}` | リテラルの閉じ波括弧 | | |
| | `\@` | `@` | リテラルのアットマーク | | |
| | `\|` | `\|` | リテラルのパイプ | | |
| | `\\` | `\` | リテラルのバックスラッシュ | | |
| | エスケープ | 結果 | 説明 | | |
| |-----------|------|------| | |
| | `\{` | `{` | リテラルの開き波括弧 | | |
| | `\}` | `}` | リテラルの閉じ波括弧 | | |
| | `\@` | `@` | リテラルのアットマーク | | |
| | `\|` | `|` | リテラルのパイプ | | |
| | `\\` | `\` | リテラルのバックスラッシュ | |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/jp/guide/essentials/syntax.md` around lines 337 - 343, The table row for
the pipe escape is inconsistent: the escape column shows `\|` but the result
column also shows `\|`, while the rendered example should be a literal pipe `|`.
Update the table row that uses the escape symbol `\|` so its result cell is `|`
(and keep the description "リテラルのパイプ"), ensuring the escape→result mapping reads
"`\|` → `|`".
| 你必须在 `<script setup>` 的顶部调用 `useI18n`。 | ||
|
|
||
| `useI18n` 返回一个 Composer 实例。Composer 实例提供翻译 API(如 `t` 函数)以及 `locale` 和 `fallbackLocale` 等属性,就像 VueI18n 实例一样。有关 Composer 实例的更多信息,请参阅 [API 参考](../../api/general/interfaces/Composer.md)。 | ||
| `useI18n` 返回一个 Composer 实例。Composer 实例提供翻译 API(如 `t` 函数)以及 `locale` 和 `fallbackLocale` 等属性,就像 VueI18n 实例一样。有关 Composer 实例的更多信息,请参阅 [API 参考](../../../api/general/interfaces/Composer.md)。 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Locate Composer.md and confirm the relative path target exists.
echo "=== Searching for Composer.md files ==="
fd -a 'Composer\.md' docs
echo ""
echo "=== Path verification ==="
# Show the resolved path for this file and the target to verify relative depth.
python3 - <<'PY'
import os
src = 'docs/zh/guide/advanced/composition.md'
target = 'docs/api/general/interfaces/Composer.md'
print('Source file exists:', os.path.exists(src))
print('Target file exists:', os.path.exists(target))
src_dir = os.path.dirname(src)
resolved_path = os.path.normpath(os.path.join(src_dir, '../../../api/general/interfaces/Composer.md'))
print('Resolved path from source:', resolved_path)
print('Resolved path exists:', os.path.exists(resolved_path))
PY
echo ""
echo "=== Directory structure of docs/api ==="
find docs/api -type d | head -20
echo ""
echo "=== Check if Composer.md exists and its location ==="
find docs -name 'Composer.md' -type fRepository: intlify/vue-i18n
Length of output: 389
🏁 Script executed:
#!/bin/bash
# Check what's in docs/api/v11
echo "=== Contents of docs/api/v11 ==="
ls -la docs/api/v11
echo ""
echo "=== Search for files mentioning Composer ==="
rg 'Composer' docs --type md -l | head -20
echo ""
echo "=== Check git history for this file to see if path changed ==="
git log --oneline -n 10 -- docs/zh/guide/advanced/composition.md
echo ""
echo "=== Show recent changes to this file ==="
git show HEAD:docs/zh/guide/advanced/composition.md | head -100Repository: intlify/vue-i18n
Length of output: 3539
🏁 Script executed:
#!/bin/bash
echo "=== Search for 'Composer' in docs/api/v11/composition.md ==="
rg 'Composer|^## .*\bt\b|^## .*\bd\b|^## .*\bn\b' docs/api/v11/composition.md | head -30
echo ""
echo "=== Search for 'Composer' in docs/api/v11/general.md ==="
rg 'Composer|^## .*\bt\b|^## .*\bd\b|^## .*\bn\b' docs/api/v11/general.md | head -30
echo ""
echo "=== List all heading levels in docs/api/v11/composition.md ==="
rg '^\#+\s+' docs/api/v11/composition.md | head -40
echo ""
echo "=== Check for interface definitions ==="
rg 'interface Composer|class Composer' docs/api/v11/*.mdRepository: intlify/vue-i18n
Length of output: 5724
Fix incorrect API reference path.
The link path ../../../api/general/interfaces/Composer.md is broken—the file does not exist. The Composer API documentation is located at ../../../api/v11/composition.md instead. The anchors #t, #d, and #n already exist in that file.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/zh/guide/advanced/composition.md` at line 65, The API link for the
Composer reference is incorrect: update the markdown link in the sentence
referencing useI18n/Composer to point to ../../../api/v11/composition.md instead
of ../../../api/general/interfaces/Composer.md, and ensure the anchors for t, d,
and n (e.g., ../../../api/v11/composition.md#t, `#d`, `#n`) are used where
appropriate so the Composer (useI18n) API, including t/d/n examples, resolves
correctly.
| | 转义 | 结果 | 描述 | | ||
| |------|------|------| | ||
| | `\{` | `{` | 字面量左大括号 | | ||
| | `\}` | `}` | 字面量右大括号 | | ||
| | `\@` | `@` | 字面量 @ 符号 | | ||
| | `\|` | `\|` | 字面量管道符 | | ||
| | `\\` | `\` | 字面量反斜杠 | |
There was a problem hiding this comment.
Escape table row for \| looks inconsistent with the example output.
The “结果” column shows \|, but the example renders a literal |. The result should likely be | (without the backslash) to match behavior.
✅ Suggested doc fix
-| `\|` | `\|` | 字面量管道符 |
+| `\|` | `|` | 字面量管道符 |📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| | 转义 | 结果 | 描述 | | |
| |------|------|------| | |
| | `\{` | `{` | 字面量左大括号 | | |
| | `\}` | `}` | 字面量右大括号 | | |
| | `\@` | `@` | 字面量 @ 符号 | | |
| | `\|` | `\|` | 字面量管道符 | | |
| | `\\` | `\` | 字面量反斜杠 | | |
| | 转义 | 结果 | 描述 | | |
| |------|------|------| | |
| | `\{` | `{` | 字面量左大括号 | | |
| | `\}` | `}` | 字面量右大括号 | | |
| | `\@` | `@` | 字面量 @ 符号 | | |
| | `\|` | `|` | 字面量管道符 | | |
| | `\\` | `\` | 字面量反斜杠 | |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/zh/guide/essentials/syntax.md` around lines 337 - 343, The table row for
the pipe escape is inconsistent: the "结果" column currently shows `\|` but the
example renders a literal `|`; update the table row so the result column is `|`
(no backslash) to match rendered behavior, i.e., edit the row containing `\|` in
the diff so its second cell is `|` and keep the first cell as `\|` to show the
escape sequence.
Summary by CodeRabbit
New Features
Documentation