diff options
author | Simon Rozman <simon@rozman.si> | 2019-11-14 09:27:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-15 14:49:27 -0600 |
commit | 8a476b326136f5c03790fa168686848884c8cd5a (patch) | |
tree | 3fac4f2940c3012734a4147ef627e2b52a27a859 /conf/config.go | |
parent | manager: chdir into unelevated profile before execing (diff) | |
download | wireguard-windows-8a476b326136f5c03790fa168686848884c8cd5a.tar.xz wireguard-windows-8a476b326136f5c03790fa168686848884c8cd5a.zip |
l18n: add localization support
Revise the messages to make them localizable.
Note: The log messages are not marked for localization. Probably, we
want to keep log files in English for easier global troubleshooting.
Having a user run `go generate` requires a valid and up-to-date Go
environment. Rather than instructing users how to setup the environment
correctly, the `go generate` was integrated into build.bat. This reuses
the Go building environment downloaded and prepared by build.bat to
provide controllable and consistent result.
Use `make generate` on Linux.
As the zgotext.go output varies for GOARCH=386 and amd64, one had to be
chosen to provide stable output. The former is the first one to build in
build.bat.
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'conf/config.go')
-rw-r--r-- | conf/config.go | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/conf/config.go b/conf/config.go index a84dc418..f4d8478a 100644 --- a/conf/config.go +++ b/conf/config.go @@ -16,6 +16,8 @@ import ( "time" "golang.org/x/crypto/curve25519" + + "golang.zx2c4.com/wireguard/windows/l18n" ) const KeyLength = 32 @@ -131,18 +133,6 @@ func NewPrivateKeyFromString(b64 string) (*Key, error) { return parseKeyBase64(b64) } -func formatInterval(i int64, n string, l int) string { - r := "" - if l > 0 { - r += ", " - } - r += fmt.Sprintf("%d %s", i, n) - if i != 1 { - r += "s" - } - return r -} - func (t HandshakeTime) IsEmpty() bool { return t == HandshakeTime(0) } @@ -151,9 +141,9 @@ func (t HandshakeTime) String() string { u := time.Unix(0, 0).Add(time.Duration(t)).Unix() n := time.Now().Unix() if u == n { - return "Now" + return l18n.Sprintf("Now") } else if u > n { - return "System clock wound backward!" + return l18n.Sprintf("System clock wound backward!") } left := n - u years := left / (365 * 24 * 60 * 60) @@ -164,37 +154,37 @@ func (t HandshakeTime) String() string { left = left % (60 * 60) minutes := left / 60 seconds := left % 60 - s := "" + s := make([]string, 0, 5) if years > 0 { - s += formatInterval(years, "year", len(s)) + s = append(s, l18n.Sprintf("%d year(s)", years)) } if days > 0 { - s += formatInterval(days, "day", len(s)) + s = append(s, l18n.Sprintf("%d day(s)", days)) } if hours > 0 { - s += formatInterval(hours, "hour", len(s)) + s = append(s, l18n.Sprintf("%d hour(s)", hours)) } if minutes > 0 { - s += formatInterval(minutes, "minute", len(s)) + s = append(s, l18n.Sprintf("%d minute(s)", minutes)) } if seconds > 0 { - s += formatInterval(seconds, "second", len(s)) + s = append(s, l18n.Sprintf("%d second(s)", seconds)) } - s += " ago" - return s + timestamp := strings.Join(s, l18n.EnumerationSeparator()) + return l18n.Sprintf("%s ago", timestamp) } func (b Bytes) String() string { if b < 1024 { - return fmt.Sprintf("%d B", b) + return l18n.Sprintf("%d\u00a0B", b) } else if b < 1024*1024 { - return fmt.Sprintf("%.2f KiB", float64(b)/1024) + return l18n.Sprintf("%.2f\u00a0KiB", float64(b)/1024) } else if b < 1024*1024*1024 { - return fmt.Sprintf("%.2f MiB", float64(b)/(1024*1024)) + return l18n.Sprintf("%.2f\u00a0MiB", float64(b)/(1024*1024)) } else if b < 1024*1024*1024*1024 { - return fmt.Sprintf("%.2f GiB", float64(b)/(1024*1024*1024)) + return l18n.Sprintf("%.2f\u00a0GiB", float64(b)/(1024*1024*1024)) } - return fmt.Sprintf("%.2f TiB", float64(b)/(1024*1024*1024)/1024) + return l18n.Sprintf("%.2f\u00a0TiB", float64(b)/(1024*1024*1024)/1024) } func (conf *Config) DeduplicateNetworkEntries() { |