Repository navigation
feat(translator): look the translations up in a chain of sources - #81
Merged
Merged
Conversation
translator.Source translates a key in one language or reports that it
has none; WithSources looks every language of a request up in the
sources in order, so your messages go before the built-in ones and
the built-in ones translate the rest. Embedded is the source of the
YAML locales of valigo. The named parameters of the messages, {"max":
64}, reach the sources for the named placeholders of go-i18n and others:
the helper of the validator passes them, the interfaces are unchanged.
Contributor
Benchmark diff:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 38 39 +1
Lines 1784 1806 +22
=========================================
+ Hits 1784 1806 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The ground of the adapters of external i18n libraries, the YAML of valigo stays the default:
translator.Source:Translate(lang, key, args, params) (string, bool)— a translation of a key in one language, or none.translator.WithSources(a, b, ...): for every language of a request in order, the first source with a translation wins —WithSources(goi18n.Source(bundle), translator.Embedded())is your messages in go-i18n and the built-in ones for the rest; a German request gets the built-in German before your English.translator.Embedded(opts...): the built-in YAML locales as a source; the in-memory storage implementsSource.max,min,field...) reach the sources:Msg.ErrorusesErrorParamsof the helper of the validator when it has one, the translator of valigo passes them byTParams.shared.Helper,translator.TranslatorandStorageROare unchanged; custom helpers and translators work as before.The valid path is untouched, the change is in the building of the errors. 100% coverage.