Skip to content

Commit

Permalink
Merge pull request #7 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 18, 2022
2 parents 04168b3 + 8437537 commit 286b6da
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 157 deletions.
9 changes: 5 additions & 4 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
)

const configDir = "../../test/data/config"
Expand Down Expand Up @@ -324,10 +325,10 @@ func TestGenerateConfigMarkdown(t *testing.T) {
key3 := AddRootKey("level1_1.level2_2.level3")
key4 := AddRootKey("level1_2.level2.level3")

i18n.FFC(fmt.Sprintf("config.%s", key1), "Description 1", "Type 1")
i18n.FFC(fmt.Sprintf("config.%s", key2), "Description 2", "Type 2")
i18n.FFC("config.global.level2_2.level3", "Description 3", "Type 3")
i18n.FFC(fmt.Sprintf("config.%s", key4), "Description 4", "Type 4")
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key1), "Description 1", "Type 1")
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key2), "Description 2", "Type 2")
i18n.FFC(language.AmericanEnglish, "config.global.level2_2.level3", "Description 3", "Type 3")
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key4), "Description 4", "Type 4")

RootConfigReset(func() {
viper.SetDefault(string(key1), "val1")
Expand Down
122 changes: 64 additions & 58 deletions pkg/i18n/en_base_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package i18n

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

var TimeDurationType = "[`time.Duration`](https://pkg.go.dev/time#Duration)"
var TimeFormatType = "[Time format](https://pkg.go.dev/time#pkg-constants) `string`"
var ByteSizeType = "[`BytesSize`](https://pkg.go.dev/github.com/docker/go-units#BytesSize)"
Expand All @@ -27,72 +29,76 @@ var FloatType = "`boolean`"
var MapStringStringType = "`map[string]string`"
var IgnoredType = "IGNORE"

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

//revive:disable
var (
ConfigGlobalConnectionTimeout = FFC("config.global.connectionTimeout", "The maximum amount of time that a connection is allowed to remain with no data transmitted", TimeDurationType)
ConfigGlobalRequestTimeout = FFC("config.global.requestTimeout", "The maximum amount of time that a request is allowed to remain open", TimeDurationType)
ConfigGlobalConnectionTimeout = ffc("config.global.connectionTimeout", "The maximum amount of time that a connection is allowed to remain with no data transmitted", TimeDurationType)
ConfigGlobalRequestTimeout = ffc("config.global.requestTimeout", "The maximum amount of time that a request is allowed to remain open", TimeDurationType)

ConfigGlobalRetryEnabled = FFC("config.global.retry.enabled", "Enables retries", BooleanType)
ConfigGlobalRetryFactor = FFC("config.global.retry.factor", "The retry backoff factor", FloatType)
ConfigGlobalRetryInitDelay = FFC("config.global.retry.initDelay", "The initial retry delay", TimeDurationType)
ConfigGlobalRetryInitialDelay = FFC("config.global.retry.initialDelay", "The initial retry delay", TimeDurationType)
ConfigGlobalRetryMaxDelay = FFC("config.global.retry.maxDelay", "The maximum retry delay", TimeDurationType)
ConfigGlobalRetryMaxAttempts = FFC("config.global.retry.maxAttempts", "The maximum number attempts", IntType)
ConfigGlobalRetryCount = FFC("config.global.retry.count", "The maximum number of times to retry", IntType)
ConfigGlobalInitWaitTime = FFC("config.global.retry.initWaitTime", "The initial retry delay", TimeDurationType)
ConfigGlobalMaxWaitTime = FFC("config.global.retry.maxWaitTime", "The maximum retry delay", TimeDurationType)
ConfigGlobalRetryEnabled = ffc("config.global.retry.enabled", "Enables retries", BooleanType)
ConfigGlobalRetryFactor = ffc("config.global.retry.factor", "The retry backoff factor", FloatType)
ConfigGlobalRetryInitDelay = ffc("config.global.retry.initDelay", "The initial retry delay", TimeDurationType)
ConfigGlobalRetryInitialDelay = ffc("config.global.retry.initialDelay", "The initial retry delay", TimeDurationType)
ConfigGlobalRetryMaxDelay = ffc("config.global.retry.maxDelay", "The maximum retry delay", TimeDurationType)
ConfigGlobalRetryMaxAttempts = ffc("config.global.retry.maxAttempts", "The maximum number attempts", IntType)
ConfigGlobalRetryCount = ffc("config.global.retry.count", "The maximum number of times to retry", IntType)
ConfigGlobalInitWaitTime = ffc("config.global.retry.initWaitTime", "The initial retry delay", TimeDurationType)
ConfigGlobalMaxWaitTime = ffc("config.global.retry.maxWaitTime", "The maximum retry delay", TimeDurationType)

ConfigGlobalUsername = FFC("config.global.auth.username", "Username", StringType)
ConfigGlobalPassword = FFC("config.global.auth.password", "Password", StringType)
ConfigGlobalUsername = ffc("config.global.auth.username", "Username", StringType)
ConfigGlobalPassword = ffc("config.global.auth.password", "Password", StringType)

ConfigGlobalSize = FFC("config.global.cache.size", "The size of the cache", ByteSizeType)
ConfigGlobalTTL = FFC("config.global.cache.ttl", "The time to live (TTL) for the cache", TimeDurationType)
ConfigGlobalSize = ffc("config.global.cache.size", "The size of the cache", ByteSizeType)
ConfigGlobalTTL = ffc("config.global.cache.ttl", "The time to live (TTL) for the cache", TimeDurationType)

ConfigGlobaltWsHeartbeatInterval = FFC("config.global.ws.heartbeatInterval", "The amount of time to wait between heartbeat signals on the WebSocket connection", TimeDurationType)
ConfigGlobalWsInitialConnectAttempts = FFC("config.global.ws.initialConnectAttempts", "The number of attempts FireFly will make to connect to the WebSocket when starting up, before failing", IntType)
ConfigGlobalWsPath = FFC("config.global.ws.path", "The WebSocket sever URL to which FireFly should connect", "WebSocket URL "+StringType)
ConfigGlobalWsReadBufferSize = FFC("config.global.ws.readBufferSize", "The size in bytes of the read buffer for the WebSocket connection", ByteSizeType)
ConfigGlobalWsWriteBufferSize = FFC("config.global.ws.writeBufferSize", "The size in bytes of the write buffer for the WebSocket connection", ByteSizeType)
ConfigGlobaltWsHeartbeatInterval = ffc("config.global.ws.heartbeatInterval", "The amount of time to wait between heartbeat signals on the WebSocket connection", TimeDurationType)
ConfigGlobalWsInitialConnectAttempts = ffc("config.global.ws.initialConnectAttempts", "The number of attempts FireFly will make to connect to the WebSocket when starting up, before failing", IntType)
ConfigGlobalWsPath = ffc("config.global.ws.path", "The WebSocket sever URL to which FireFly should connect", "WebSocket URL "+StringType)
ConfigGlobalWsReadBufferSize = ffc("config.global.ws.readBufferSize", "The size in bytes of the read buffer for the WebSocket connection", ByteSizeType)
ConfigGlobalWsWriteBufferSize = ffc("config.global.ws.writeBufferSize", "The size in bytes of the write buffer for the WebSocket connection", ByteSizeType)

ConfigGlobalTLSCaFile = FFC("config.global.tls.caFile", "The path to the CA file for TLS on this API", StringType)
ConfigGlobalTLSCertFile = FFC("config.global.tls.certFile", "The path to the certificate file for TLS on this API", StringType)
ConfigGlobalTLSClientAuth = FFC("config.global.tls.clientAuth", "Enables or disables client auth for TLS on this API", StringType)
ConfigGlobalTLSEnabled = FFC("config.global.tls.enabled", "Enables or disables TLS on this API", BooleanType)
ConfigGlobalTLSKeyFile = FFC("config.global.tls.keyFile", "The path to the private key file for TLS on this API", StringType)
ConfigGlobalTLSHandshakeTimeout = FFC("config.global.tlsHandshakeTimeout", "The maximum amount of time to wait for a successful TLS handshake", TimeDurationType)
ConfigGlobalTLSCaFile = ffc("config.global.tls.caFile", "The path to the CA file for TLS on this API", StringType)
ConfigGlobalTLSCertFile = ffc("config.global.tls.certFile", "The path to the certificate file for TLS on this API", StringType)
ConfigGlobalTLSClientAuth = ffc("config.global.tls.clientAuth", "Enables or disables client auth for TLS on this API", StringType)
ConfigGlobalTLSEnabled = ffc("config.global.tls.enabled", "Enables or disables TLS on this API", BooleanType)
ConfigGlobalTLSKeyFile = ffc("config.global.tls.keyFile", "The path to the private key file for TLS on this API", StringType)
ConfigGlobalTLSHandshakeTimeout = ffc("config.global.tlsHandshakeTimeout", "The maximum amount of time to wait for a successful TLS handshake", TimeDurationType)

ConfigGlobalBodyTemplate = FFC("config.global.bodyTemplate", "The body go template string to use when making HTTP requests", GoTemplateType)
ConfigGlobalCustomClient = FFC("config.global.customClient", "Used for testing purposes only", IgnoredType)
ConfigGlobalExpectContinueTimeout = FFC("config.global.expectContinueTimeout", "See [ExpectContinueTimeout in the Go docs](https://pkg.go.dev/net/http#Transport)", TimeDurationType)
ConfigGlobalHeaders = FFC("config.global.headers", "Adds custom headers to HTTP requests", MapStringStringType)
ConfigGlobalIdleTimeout = FFC("config.global.idleTimeout", "The max duration to hold a HTTP keepalive connection between calls", TimeDurationType)
ConfigGlobalMaxIdleConns = FFC("config.global.maxIdleConns", "The max number of idle connections to hold pooled", IntType)
ConfigGlobalMethod = FFC("config.global.method", "The HTTP method to use when making requests to the Address Resolver", StringType)
ConfigGlobalBodyTemplate = ffc("config.global.bodyTemplate", "The body go template string to use when making HTTP requests", GoTemplateType)
ConfigGlobalCustomClient = ffc("config.global.customClient", "Used for testing purposes only", IgnoredType)
ConfigGlobalExpectContinueTimeout = ffc("config.global.expectContinueTimeout", "See [ExpectContinueTimeout in the Go docs](https://pkg.go.dev/net/http#Transport)", TimeDurationType)
ConfigGlobalHeaders = ffc("config.global.headers", "Adds custom headers to HTTP requests", MapStringStringType)
ConfigGlobalIdleTimeout = ffc("config.global.idleTimeout", "The max duration to hold a HTTP keepalive connection between calls", TimeDurationType)
ConfigGlobalMaxIdleConns = ffc("config.global.maxIdleConns", "The max number of idle connections to hold pooled", IntType)
ConfigGlobalMethod = ffc("config.global.method", "The HTTP method to use when making requests to the Address Resolver", StringType)

ConfigLang = FFC("config.lang", "Default language for translation (API calls may support language override using headers)", StringType)
ConfigLogCompress = FFC("config.log.compress", "Determines if the rotated log files should be compressed using gzip", BooleanType)
ConfigLogFilename = FFC("config.log.filename", "Filename is the file to write logs to. Backup log files will be retained in the same directory", StringType)
ConfigLogFilesize = FFC("config.log.filesize", "MaxSize is the maximum size the log file before it gets rotated", ByteSizeType)
ConfigLogForceColor = FFC("config.log.forceColor", "Force color to be enabled, even when a non-TTY output is detected", BooleanType)
ConfigLogLevel = FFC("config.log.level", "The log level - error, warn, info, debug, trace", StringType)
ConfigLogMaxAge = FFC("config.log.maxAge", "The maximum time to retain old log files based on the timestamp encoded in their filename.", TimeDurationType)
ConfigLogMaxBackups = FFC("config.log.maxBackups", "Maximum number of old log files to retain", IntType)
ConfigLogNoColor = FFC("config.log.noColor", "Force color to be disabled, event when TTY output is detected", BooleanType)
ConfigLogTimeFormat = FFC("config.log.timeFormat", "Custom time format for logs", TimeFormatType)
ConfigLogUtc = FFC("config.log.utc", "Use UTC timestamps for logs", BooleanType)
ConfigLogIncludeCodeInfo = FFC("config.log.includeCodeInfo", "Enables the report caller for including the calling file and line number, and the calling function. If using text logs, it uses the logrus text format rather than the default prefix format.", BooleanType)
ConfigLogJSONEnabled = FFC("config.log.json.enabled", "Enables JSON formatted logs rather than text. All log color settings are ignored when enabled.", BooleanType)
ConfigLogJSONTimestampField = FFC("config.log.json.fields.timestamp", "Configures the JSON key containing the timestamp of the log", StringType)
ConfigLogJSONLevelField = FFC("config.log.json.fields.level", "Configures the JSON key containing the log level", StringType)
ConfigLogJSONMessageField = FFC("config.log.json.fields.message", "Configures the JSON key containing the log message", StringType)
ConfigLogJSONFuncField = FFC("config.log.json.fields.func", "Configures the JSON key containing the calling function", StringType)
ConfigLogJSONFileField = FFC("config.log.json.fields.file", "configures the JSON key containing the calling file", StringType)
ConfigCorsCredentials = FFC("config.cors.credentials", "CORS setting to control whether a browser allows credentials to be sent to this API", BooleanType)
ConfigLang = ffc("config.lang", "Default language for translation (API calls may support language override using headers)", StringType)
ConfigLogCompress = ffc("config.log.compress", "Determines if the rotated log files should be compressed using gzip", BooleanType)
ConfigLogFilename = ffc("config.log.filename", "Filename is the file to write logs to. Backup log files will be retained in the same directory", StringType)
ConfigLogFilesize = ffc("config.log.filesize", "MaxSize is the maximum size the log file before it gets rotated", ByteSizeType)
ConfigLogForceColor = ffc("config.log.forceColor", "Force color to be enabled, even when a non-TTY output is detected", BooleanType)
ConfigLogLevel = ffc("config.log.level", "The log level - error, warn, info, debug, trace", StringType)
ConfigLogMaxAge = ffc("config.log.maxAge", "The maximum time to retain old log files based on the timestamp encoded in their filename.", TimeDurationType)
ConfigLogMaxBackups = ffc("config.log.maxBackups", "Maximum number of old log files to retain", IntType)
ConfigLogNoColor = ffc("config.log.noColor", "Force color to be disabled, event when TTY output is detected", BooleanType)
ConfigLogTimeFormat = ffc("config.log.timeFormat", "Custom time format for logs", TimeFormatType)
ConfigLogUtc = ffc("config.log.utc", "Use UTC timestamps for logs", BooleanType)
ConfigLogIncludeCodeInfo = ffc("config.log.includeCodeInfo", "Enables the report caller for including the calling file and line number, and the calling function. If using text logs, it uses the logrus text format rather than the default prefix format.", BooleanType)
ConfigLogJSONEnabled = ffc("config.log.json.enabled", "Enables JSON formatted logs rather than text. All log color settings are ignored when enabled.", BooleanType)
ConfigLogJSONTimestampField = ffc("config.log.json.fields.timestamp", "Configures the JSON key containing the timestamp of the log", StringType)
ConfigLogJSONLevelField = ffc("config.log.json.fields.level", "Configures the JSON key containing the log level", StringType)
ConfigLogJSONMessageField = ffc("config.log.json.fields.message", "Configures the JSON key containing the log message", StringType)
ConfigLogJSONFuncField = ffc("config.log.json.fields.func", "Configures the JSON key containing the calling function", StringType)
ConfigLogJSONFileField = ffc("config.log.json.fields.file", "configures the JSON key containing the calling file", StringType)
ConfigCorsCredentials = ffc("config.cors.credentials", "CORS setting to control whether a browser allows credentials to be sent to this API", BooleanType)

ConfigCorsDebug = FFC("config.global.cors.debug", "Whether debug is enabled for the CORS implementation", BooleanType)
ConfigCorsEnabled = FFC("config.global.cors.enabled", "Whether CORS is enabled", BooleanType)
ConfigCorsHeaders = FFC("config.global.cors.headers", "CORS setting to control the allowed headers", StringType)
ConfigCorsMaxAge = FFC("config.global.cors.maxAge", "The maximum age a browser should rely on CORS checks", TimeDurationType)
ConfigCorsMethods = FFC("config.global.cors.methods", " CORS setting to control the allowed methods", StringType)
ConfigCorsOrigins = FFC("config.global.cors.origins", "CORS setting to control the allowed origins", StringType)
ConfigCorsDebug = ffc("config.global.cors.debug", "Whether debug is enabled for the CORS implementation", BooleanType)
ConfigCorsEnabled = ffc("config.global.cors.enabled", "Whether CORS is enabled", BooleanType)
ConfigCorsHeaders = ffc("config.global.cors.headers", "CORS setting to control the allowed headers", StringType)
ConfigCorsMaxAge = ffc("config.global.cors.maxAge", "The maximum age a browser should rely on CORS checks", TimeDurationType)
ConfigCorsMethods = ffc("config.global.cors.methods", " CORS setting to control the allowed methods", StringType)
ConfigCorsOrigins = ffc("config.global.cors.origins", "CORS setting to control the allowed origins", StringType)
)
Loading

0 comments on commit 286b6da

Please sign in to comment.