Conversation
There was a problem hiding this comment.
Pull Request Overview
Integrates the vorlif/spreak library as a replacement for golang.org/x/text to power translations across the service. Key changes include wiring up a spreak Bundle and Localizer via FX, updating middleware and context to use the new localizer, and extending error types to capture and localize hint arguments.
- Introduce
spreak.Bundleandspreak.Localizerin place ofx/textprinters - Revamp the FX module to load
.pofiles and provide translation bundles - Migrate all context, middleware, error wrappers, and auth errors to use spreak APIs
Reviewed Changes
Copilot reviewed 26 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| translation/translator.go | Swapped x/text printer for spreak Localizer and bundle |
| translation/module.go | Updated FX module to provide spreak.Bundle with locale files |
| translation/middleware.go | Middleware now injects spreak.Localizer into request context |
| translation/install/translation.mk | Added make target for xspreak extraction |
| translation/install/locales.go | Provided embed FS group provider for locales |
| translation/error_wrapper_test.go | Tests for storing and retrieving hint args in errors |
| translation/error_wrapper.go | Wrapped errors to include JSON-encoded translation args |
| translation/error_processor_test.go | Tests LocalizeErrorHint error processor functionality |
| translation/error_processor.go | Error processor for localizing error hints with spreak |
| translation/context.go | Replaced translators with Localizer in context |
| module/module.go | Added Option pattern for Module customization |
| http/input.go | Updated input handler to use Localizer for validation errors |
| http/errhttp/error_processor.go | Changed ErrorPipeline to ordered map with ranks |
| graphql/server.go | Refactored error presenter to use pipeline.Process |
| go.mod | Bumped dependencies, added spreak |
| examples/blog/go.mod | Updated indirect x/text and x/sync versions |
| errors/hint.go | Changed error hint API to use localize.Singular |
| errors/erruser/error.go | Updated user error creation to accept localize.Singular |
| errors/errsys/error.go | Updated system error creation to accept localize.Singular |
| errors/error.go | Removed old Message function stub |
| auth/module.go | Integrated locales FS provider into auth module |
| auth/locales/uk-UA/auth.po | Added Ukrainian translations for auth messages |
| auth/locales/locales.go | Provided embed FS group for auth translation domain |
| auth/locales/auth.pot | Added POT template for auth translations |
| auth/auth.go | Annotated auth errors with translation domain and locales |
| Makefile | Added translation-extract target for auth package |
Comments suppressed due to low confidence (4)
translation/translator.go:36
- [nitpick] The function name
Eis not descriptive. Consider renaming it to something likeMarkForExtractionorExtractMsgIDso its purpose is clearer.
func E(txt localize.Singular) string {
translation/module.go:42
- Building a slice of
interface{}and passing it tospreak.WithLanguage(tags...)will not compile. Change the slice type to[]language.Tagso you can spread it directly into the variadic function.
tags := make([]interface{}, 0, len(cfg.Locales))
auth/auth.go:20
- The
erruser.Newsignature now expects alocalize.Singularhint, not a plain string. Wrap literal hints inlocalize.Singular(...)to match the new API.
erruser.New("invalid access token", "Please provide a valid access token"),
errors/errsys/error.go:10
- Calls to
errsys.New(e.g., inHideInternalError) still pass plain strings for thehintparameter. Update those calls to convert strings intolocalize.Singular.
func New(code string, hint localize.Singular) error {
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.
No description provided.