Skip to content

feat(goi18n): translate the messages by a bundle of go-i18n - #82

Merged
Insei merged 3 commits into
mainfrom
feat/goi18n
Oct 19, 2026
Merged

Insei merged 3 commits into
mainfrom
feat/goi18n

Conversation

@Insei

@Insei Insei commented Oct 19, 2026

Copy link
Copy Markdown
Owner

The module github.com/insei/valigo/integrations/goi18n over the chain of sources of #81:

tr := translator.New(translator.WithSources(goi18n.Source(bundle), translator.Embedded()))
v := valigo.New(valigo.WithTranslator(tr))
  • Your messages from the bundle, the built-in YAML for the rest; the IDs are the locale keys of valigo.
  • A message uses the named parameters of the rule ({{.max}}, {{.field}}) or the format verbs of the key (%d); the plural forms by the first integer argument.
  • The fallback of go-i18n to its default language isn't used: a German request gets the built-in German, not the English of the bundle.
  • goi18n.Messages(lang) exports the built-in messages with their plural forms — added back to a bundle they translate like the built-in ones (tested).

Docs: Translations → Sources of translations, the page Integrations → go-i18n with a checked program. CI, dependabot and the modules list have the module; 100% coverage.

The module needs the sources of the core, unreleased: its tag goes with v0.2.0 of the core.

Insei added 3 commits October 19, 2026 13:22
The module github.com/insei/valigo/integrations/goi18n: Source is a
translator.Source of a bundle, the messages use the named parameters of
the rules, {{.max}}, or the format verbs of the keys, the plural forms
are chosen by the first integer argument, the fallback of go-i18n to
another language is left to the next sources. Messages exports the
built-in messages of a language.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark diff: 7a18459 → 39c58da (10 runs)

goos: linux
goarch: amd64
pkg: github.com/insei/valigo
cpu: AMD EPYC 7763 64-Core Processor                
           │  base.txt   │              head.txt              │
           │   sec/op    │   sec/op     vs base               │
Validate-4   148.4n ± 1%   146.6n ± 1%  -1.21% (p=0.002 n=10)

           │  base.txt  │            head.txt            │
           │    B/op    │    B/op     vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

           │  base.txt  │            head.txt            │
           │ allocs/op  │ allocs/op   vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7a18459) to head (8a393a3).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #82   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           39        40    +1     
  Lines         1806      1865   +59     
=========================================
+ Hits          1806      1865   +59     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Insei
Insei merged commit b277714 into main Oct 19, 2026
7 checks passed
@Insei
Insei deleted the feat/goi18n branch October 19, 2026 10:26
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.

2 participants