Skip to content

feat: string message keys and named template parameters#4

Merged
cmelgarejo merged 5 commits intomainfrom
cmdash/codes-9kz
Feb 26, 2026
Merged

feat: string message keys and named template parameters#4
cmelgarejo merged 5 commits intomainfrom
cmdash/codes-9kz

Conversation

@cmelgarejo
Copy link
Member

Implements the full conversion from numeric message codes and positional template parameters to string message keys and named parameters as specified in docs/CONVERSION_PLAN.md.

Summary

  • Message keys: intstring (e.g. greeting.hello, error.not_found)
  • YAML: set is map[string]RawMessage; optional code per entry; group removed
  • Templates: {{0}}{{name}}; {{plural:count|item|items}}, {{num:amount}}, {{date:when}}
  • API: GetMessageWithCtx(ctx, msgKey string, params Params); Params = map[string]interface{}
  • LoadMessages: RawMessage.Key required with sys. prefix
  • Observer: OnMessageMissing(lang, msgKey string), OnTemplateIssue(lang, msgKey string, issue string)

All tests pass. No backward compatibility (lib not used elsewhere yet).

Made with Cursor

- Message lookup: numeric codes → string keys (e.g. greeting.hello, error.not_found)
- YAML set: map[string]RawMessage, optional per-entry code; removed Group
- Templates: positional params → named ({{name}}, {{plural:count|...}}, {{num:amount}}, {{date:when}})
- API: GetMessageWithCtx(ctx, msgKey string, params Params); Params = map[string]interface{}
- LoadMessages: RawMessage.Key required with sys. prefix; RuntimeKeyPrefix constant
- Observer/stats: OnMessageMissing(lang, msgKey string), OnTemplateIssue(lang, msgKey string, issue string)
- Tests, mocks, fuzz, bench, examples, README, CONTEXT7 docs updated

Implements docs/CONVERSION_PLAN.md

Made-with: Cursor
@cmelgarejo cmelgarejo self-assigned this Feb 26, 2026
- Code is optional and string: OptionalCode (YAML int/string), Message.Code and ErrorCode() string
- RawMessage.Code: any value, not unique; helpers CodeInt(), CodeString()
- Message.Key and ErrorKey() for API identifier when code is empty
- Constants CodeMissingMessage/Language as strings (msgcat.missing_*)
- New code.go: OptionalCode, UnmarshalYAML, CodeInt, CodeString
- Docs: 'Message and error codes' section (README, CONTEXT7, CONTEXT7_RETRIEVAL)
- Runnable examples: basic, load_messages, reload, strict, stats; http/metrics resources

Made-with: Cursor
…eased, duplicate-code test, YAML code type

Made-with: Cursor
…/merge

- CLDR plural forms: RawMessage.ShortForms/LongForms/PluralParam, internal/plural
- MessageDef type; CLI extract finds MessageDef literals and merges into source YAML
- Optional group (OptionalGroup) on Messages; CLI preserves in extract/merge
- cmd/msgcat: extract (keys + sync with MessageDef), merge (translate.<lang>.yaml)
- Examples: cldr_plural, msgdef. Docs: CLI_WORKFLOW_PLAN, CLDR_AND_GO_MESSAGES_PLAN
- README, CONTEXT7, CONTEXT7_RETRIEVAL, CHANGELOG updated

Made-with: Cursor
…, CI, tests

- LoadMessages: preserve ShortForms, LongForms, PluralParam on runtime messages
- Merge: treat target as translated when it has short_forms/long_forms (not only short/long)
- CI: Go 1.26, build ./cmd/...
- MIGRATION §10: new optional features (no migration required)
- Tests: LoadMessages_preservesShortFormsLongFormsPluralParam, Merge_preservesTargetWhenOnlyForms
- CHANGELOG: Fixed, Changed

Made-with: Cursor
@cmelgarejo cmelgarejo merged commit a8081ec into main Feb 26, 2026
1 check passed
@cmelgarejo cmelgarejo deleted the cmdash/codes-9kz branch February 26, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant