Repository navigation
Conversation
draft() and TemplateMarkInterpreter.generate() take a Concerto
VocabularyManager and a locale, and draft each enum value as its term in
that locale: in variables, {{#join}}, and inside list, optional and if
blocks. The lookup falls back from a region to its language (as
VocabularyManager.getTerm does), then to English, then to the raw value.
Without a vocabulary, drafting is unchanged: draft() passes the locale on
only together with a vocabulary, since a locale alone would change how
{{#join}} formats lists. The vocabulary option is declared on the
interpreter, not in TypeScriptRuntime, whose GenerationOptions is copied
into generated template code.
Closes accordproject#10
Signed-off-by: rue19 <shrinjalik@gmail.com>
|
Thank you for this, @rue19 — er, without the handle: thank you for opening this pull request, and for the careful write-up. Enum values drafted as their vocabulary terms, with the locale fallback and no change without a vocabulary, is the kind of change this repository needs. What happens next: Dan Selman, who maintains this repository, has been asked to review it. The DCO check has passed. The other CI checks have not started yet, so a maintainer will need to approve them before they run. The review will come on this thread. Your notes on the {{#foreach}} bug and the English fallback are useful, and they will be part of the review. Posted automatically by Mira, an Accord Project agent. A maintainer will follow up; they make the decisions on this. |
Closes #10
Summary
draft()andTemplateMarkInterpreter.generate()now take a ConcertoVocabularyManagerand alocale. When both are given, each enum value is drafted as its term in that locale:Terms replace values in variables and in
{{#join}}, and insidelist,optionalandifblocks, nested ones included. The lookup goes from region to language (fr-CA, thenfr, asVocabularyManager.getTermalready does), then to English, then to the raw value. Drafting without a vocabulary is unchanged.Earlier work this builds on
This takes over #203 by @bhushan4work, which was closed after review, and follows that review's required changes item by item. Thanks for the groundwork, @bhushan4work: the locale fallback chain and the idea of handling
{{#join}}come from #203.TypeScriptRuntime.ts. I leftTypeScriptRuntime.tsuntouched. ItsGenerationOptionsis copied into generated template code (TypeScriptCompilationContext), and that code never sees a vocabulary. The interpreter declares its ownGenerationOptions, the runtime options plusvocabularyManager, so nothing has to be kept in step and the code generator gains no import.draft()passeslocaleandvocabularyManageron only when a vocabulary is given, and otherwise passes exactly{ now }as before. A test drafts{{#join}}with{ locale: 'fr' }and no vocabulary, and asserts the output equals drafting with{}(HEARTS and SPADES, notet). All 46 existing snapshots pass unchanged.player) drafts unchanged even when the vocabulary has a term for its property.join,list,optional,if, and anoptionalnested in alist, there are two tests each. With a vocabulary, the term appears and the raw value doesn't. Without one, the raw value appears. Term lookup works in all of them, so no block needed a fix.I also read #96 (the earlier vocabulary attempt), #217 (Duration and Period in the generation locale), which uses the same
localeoption but different code, and #216, whose open PRs #213 and #222 refactor this file. To keep a rebase onto those small, the change is one helper (enumTerm) plus a lookup before the existing drafting call at the three places a value is drafted. No existing function signature changes.Flags
{{#foreach}}is not covered. It fails onmainwith or without a vocabulary (TypeError: property.isPrimitive is not a function), andTemplateMarkInterpreter.test.ts:55already skips it as "currently broken". That's a separate bug, so I left it out of this PR. I'm happy to open an issue for it.fr-CA→fr→enchain, so a value with no term in the requested locale uses its English term before its raw identifier.AGENTS.mdasks not to hardcode English. If you'd rather stop at the requested locale and draft the raw value, it's a one-line change, and the fallback test documents the current behaviour.VocabularyManager. cicero-core doesn't load vocabularies from a template archive yet (template-archive#711), so that would be a follow-up.localedrafts the raw values, since there's no locale to look terms up in.How I tested
npm test(licence check, lint, build, Jest): 211 passed (193 before, plus 18 intest/Vocabulary.test.ts), 46 snapshots unchanged, 0 lint errors.npm run test:e2e: 6 passed.fr,fr-CA(the vocabulary file declaresfr-ca, the request usesfr-CA),en, andja, whose list format differs from English (ハート、スペード).localewithout a vocabulary, dropping the{{#join}}lookup, and dropping the English fallback each make at least one test fail.AI usage
I used an AI coding assistant for parts of this change. I reviewed, tested and can explain all of it.
Author Checklist
--signoffoption of git commit.mainfromfork:branchname