Basic i18n setup

This commit is contained in:
Philipp Wolfer 2023-12-09 11:46:32 +01:00
parent 20f1732858
commit a41318d822
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
10 changed files with 700 additions and 9 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/backends"
"go.uploadedlobster.com/scotty/internal/config"
"go.uploadedlobster.com/scotty/internal/i18n"
"go.uploadedlobster.com/scotty/internal/models"
"go.uploadedlobster.com/scotty/internal/storage"
)
@ -84,7 +85,7 @@ func (c *TransferCmd[E, I, R]) resolveBackends(source string, target string) err
}
func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp backends.ImportProcessor[R]) error {
fmt.Printf("Transferring %s from %s to %s...\n", c.entity, c.sourceName, c.targetName)
fmt.Println(i18n.Tr("Transferring %s from %s to %s...", c.entity, c.sourceName, c.targetName))
// Authenticate backends, if needed
config := viper.GetViper()
@ -103,7 +104,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
if err != nil {
return err
}
fmt.Printf("From timestamp: %v (%v)\n", timestamp, timestamp.Unix())
fmt.Println(i18n.Tr("From timestamp: %v (%v)", timestamp, timestamp.Unix()))
// Prepare progress bars
exportProgress := make(chan models.Progress)
@ -123,11 +124,12 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
wg.Wait()
progress.Wait()
if result.Error != nil {
fmt.Printf("Import failed, last reported timestamp was %v (%v)\n", result.LastTimestamp, result.LastTimestamp.Unix())
fmt.Println(i18n.Tr("Import failed, last reported timestamp was %v (%v)",
result.LastTimestamp, result.LastTimestamp.Unix()))
return result.Error
}
fmt.Printf("Imported %v of %v %s into %v.\n",
result.ImportCount, result.TotalCount, c.entity, c.targetName)
fmt.Println(i18n.Tr("Imported %v of %v %s into %v.",
result.ImportCount, result.TotalCount, c.entity, c.targetName))
// Update timestamp
err = c.updateTimestamp(result, timestamp)
@ -137,9 +139,10 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
// Print errors
if len(result.ImportErrors) > 0 {
fmt.Printf("\nDuring the import the following errors occurred:\n")
fmt.Println()
fmt.Println(i18n.Tr("During the import the following errors occurred:"))
for _, err := range result.ImportErrors {
fmt.Printf("Error: %v\n", err)
fmt.Println(i18n.Tr("Error: %v\n", err))
}
}
@ -159,7 +162,7 @@ func (c *TransferCmd[E, I, R]) updateTimestamp(result models.ImportResult, oldTi
if result.LastTimestamp.Unix() < oldTimestamp.Unix() {
result.LastTimestamp = oldTimestamp
}
fmt.Printf("Latest timestamp: %v (%v)\n", result.LastTimestamp, result.LastTimestamp.Unix())
fmt.Println(i18n.Tr("Latest timestamp: %v (%v)\n", result.LastTimestamp, result.LastTimestamp.Unix()))
err := c.db.SetImportTimestamp(c.sourceName, c.targetName, c.entity, result.LastTimestamp)
return err
}