support translations
Some checks failed
Generate check / check-changes (pull_request) Failing after 0s
Quality / check-changes (pull_request) Successful in 19s
Generate check / verify-generate (pull_request) Has been skipped
Quality / run-tests (pull_request) Failing after 1m3s

This commit is contained in:
2025-12-04 16:03:10 +00:00
parent b12c519fdb
commit 21147954cb
7 changed files with 192 additions and 16 deletions

View File

@@ -13,12 +13,15 @@ import (
"github.com/nmoniz/any2anexoj/internal/trading212"
"github.com/spf13/pflag"
"golang.org/x/sync/errgroup"
"golang.org/x/text/language"
)
// TODO: once we support more brokers or exchanges we should make this parameter required and
// remove/change default
var platform = pflag.StringP("platform", "p", "trading212", "one of the supported platforms")
var lang = pflag.StringP("language", "l", language.Portuguese.String(), "2 letter language code")
var readerFactories = map[string]func() internal.RecordReader{
"trading212": func() internal.RecordReader {
return trading212.NewRecordReader(os.Stdin, internal.NewOpenFIGI(&http.Client{Timeout: 5 * time.Second}))
@@ -33,14 +36,19 @@ func main() {
os.Exit(1)
}
err := run(context.Background(), *platform)
if lang == nil || len(*lang) == 0 {
slog.Error("--language flag is required")
os.Exit(1)
}
err := run(context.Background(), *platform, *lang)
if err != nil {
slog.Error("found a fatal issue", slog.Any("err", err))
os.Exit(1)
}
}
func run(ctx context.Context, platform string) error {
func run(ctx context.Context, platform, lang string) error {
ctx, cancel := signal.NotifyContext(ctx, os.Kill, os.Interrupt)
defer cancel()
@@ -66,7 +74,12 @@ func run(ctx context.Context, platform string) error {
return err
}
printer := NewPrettyPrinter(os.Stdout)
loc, err := NewLocalizer(lang)
if err != nil {
return fmt.Errorf("create localizer: %w", err)
}
printer := NewPrettyPrinter(os.Stdout, loc)
printer.Render(writer)