Repository navigation
docs(kb): fix the <T> example that the CLI rejects - #608
Closed
Kevin-Liu-01 wants to merge 2 commits into
Closed
Kevin-Liu-01 wants to merge 2 commits into
Kevin-Liu-01 wants to merge 2 commits into
Conversation
The inline example in "Can I do i18n without translation files?" put
{itemCount} and a {discount && ...} conditional straight inside <T>.
gt 2.26.1 stops validate, generate and translate with "<T> component
has children that could change at runtime". The example now wraps the
values in <Num> and the conditional in <Branch>, and a sentence says
why.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolved conflicts in kb/en-US/i18n-without-translation-files.mdx (moved from kb/ on main; the example fix applies unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Covered by #650 (merged): it replaced the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
The "Translating code directly" example in the KB article "Can I do i18n without translation files?" puts
{itemCount}and{discount && <p>{discount}% discount applied!</p>}directly inside<T>. The CLI does not accept dynamic children in<T>, and the<T>reference says to wrap them in variable components (react/reference/components/t.mdx:31). A reader who copies the example cannot translate it.Checked with gt 2.26.1 on the article's example (
kb/i18n-without-translation-files.mdx:50-64), in a project with gt-react 11.4.11 inpackage.json:npx gt validateexits 1:<T> component has children that could change at runtime. Use a variable component like <Var> to ensure this content is translated., quoting{itemCount}and the{discount && ...}line.npx gt generateandnpx gt translate --dry-runexit 1 withCLI tool encountered 1 syntax errors while scanning for translatable content. To ignore these errors, re-run with --ignore-errors.Changes
kb/i18n-without-translation-files.mdx: the example wraps the item count in<Num>and replaces the&&conditional with<Branch branch={discount > 0} true={...} />, which renders the discount line only when there is a discount. The discount is also a<Num>. A new sentence after the example says that runtime values go in variable components, conditional content goes in<Branch>, and the CLI stops with an error otherwise.Size: 1 file, +8/-3.
Test plan
src/CheckoutSummary.tsxand byte-identical to the code block:npx gt validateprints "Success! Found 1 translatable entries for gt-react", andnpx gt generateandnpx gt translate --dry-runexit 0.initializeGTandGTProvider, English):discount={10}gives "10% discount applied!",discount={0}and nodiscountleave the line out, anditemCount={1200}renders "1,200". The<Branch>code in@generaltranslation/react-core11.4.11 renders the prop named afterString(branch)and otherwise its children, sofalserenders nothing here.Run on this branch (
k/docs-kb-t-exampleat 755ad83, on origin/main f93de7c), inscripts/afternpm ci:validate-links: all links validvalidate:unsafe-htmlandvalidate:callouts: 546 MDX files each, cleanvalidate:reference-links: 500 MDX files against 301 reference symbol aliases, cleanvalidate:structure,validate:blog-orderandvalidate:kb(5 articles): cleantest: 7 scripts, 155 cases passedtypecheck: cleanjavascript:URLs in MDX finds nothing, and the changed article parses with the MDX parser the validators use.Open PRs #595 (publish dates) and #597 (wording later in the article) edit the same file. Both merge cleanly with this branch (
git merge-tree).🤖 Generated with Claude Code