Skip to content

Commit 286b6da

Browse files
authored
Merge pull request #7 from kaleido-io/multi-language
Add language tag to FFM, FFE, FFC, etc
2 parents 04168b3 + 8437537 commit 286b6da

File tree

6 files changed

+255
-157
lines changed

6 files changed

+255
-157
lines changed

pkg/config/config_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/hyperledger/firefly-common/pkg/i18n"
3131
"github.com/spf13/viper"
3232
"github.com/stretchr/testify/assert"
33+
"golang.org/x/text/language"
3334
)
3435

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

327-
i18n.FFC(fmt.Sprintf("config.%s", key1), "Description 1", "Type 1")
328-
i18n.FFC(fmt.Sprintf("config.%s", key2), "Description 2", "Type 2")
329-
i18n.FFC("config.global.level2_2.level3", "Description 3", "Type 3")
330-
i18n.FFC(fmt.Sprintf("config.%s", key4), "Description 4", "Type 4")
328+
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key1), "Description 1", "Type 1")
329+
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key2), "Description 2", "Type 2")
330+
i18n.FFC(language.AmericanEnglish, "config.global.level2_2.level3", "Description 3", "Type 3")
331+
i18n.FFC(language.AmericanEnglish, fmt.Sprintf("config.%s", key4), "Description 4", "Type 4")
331332

