Skip to content

Commit

Permalink
gotext: fix non-existing translation lookup
Browse files Browse the repository at this point in the history
The ", " somehow doesn't make it to the locale catalogues. And gotext
has a bug to return first translation instead of error on non-existing
lookups.

When the gotext is fixed upstream (fix proposed), remove this commit.
But, do research, why ", " strings are not picked up by gotext for
translation.

See-also: golang/go#35587).
See-also: https://go-review.googlesource.com/c/text/+/207217
Signed-off-by: Simon Rozman <simon@rozman.si>
  • Loading branch information
rozmansi committed Nov 15, 2019
1 parent 48d5ece commit c8a9f38
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ if exist .deps\prepared goto :render
rem Mirror of https://sourceforge.net/projects/ezwinports/files/make-4.2.1-without-guile-w32-bin.zip
call :download make.zip https://download.wireguard.com/windows-toolchain/distfiles/make-4.2.1-without-guile-w32-bin.zip 30641be9602712be76212b99df7209f4f8f518ba764cf564262bc9d6e4047cc7 "--strip-components 1 bin" || goto :error
call :download wireguard-tools.zip https://git.zx2c4.com/WireGuard/snapshot/WireGuard-0.0.20190905.zip 6683eb4ed83a6b5b18ea4c36276e68457ca4c611e40392685c2e9da562e9c837 "--exclude wg-quick --strip-components 1" || goto :error
rem Mirror of https://sourceforge.net/projects/gnuwin32/files/patch/2.5.9-7/patch-2.5.9-7-bin.zip with fixed manifest
call :download patch.zip https://download.wireguard.com/windows-toolchain/distfiles/patch-2.5.9-7-bin-fixed-manifest.zip 25977006ca9713f2662a5d0a2ed3a5a138225b8be3757035bd7da9dcf985d0a1 "--strip-components 1 bin" || goto :error
copy /y NUL prepared > NUL || goto :error
cd .. || goto :error

Expand Down Expand Up @@ -73,6 +75,8 @@ if exist .deps\prepared goto :render
if "%~1|%WIREGUARD_GENERATE_LOCALES%" == "x86|yes" (
echo [+] Generating locales %1
go generate || exit /b 1
echo [+] Patching gotext generated files %1
for %%a in ("gotext-*.patch") do .deps\patch -f -N -r- -p1 --binary < "%%a" || exit /b 1
)
echo [+] Building program %1
go build -ldflags="-H windowsgui -s -w" -tags walk_use_cgo -trimpath -v -o "%~1\wireguard.exe" || exit /b 1
Expand Down
30 changes: 30 additions & 0 deletions gotext-fix-non-existing-key-lookup.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 8359973c072d7822b711ad548902a8130b35d85a Mon Sep 17 00:00:00 2001
From: Simon Rozman <simon@rozman.si>
Date: Thu, 14 Nov 2019 15:11:40 +0100
Subject: [PATCH] gotext: fix non-existing key lookup

See-also: https://go-review.googlesource.com/c/text/+/207217
Signed-off-by: Simon Rozman <simon@rozman.si>
---
zgotext.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/zgotext.go b/zgotext.go
index 4a840c02..b66b2272 100644
--- a/zgotext.go
+++ b/zgotext.go
@@ -14,7 +14,10 @@ type dictionary struct {
}

func (d *dictionary) Lookup(key string) (data string, ok bool) {
- p := messageKeyToIndex[key]
+ p, ok := messageKeyToIndex[key]
+ if !ok {
+ return "", false
+ }
start, end := d.index[p], d.index[p+1]
if start == end {
return "", false
--
2.19.1.windows.1

5 changes: 4 additions & 1 deletion zgotext.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8a9f38

Please sign in to comment.