Skip to content

Commit

Permalink
Merge pull request #818 from kaleido-io/multi-language
Browse files Browse the repository at this point in the history
Add language tag to FFM, FFE, FFC, etc
  • Loading branch information
awrichar authored May 19, 2022
2 parents 1d45d86 + 64eb64a commit 6be7ca8
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 27 deletions.
73 changes: 59 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,42 +1,87 @@
module github.com/hyperledger/firefly

go 1.16
go 1.17

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Masterminds/squirrel v1.5.2
github.com/aidarkhanov/nanoid v1.0.8
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect
github.com/containerd/containerd v1.5.10 // indirect
github.com/docker/go-units v0.4.0
github.com/getkin/kin-openapi v0.94.1-0.20220401165309-136a868a30c2
github.com/ghodss/yaml v1.0.0
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-resty/resty/v2 v2.7.0
github.com/golang-migrate/migrate/v4 v4.15.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hyperledger/firefly-common v0.1.4
github.com/hyperledger/firefly-common v0.1.5
github.com/jarcoal/httpmock v1.1.0
github.com/karlseguin/ccache v2.0.3+incompatible
github.com/karlseguin/expect v1.0.8 // indirect
github.com/lib/pq v1.10.4
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.10
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/qeesung/image2ascii v1.0.1
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.11.0
github.com/stretchr/testify v1.7.1
github.com/wayneashleyberry/terminal-dimensions v1.0.0 // indirect
gitlab.com/hfuss/mux-prometheus v0.0.4
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5
golang.org/x/text v0.3.7
)

require (
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/containerd v1.5.10 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/karlseguin/expect v1.0.8 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/wayneashleyberry/terminal-dimensions v1.0.0 // indirect
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKEN
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hyperledger/firefly-common v0.1.4 h1:wjZgYZohimKVlBxF3lZmrymVbHwgUIZQshQtE2AQvgQ=
github.com/hyperledger/firefly-common v0.1.4/go.mod h1:ytB+404+Qg00wJKx602Yi/V6Spx9d0g65lZR9y5fzlo=
github.com/hyperledger/firefly-common v0.1.5 h1:66RXEAc/dsSEYPRye3G48Lk9sN+AmYGPf1FkrkbQGWs=
github.com/hyperledger/firefly-common v0.1.5/go.mod h1:qGy7i8eWlE8Ed7jFn2Hpn8bYaflL204j4NJB1mAfTms=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
4 changes: 0 additions & 4 deletions internal/coremsgs/en_api_translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package coremsgs

import "github.com/hyperledger/firefly-common/pkg/i18n"

var ffm = i18n.FFM

//revive:disable
var (
CoreSystemNSDescription = ffm("core.systemNSDescription", "FireFly system namespace")
Expand Down
5 changes: 4 additions & 1 deletion internal/coremsgs/en_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ package coremsgs

import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"golang.org/x/text/language"
)

var ffc = i18n.FFC
var ffc = func(key, translation, fieldType string) i18n.ConfigMessageKey {
return i18n.FFC(language.AmericanEnglish, key, translation, fieldType)
}

//revive:disable
var (
Expand Down
9 changes: 7 additions & 2 deletions internal/coremsgs/en_error_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

package coremsgs

import "github.com/hyperledger/firefly-common/pkg/i18n"
import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"golang.org/x/text/language"
)

var ffe = i18n.FFE
var ffe = func(key, translation string, statusHint ...int) i18n.ErrorMessageKey {
return i18n.FFE(language.AmericanEnglish, key, translation, statusHint...)
}

//revive:disable
var (
Expand Down
10 changes: 10 additions & 0 deletions internal/coremsgs/en_struct_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package coremsgs

import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"golang.org/x/text/language"
)

//revive:disable

/*
Expand All @@ -36,6 +41,11 @@ type Message struct {
MessageHeader = ffm("Message.header", "The message header")
*/

var ffm = func(key, translation string) i18n.MessageKey {
return i18n.FFM(language.AmericanEnglish, key, translation)
}

var (
// MessageHeader field descriptions
MessageHeaderID = ffm("MessageHeader.id", "The UUID of the message. Unique to each message")
Expand Down
52 changes: 52 additions & 0 deletions internal/coremsgs/es/es_struct_descriptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright © 2022 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package es

import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"golang.org/x/text/language"
)

//revive:disable

/*
This file contains the field level descriptions that are used in
OpenAPI Spec generation. Each struct field that wants to use one of these
needs to have an ffstruct tag on it, indicating the name of the struct.
That will be combined with the JSON field name (note, it is not the GO
field name, but the JSON serialized name), separated by a "." This is the
key used to lookup the translation below. If it is not found, the description
is left blank in the OpenAPI spec
Example:
// message.go
type Message struct {
Header MessageHeader `ffstruct:"Message" json:"header"`
// en_translations_descriptions.go
MessageHeader = ffm("Message.header", "The message header")
*/

var ffm = func(key, translation string) i18n.MessageKey {
return i18n.FFM(language.Spanish, key, translation)
}

var (
// MessageHeader field descriptions
MessageHeaderID = ffm("MessageHeader.id", "El UUID del mensaje. Único para cada mensaje")
)
7 changes: 6 additions & 1 deletion internal/reference/generate_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@
package reference

import (
"context"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/hyperledger/firefly-common/pkg/i18n"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
)

func TestGenerateMarkdownPages(t *testing.T) {
markdownMap, err := GenerateObjectsReferenceMarkdown()
// TODO: Generate multiple languages when supported in the future here
ctx := i18n.WithLang(context.Background(), language.AmericanEnglish)
markdownMap, err := GenerateObjectsReferenceMarkdown(ctx)
assert.NoError(t, err)
assert.NotNil(t, markdownMap)

Expand Down
4 changes: 2 additions & 2 deletions internal/reference/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type TypeReferenceDoc struct {
* array which is passed to generateMarkdownPages(). Note: It is the responsibility of
* some other caller function to actually write the bytes to disk.
*/
func GenerateObjectsReferenceMarkdown() (map[string][]byte, error) {
func GenerateObjectsReferenceMarkdown(ctx context.Context) (map[string][]byte, error) {
message := &core.Message{
Header: core.MessageHeader{
ID: fftypes.MustParseUUID("4ea27cce-a103-4187-b318-f7b20fd87bf3"),
Expand Down Expand Up @@ -89,7 +89,7 @@ func GenerateObjectsReferenceMarkdown() (map[string][]byte, error) {

simpleTypes := []interface{}{time, bigInt}

return generateMarkdownPages(context.Background(), types, simpleTypes, filepath.Join("..", "..", "docs", "reference", "types"))
return generateMarkdownPages(ctx, types, simpleTypes, filepath.Join("..", "..", "docs", "reference", "types"))
}

func getType(v interface{}) reflect.Type {
Expand Down
5 changes: 4 additions & 1 deletion internal/reference/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import (
"path/filepath"
"testing"

"github.com/hyperledger/firefly-common/pkg/i18n"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
)

func TestCheckGeneratedMarkdownPages(t *testing.T) {
markdownMap, err := GenerateObjectsReferenceMarkdown()
ctx := i18n.WithLang(context.Background(), language.Spanish)
markdownMap, err := GenerateObjectsReferenceMarkdown(ctx)
assert.NoError(t, err)
assert.NotNil(t, markdownMap)

Expand Down

0 comments on commit 6be7ca8

Please sign in to comment.