332333
RootConfigReset(func() {
333334
viper.SetDefault(string(key1), "val1")

pkg/i18n/en_base_config_descriptions.go

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package i18n
1818

19+
import "golang.org/x/text/language"
20+
1921
var TimeDurationType = "[`time.Duration`](https://pkg.go.dev/time#Duration)"
2022
var TimeFormatType = "[Time format](https://pkg.go.dev/time#pkg-constants) `string`"
2123
var ByteSizeType = "[`BytesSize`](https://pkg.go.dev/github.com/docker/go-units#BytesSize)"
@@ -27,72 +29,76 @@ var FloatType = "`boolean`"
2729
var MapStringStringType = "`map[string]string`"
2830
var IgnoredType = "IGNORE"
2931

32+
var ffc = func(key, translation, fieldType string) ConfigMessageKey {
33+
return FFC(language.AmericanEnglish, key, translation, fieldType)
34+
}
35+
3036
//revive:disable
3137
var (
32-
ConfigGlobalConnectionTimeout = FFC("config.global.connectionTimeout", "The maximum amount of time that a connection is allowed to remain with no data transmitted", TimeDurationType)
33-
ConfigGlobalRequestTimeout = FFC("config.global.requestTimeout", "The maximum amount of time that a request is allowed to remain open", TimeDurationType)
38+
ConfigGlobalConnectionTimeout = ffc("config.global.connectionTimeout", "The maximum amount of time that a connection is allowed to remain with no data transmitted", TimeDurationType)
39+
ConfigGlobalRequestTimeout = ffc("config.global.requestTimeout", "The maximum amount of time that a request is allowed to remain open", TimeDurationType)
3440

35-
ConfigGlobalRetryEnabled = FFC("config.global.retry.enabled", "Enables retries", BooleanType)
36-
ConfigGlobalRetryFactor = FFC("config.global.retry.factor", "The retry backoff factor", FloatType)
37-
ConfigGlobalRetryInitDelay = FFC("config.global.retry.initDelay", "The initial retry delay", TimeDurationType)
38-
ConfigGlobalRetryInitialDelay = FFC("config.global.retry.initialDelay", "The initial retry delay", TimeDurationType)
39-
ConfigGlobalRetryMaxDelay = FFC("config.global.retry.maxDelay", "The maximum retry delay", TimeDurationType)
40-
ConfigGlobalRetryMaxAttempts = FFC("config.global.retry.maxAttempts", "The maximum number attempts", IntType)
41-
ConfigGlobalRetryCount = FFC("config.global.retry.count", "The maximum number of times to retry", IntType)
42-
ConfigGlobalInitWaitTime = FFC("config.global.retry.initWaitTime", "The initial retry delay", TimeDurationType)
43-
ConfigGlobalMaxWaitTime = FFC("config.global.retry.maxWaitTime", "The maximum retry delay", TimeDurationType)
41+
ConfigGlobalRetryEnabled = ffc("config.global.retry.enabled", "Enables retries", BooleanType)
42+
ConfigGlobalRetryFactor = ffc("config.global.retry.factor", "The retry backoff factor", FloatType)
43+
ConfigGlobalRetryInitDelay = ffc("config.global.retry.initDelay", "The initial retry delay", TimeDurationType)
44+
ConfigGlobalRetryInitialDelay = ffc("config.global.retry.initialDelay", "The initial retry delay", TimeDurationType)
45+
ConfigGlobalRetryMaxDelay = ffc("config.global.retry.maxDelay", "The maximum retry delay", TimeDurationType)
46+
ConfigGlobalRetryMaxAttempts = ffc("config.global.retry.maxAttempts", "The maximum number attempts", IntType)
47+
ConfigGlobalRetryCount = ffc("config.global.retry.count", "The maximum number of times to retry", IntType)
48+
ConfigGlobalInitWaitTime = ffc("config.global.retry.initWaitTime", "The initial retry delay", TimeDurationType)
49+
ConfigGlobalMaxWaitTime = ffc("config.global.retry.maxWaitTime", "The maximum retry delay", TimeDurationType)
4450

45-
ConfigGlobalUsername = FFC("config.global.auth.username", "Username", StringType)
46-
ConfigGlobalPassword = FFC("config.global.auth.password", "Password", StringType)
51+
ConfigGlobalUsername = ffc("config.global.auth.username", "Username", StringType)
52+
ConfigGlobalPassword = ffc("config.global.auth.password", "Password", StringType)
4753

48-
ConfigGlobalSize = FFC("config.global.cache.size", "The size of the cache", ByteSizeType)
49-
ConfigGlobalTTL = FFC("config.global.cache.ttl", "The time to live (TTL) for the cache", TimeDurationType)
54+
ConfigGlobalSize = ffc("config.global.cache.size", "The size of the cache", ByteSizeType)
55+
ConfigGlobalTTL = ffc("config.global.cache.ttl", "The time to live (TTL) for the cache", TimeDurationType)
5056

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

57-
ConfigGlobalTLSCaFile = FFC("config.global.tls.caFile", "The path to the CA file for TLS on this API", StringType)
58-
ConfigGlobalTLSCertFile = FFC("config.global.tls.certFile", "The path to the certificate file for TLS on this API", StringType)
59-
ConfigGlobalTLSClientAuth = FFC("config.global.tls.clientAuth", "Enables or disables client auth for TLS on this API", StringType)
60-
ConfigGlobalTLSEnabled = FFC("config.global.tls.enabled", "Enables or disables TLS on this API", BooleanType)
61-
ConfigGlobalTLSKeyFile = FFC("config.global.tls.keyFile", "The path to the private key file for TLS on this API", StringType)
62-
ConfigGlobalTLSHandshakeTimeout = FFC("config.global.tlsHandshakeTimeout", "The maximum amount of time to wait for a successful TLS handshake", TimeDurationType)
63+
ConfigGlobalTLSCaFile = ffc("config.global.tls.caFile", "The path to the CA file for TLS on this API", StringType)
64+
ConfigGlobalTLSCertFile = ffc("config.global.tls.certFile", "The path to the certificate file for TLS on this API", StringType)
65+
ConfigGlobalTLSClientAuth = ffc("config.global.tls.clientAuth", "Enables or disables client auth for TLS on this API", StringType)
66+
ConfigGlobalTLSEnabled = ffc("config.global.tls.enabled", "Enables or disables TLS on this API", BooleanType)
67+
ConfigGlobalTLSKeyFile = ffc("config.global.tls.keyFile", "The path to the private key file for TLS on this API", StringType)
68+
ConfigGlobalTLSHandshakeTimeout = ffc("config.global.tlsHandshakeTimeout", "The maximum amount of time to wait for a successful TLS handshake", TimeDurationType)
6369

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

72-
ConfigLang = FFC("config.lang", "Default language for translation (API calls may support language override using headers)", StringType)
73-
ConfigLogCompress = FFC("config.log.compress", "Determines if the rotated log files should be compressed using gzip", BooleanType)
74-
ConfigLogFilename = FFC("config.log.filename", "Filename is the file to write logs to. Backup log files will be retained in the same directory", StringType)
75-
ConfigLogFilesize = FFC("config.log.filesize", "MaxSize is the maximum size the log file before it gets rotated", ByteSizeType)
76-
ConfigLogForceColor = FFC("config.log.forceColor", "Force color to be enabled, even when a non-TTY output is detected", BooleanType)
77-
ConfigLogLevel = FFC("config.log.level", "The log level - error, warn, info, debug, trace", StringType)
78-
ConfigLogMaxAge = FFC("config.log.maxAge", "The maximum time to retain old log files based on the timestamp encoded in their filename.", TimeDurationType)
79-
ConfigLogMaxBackups = FFC("config.log.maxBackups", "Maximum number of old log files to retain", IntType)
80-
ConfigLogNoColor = FFC("config.log.noColor", "Force color to be disabled, event when TTY output is detected", BooleanType)
81-
ConfigLogTimeFormat = FFC("config.log.timeFormat", "Custom time format for logs", TimeFormatType)
82-
ConfigLogUtc = FFC("config.log.utc", "Use UTC timestamps for logs", BooleanType)
83-
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)
84-
ConfigLogJSONEnabled = FFC("config.log.json.enabled", "Enables JSON formatted logs rather than text. All log color settings are ignored when enabled.", BooleanType)
85-
ConfigLogJSONTimestampField = FFC("config.log.json.fields.timestamp", "Configures the JSON key containing the timestamp of the log", StringType)
86-
ConfigLogJSONLevelField = FFC("config.log.json.fields.level", "Configures the JSON key containing the log level", StringType)
87-
ConfigLogJSONMessageField = FFC("config.log.json.fields.message", "Configures the JSON key containing the log message", StringType)
88-
ConfigLogJSONFuncField = FFC("config.log.json.fields.func", "Configures the JSON key containing the calling function", StringType)
89-
ConfigLogJSONFileField = FFC("config.log.json.fields.file", "configures the JSON key containing the calling file", StringType)
90-
ConfigCorsCredentials = FFC("config.cors.credentials", "CORS setting to control whether a browser allows credentials to be sent to this API", BooleanType)
78+
ConfigLang = ffc("config.lang", "Default language for translation (API calls may support language override using headers)", StringType)
79+
ConfigLogCompress = ffc("config.log.compress", "Determines if the rotated log files should be compressed using gzip", BooleanType)
80+
ConfigLogFilename = ffc("config.log.filename", "Filename is the file to write logs to. Backup log files will be retained in the same directory", StringType)
81+
ConfigLogFilesize = ffc("config.log.filesize", "MaxSize is the maximum size the log file before it gets rotated", ByteSizeType)
82+
ConfigLogForceColor = ffc("config.log.forceColor", "Force color to be enabled, even when a non-TTY output is detected", BooleanType)
83+
ConfigLogLevel = ffc("config.log.level", "The log level - error, warn, info, debug, trace", StringType)
84+
ConfigLogMaxAge = ffc("config.log.maxAge", "The maximum time to retain old log files based on the timestamp encoded in their filename.", TimeDurationType)
85+
ConfigLogMaxBackups = ffc("config.log.maxBackups", "Maximum number of old log files to retain", IntType)
86+
ConfigLogNoColor = ffc("config.log.noColor", "Force color to be disabled, event when TTY output is detected", BooleanType)
87+
ConfigLogTimeFormat = ffc("config.log.timeFormat", "Custom time format for logs", TimeFormatType)
88+
ConfigLogUtc = ffc("config.log.utc", "Use UTC timestamps for logs", BooleanType)
89+
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)
90+
ConfigLogJSONEnabled = ffc("config.log.json.enabled", "Enables JSON formatted logs rather than text. All log color settings are ignored when enabled.", BooleanType)
91+
ConfigLogJSONTimestampField = ffc("config.log.json.fields.timestamp", "Configures the JSON key containing the timestamp of the log", StringType)
92+
ConfigLogJSONLevelField = ffc("config.log.json.fields.level", "Configures the JSON key containing the log level", StringType)
93+
ConfigLogJSONMessageField = ffc("config.log.json.fields.message", "Configures the JSON key containing the log message", StringType)
94+
ConfigLogJSONFuncField = ffc("config.log.json.fields.func", "Configures the JSON key containing the calling function", StringType)
95+
ConfigLogJSONFileField = ffc("config.log.json.fields.file", "configures the JSON key containing the calling file", StringType)
96+
ConfigCorsCredentials = ffc("config.cors.credentials", "CORS setting to control whether a browser allows credentials to be sent to this API", BooleanType)
9197

92-
ConfigCorsDebug = FFC("config.global.cors.debug", "Whether debug is enabled for the CORS implementation", BooleanType)
93-
ConfigCorsEnabled = FFC("config.global.cors.enabled", "Whether CORS is enabled", BooleanType)
94-
ConfigCorsHeaders = FFC("config.global.cors.headers", "CORS setting to control the allowed headers", StringType)
95-
ConfigCorsMaxAge = FFC("config.global.cors.maxAge", "The maximum age a browser should rely on CORS checks", TimeDurationType)
96-
ConfigCorsMethods = FFC("config.global.cors.methods", " CORS setting to control the allowed methods", StringType)
97-
ConfigCorsOrigins = FFC("config.global.cors.origins", "CORS setting to control the allowed origins", StringType)
98+
ConfigCorsDebug = ffc("config.global.cors.debug", "Whether debug is enabled for the CORS implementation", BooleanType)
99+
ConfigCorsEnabled = ffc("config.global.cors.enabled", "Whether CORS is enabled", BooleanType)
100+
ConfigCorsHeaders = ffc("config.global.cors.headers", "CORS setting to control the allowed headers", StringType)
101+
ConfigCorsMaxAge = ffc("config.global.cors.maxAge", "The maximum age a browser should rely on CORS checks", TimeDurationType)
102+
ConfigCorsMethods = ffc("config.global.cors.methods", " CORS setting to control the allowed methods", StringType)
103+
ConfigCorsOrigins = ffc("config.global.cors.origins", "CORS setting to control the allowed origins", StringType)
98104
)

0 commit comments

Comments
 (0)