~damien/shopping

d528f989e007b6be626250b2d8198c16b3692b96 — Damien Radtke 2 years ago 857f9fe master
Various fixes and i18n modifications
6 files changed, 34 insertions(+), 7 deletions(-)

M api/apiclient/apiclient.go
M cmd/dbdo/main.go
M i18n/catalog.go
M i18n/catalog_test.go
A i18n/en/en.go
M shopping.go
M api/apiclient/apiclient.go => api/apiclient/apiclient.go +0 -1
@@ 2,7 2,6 @@ package apiclient

import (
	"errors"
	"log"
	"bytes"
	"context"
	"fmt"

M cmd/dbdo/main.go => cmd/dbdo/main.go +2 -2
@@ 10,8 10,8 @@ import (

func main() {
	ctx := context.Background()
	users := postgres.MustNewUsers(ctx, "db")
	if user, err := users.Create(ctx, shopping.User{
	db := postgres.MustNewDB(ctx, "db")
	if user, err := db.UserCreate(ctx, shopping.User{
		Username:    "damien",
		DisplayName: "Damien",
	}); err != nil {

M i18n/catalog.go => i18n/catalog.go +12 -4
@@ 4,11 4,16 @@ import (
	"golang.org/x/text/language"
	"golang.org/x/text/message"
	"golang.org/x/text/message/catalog"
)

// TODO: build a new catalog rather than use the default?
	"shopping.io"
	"shopping.io/i18n/en"
)

/*
var entries = map[string]map[language.Tag]interface{}{
	"hello world": map[language.Tag]interface{}{
		language.English: "Hello World!",
	},
	"hello web": map[language.Tag]interface{}{
		language.English: "Hello, Web!",
		language.German:  "Guten Tag, Web!",


@@ 23,10 28,13 @@ var entries = map[string]map[language.Tag]interface{}{
		language.English: "Password",
	},
}
*/

func init() {
	for key, defs := range entries {
		for lang, msg := range defs {
	for lang, defs := range map[language.Tag]shopping.TextStrings{
		language.English: en.Strings(),
	}{
		for key, msg := range defs {
			switch m := msg.(type) {
			case string:
				message.SetString(lang, key, m)

M i18n/catalog_test.go => i18n/catalog_test.go +1 -0
@@ 5,6 5,7 @@ import (

	"golang.org/x/text/language"
	"golang.org/x/text/message"

	_ "shopping.io/i18n"
)


A i18n/en/en.go => i18n/en/en.go +16 -0
@@ 0,0 1,16 @@
// Package en defines English text strings.
package en

import (
	"shopping.io"
)

func Strings() shopping.TextStrings{
	return shopping.TextStrings{
		"hello world": "Hello World!",
		"hello web": "Hello Web!",
		"login": "Login",
		"username": "Username",
		"password": "Password",
	}
}

M shopping.go => shopping.go +3 -0
@@ 72,3 72,6 @@ func ErrFmt(errp *error, format string, args ...interface{}) {
		}
	}
}

// TextStrings is a map from text key to either string, catalog.Message, or []catalog.Message.
type TextStrings map[string]interface{}