Merge lp:~unity-api-team/unity-scope-snappy/add_gettext_to_vendors into lp:~unity-api-team/unity-scope-snappy/trunk

Proposed by Antti Kaijanmäki on 2015-08-27
Status: Needs review
Proposed branch: lp:~unity-api-team/unity-scope-snappy/add_gettext_to_vendors
Merge into: lp:~unity-api-team/unity-scope-snappy/trunk
Diff against target: 579 lines (+473/-10)
6 files modified
debian/copyright (+4/-0)
internal/github.com/gosexy/gettext/LICENSE (+20/-0)
internal/github.com/gosexy/gettext/README.md (+94/-0)
internal/github.com/gosexy/gettext/gettext.go (+207/-0)
internal/github.com/gosexy/gettext/gettext_test.go (+130/-0)
internal/vendor.json (+18/-10)
To merge this branch: bzr merge lp:~unity-api-team/unity-scope-snappy/add_gettext_to_vendors
Reviewer Review Type Date Requested Status
Kyle Fazzari 2015-08-27 Needs Fixing on 2015-11-18
PS Jenkins bot (community) continuous-integration Approve on 2015-08-27
Review via email: mp+269290@code.launchpad.net

Commit message

Add github.com/gosexy/gettext to vendors.

Description of the change

-

To post a comment you must log in.
Kyle Fazzari (kyrofa) wrote :

Add this to debian/copyright, as well. Another comment is in the diff.

review: Needs Fixing
35. By Antti Kaijanmäki on 2015-08-27

merge trunk, resolve conflict in internal/vendor.json

Antti Kaijanmäki (kaijanmaki) wrote :

OK, will modify debian/copyright.

36. By Antti Kaijanmäki on 2015-08-27

update debian/copyright

Kyle Fazzari (kyrofa) wrote :

A few more things that might need fixing here.

review: Needs Fixing

Unmerged revisions

36. By Antti Kaijanmäki on 2015-08-27

update debian/copyright

35. By Antti Kaijanmäki on 2015-08-27

merge trunk, resolve conflict in internal/vendor.json

34. By Antti Kaijanmäki on 2015-08-26

Add github.com/gosexy/gettext to vendors.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/copyright'
2--- debian/copyright 2015-07-21 17:39:16 +0000
3+++ debian/copyright 2015-08-27 16:20:17 +0000
4@@ -54,6 +54,10 @@
5 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7
8+Files: internal/gihub.com/gosexy/gettext/*
9+Copyright: 2012-2013 José Carlos Nieto, http://xiam.menteslibres.org/
10+License: MIT
11+
12 Files: internal/golang.org/*
13 Copyright: 2012 The Go Authors
14 License: BSD-3-clause
15
16=== added directory 'internal/github.com/gosexy'
17=== added directory 'internal/github.com/gosexy/gettext'
18=== added file 'internal/github.com/gosexy/gettext/LICENSE'
19--- internal/github.com/gosexy/gettext/LICENSE 1970-01-01 00:00:00 +0000
20+++ internal/github.com/gosexy/gettext/LICENSE 2015-08-27 16:20:17 +0000
21@@ -0,0 +1,20 @@
22+Copyright (c) 2012-2013 José Carlos Nieto, http://xiam.menteslibres.org/
23+
24+Permission is hereby granted, free of charge, to any person obtaining
25+a copy of this software and associated documentation files (the
26+"Software"), to deal in the Software without restriction, including
27+without limitation the rights to use, copy, modify, merge, publish,
28+distribute, sublicense, and/or sell copies of the Software, and to
29+permit persons to whom the Software is furnished to do so, subject to
30+the following conditions:
31+
32+The above copyright notice and this permission notice shall be
33+included in all copies or substantial portions of the Software.
34+
35+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42
43=== added file 'internal/github.com/gosexy/gettext/README.md'
44--- internal/github.com/gosexy/gettext/README.md 1970-01-01 00:00:00 +0000
45+++ internal/github.com/gosexy/gettext/README.md 2015-08-27 16:20:17 +0000
46@@ -0,0 +1,94 @@
47+# gosexy/gettext
48+
49+Go bindings for [GNU gettext][1], an internationalization and localization
50+library for writing multilingual systems.
51+
52+## Requeriments
53+
54+The GNU C library. If you're using GNU/Linux, FreeBSD or OSX you should already
55+have it.
56+
57+## Installation
58+
59+Use `go get` to download and install the binding:
60+
61+```sh
62+go get github.com/gosexy/gettext
63+```
64+
65+## Usage
66+
67+```go
68+package main
69+
70+import (
71+ "github.com/gosexy/gettext"
72+ "fmt"
73+ "os"
74+)
75+
76+func main() {
77+ gettext.BindTextdomain("example", ".")
78+ gettext.Textdomain("example")
79+
80+ os.Setenv("LANGUAGE", "es_MX.utf8")
81+
82+ gettext.SetLocale(gettext.LC_ALL, "")
83+
84+ fmt.Println(gettext.Gettext("Hello, world!"))
85+}
86+```
87+
88+You can use `os.Setenv` to set the `LANGUAGE` environment variable or set it
89+on a terminal:
90+
91+```sh
92+export LANGUAGE="es_MX.utf8"
93+./gettext-program
94+```
95+
96+Note that `xgettext` does not officially support Go syntax yet, however, you
97+can generate a valid `.pot` file by forcing `xgettest` to use the C++
98+syntax:
99+
100+```sh
101+xgettext -d example -s gettext_test.go -o example.pot -L c++ -i \
102+--keyword=NGettext:1,2 --keyword=Gettext
103+```
104+
105+This will generate a `example.pot` file.
106+
107+After translating the `.pot` file, you must generate `.po` and `.mo` files and
108+remember to set the UTF-8 charset.
109+
110+```sh
111+msginit -l es_MX -o example.po -i example.pot
112+msgfmt -c -v -o example.mo example.po
113+```
114+
115+Finally, move the `.mo` file to an appropriate location.
116+
117+```sh
118+mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo
119+```
120+
121+## Documentation
122+
123+You can read `gosexy/gettext` documentation from a terminal
124+
125+```sh
126+go doc github.com/gosexy/gettext
127+```
128+
129+Or you can [browse it](http://godoc.org/github.com/gosexy/gettext) online.
130+
131+The original gettext documentation could be very useful as well:
132+
133+```sh
134+man 3 gettext
135+```
136+
137+Here's another [good tutorial][2] on using gettext.
138+
139+[1]: http://www.gnu.org/software/gettext/
140+[2]: http://oriya.sarovar.org/docs/gettext_single.html
141
142=== added file 'internal/github.com/gosexy/gettext/gettext.go'
143--- internal/github.com/gosexy/gettext/gettext.go 1970-01-01 00:00:00 +0000
144+++ internal/github.com/gosexy/gettext/gettext.go 2015-08-27 16:20:17 +0000
145@@ -0,0 +1,207 @@
146+/*
147+ Copyright (c) 2012 José Carlos Nieto, http://xiam.menteslibres.org/
148+
149+ Permission is hereby granted, free of charge, to any person obtaining
150+ a copy of this software and associated documentation files (the
151+ "Software"), to deal in the Software without restriction, including
152+ without limitation the rights to use, copy, modify, merge, publish,
153+ distribute, sublicense, and/or sell copies of the Software, and to
154+ permit persons to whom the Software is furnished to do so, subject to
155+ the following conditions:
156+
157+ The above copyright notice and this permission notice shall be
158+ included in all copies or substantial portions of the Software.
159+
160+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
162+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
164+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
165+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
166+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
167+*/
168+
169+package gettext
170+
171+/*
172+
173+#include <libintl.h>
174+#include <locale.h>
175+#include <stdlib.h>
176+*/
177+import "C"
178+
179+import (
180+ "fmt"
181+ "strings"
182+ "unsafe"
183+)
184+
185+var (
186+ // For all of the locale.
187+ LC_ALL = uint(C.LC_ALL)
188+
189+ // For regular expression matching (it determines the meaning of range
190+ // expressions and equivalence classes) and string collation.
191+ LC_COLATE = uint(C.LC_ALL)
192+
193+ // For regular expression matching, character classification, conversion,
194+ // case-sensitive comparison, and wide character functions.
195+ LC_CTYPE = uint(C.LC_CTYPE)
196+
197+ // For localizable natural-language messages.
198+ LC_MESSAGES = uint(C.LC_MESSAGES)
199+
200+ // For monetary formatting.
201+ LC_MONETARY = uint(C.LC_MONETARY)
202+
203+ // For number formatting (such as the decimal point and the thousands
204+ // separator).
205+ LC_NUMERIC = uint(C.LC_NUMERIC)
206+
207+ // For time and date formatting.
208+ LC_TIME = uint(C.LC_TIME)
209+)
210+
211+// Sets or queries the program's current locale.
212+func SetLocale(category uint, locale string) string {
213+ clocale := C.CString(locale)
214+
215+ res := C.GoString(C.setlocale(C.int(category), clocale))
216+
217+ C.free(unsafe.Pointer(clocale))
218+ return res
219+}
220+
221+// Sets directory containing message catalogs.
222+func BindTextdomain(domainname string, dirname string) string {
223+ cdirname := C.CString(dirname)
224+ cdomainname := C.CString(domainname)
225+
226+ res := C.GoString(C.bindtextdomain(cdomainname, cdirname))
227+
228+ C.free(unsafe.Pointer(cdirname))
229+ C.free(unsafe.Pointer(cdomainname))
230+ return res
231+}
232+
233+// Sets the output codeset for message catalogs for domain domainname.
234+func BindTextdomainCodeset(domainname string, codeset string) string {
235+ cdomainname := C.CString(domainname)
236+ ccodeset := C.CString(codeset)
237+
238+ res := C.GoString(C.bind_textdomain_codeset(cdomainname, ccodeset))
239+
240+ C.free(unsafe.Pointer(cdomainname))
241+ C.free(unsafe.Pointer(ccodeset))
242+ return res
243+}
244+
245+// Sets or retrieves the current message domain.
246+func Textdomain(domainname string) string {
247+ cdomainname := C.CString(domainname)
248+
249+ res := C.GoString(C.textdomain(cdomainname))
250+
251+ C.free(unsafe.Pointer(cdomainname))
252+ return res
253+}
254+
255+// Attempt to translate a text string into the user's native language, by
256+// looking up the translation in a message catalog.
257+func Gettext(msgid string) string {
258+ cmsgid := C.CString(msgid)
259+
260+ res := C.GoString(C.gettext(cmsgid))
261+
262+ C.free(unsafe.Pointer(cmsgid))
263+ return res
264+}
265+
266+// Like Gettext(), but looking up the message in the specified domain.
267+func DGettext(domain string, msgid string) string {
268+ cdomain := C.CString(domain)
269+ cmsgid := C.CString(msgid)
270+
271+ res := C.GoString(C.dgettext(cdomain, cmsgid))
272+
273+ C.free(unsafe.Pointer(cdomain))
274+ C.free(unsafe.Pointer(cmsgid))
275+ return res
276+}
277+
278+// Like Gettext(), but looking up the message in the specified domain and
279+// category.
280+func DCGettext(domain string, msgid string, category uint) string {
281+ cdomain := C.CString(domain)
282+ cmsgid := C.CString(msgid)
283+
284+ res := C.GoString(C.dcgettext(cdomain, cmsgid, C.int(category)))
285+
286+ C.free(unsafe.Pointer(cdomain))
287+ C.free(unsafe.Pointer(cmsgid))
288+ return res
289+}
290+
291+// Attempt to translate a text string into the user's native language, by
292+// looking up the appropriate plural form of the translation in a message
293+// catalog.
294+func NGettext(msgid string, msgid_plural string, n uint64) string {
295+ cmsgid := C.CString(msgid)
296+ cmsgid_plural := C.CString(msgid_plural)
297+
298+ res := C.GoString(C.ngettext(cmsgid, cmsgid_plural, C.ulong(n)))
299+
300+ C.free(unsafe.Pointer(cmsgid))
301+ C.free(unsafe.Pointer(cmsgid_plural))
302+
303+ return res
304+}
305+
306+// Like fmt.Sprintf() but without %!(EXTRA) errors.
307+func Sprintf(format string, a ...interface{}) string {
308+ expects := strings.Count(format, "%") - strings.Count(format, "%%")
309+
310+ if expects > 0 {
311+ arguments := make([]interface{}, expects)
312+ for i := 0; i < expects; i++ {
313+ if len(a) > i {
314+ arguments[i] = a[i]
315+ }
316+ }
317+ return fmt.Sprintf(format, arguments...)
318+ }
319+
320+ return format
321+}
322+
323+// Like NGettext(), but looking up the message in the specified domain.
324+func DNGettext(domainname string, msgid string, msgid_plural string, n uint64) string {
325+ cdomainname := C.CString(domainname)
326+ cmsgid := C.CString(msgid)
327+ cmsgid_plural := C.CString(msgid_plural)
328+
329+ res := C.GoString(C.dngettext(cdomainname, cmsgid, cmsgid_plural, C.ulong(n)))
330+
331+ C.free(unsafe.Pointer(cdomainname))
332+ C.free(unsafe.Pointer(cmsgid))
333+ C.free(unsafe.Pointer(cmsgid_plural))
334+
335+ return res
336+}
337+
338+// Like NGettext(), but looking up the message in the specified domain and
339+// category.
340+func DCNGettext(domainname string, msgid string, msgid_plural string, n uint64, category uint) string {
341+ cdomainname := C.CString(domainname)
342+ cmsgid := C.CString(msgid)
343+ cmsgid_plural := C.CString(msgid_plural)
344+
345+ res := C.GoString(C.dcngettext(cdomainname, cmsgid, cmsgid_plural, C.ulong(n), C.int(category)))
346+
347+ C.free(unsafe.Pointer(cdomainname))
348+ C.free(unsafe.Pointer(cmsgid))
349+ C.free(unsafe.Pointer(cmsgid_plural))
350+
351+ return res
352+}
353
354=== added file 'internal/github.com/gosexy/gettext/gettext_test.go'
355--- internal/github.com/gosexy/gettext/gettext_test.go 1970-01-01 00:00:00 +0000
356+++ internal/github.com/gosexy/gettext/gettext_test.go 2015-08-27 16:20:17 +0000
357@@ -0,0 +1,130 @@
358+package gettext
359+
360+import (
361+ "fmt"
362+ "os"
363+ "testing"
364+)
365+
366+/*
367+ NOTE:
368+
369+ xgettext does not officially support Go syntax, however, you can generate a valid .pot file by forcing
370+ xgettest to use the C++ syntax:
371+
372+ % xgettext -d example -s gettext_test.go -o example.pot -L c++ -i --keyword=NGettext:1,2 --keyword=Gettext
373+
374+ This will generate a example.pot file.
375+
376+ After translating the .pot file, you must generate .po and .mo files.
377+
378+ Remember to set the UTF-8 charset.
379+
380+ % msginit -l es_MX -o example.po -i example.pot
381+ % msgfmt -c -v -o example.mo example.po
382+
383+ And finally, move the .mo file to an appropriate location.
384+
385+ % mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo
386+
387+*/
388+
389+func TestSpanishMexico(t *testing.T) {
390+
391+ os.Setenv("LANGUAGE", "es_MX.utf8")
392+
393+ SetLocale(LC_ALL, "")
394+ BindTextdomain("example", "./examples/")
395+ Textdomain("example")
396+
397+ t1 := Gettext("Hello, world!")
398+
399+ fmt.Println(t1)
400+
401+ if t1 != "¡Hola mundo!" {
402+ t.Errorf("Failed translation.")
403+ }
404+
405+ t2 := Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage")
406+
407+ fmt.Println(t2)
408+
409+ if t2 != "Una manzana" {
410+ t.Errorf("Failed translation.")
411+ }
412+
413+ t3 := Sprintf(NGettext("An apple", "%d apples", 3), 3)
414+
415+ fmt.Println(t3)
416+
417+ if t3 != "3 manzanas" {
418+ t.Errorf("Failed translation.")
419+ }
420+
421+ t4 := Gettext("Good morning")
422+
423+ fmt.Println(t4)
424+
425+ if t4 != "Buenos días" {
426+ t.Errorf("Failed translation.")
427+ }
428+
429+ t5 := Gettext("Good bye!")
430+
431+ fmt.Println(t5)
432+
433+ if t5 != "¡Hasta luego!" {
434+ t.Errorf("Failed translation.")
435+ }
436+
437+}
438+
439+func TestGermanDeutschland(t *testing.T) {
440+
441+ os.Setenv("LANGUAGE", "de_DE.utf8")
442+
443+ SetLocale(LC_ALL, "")
444+ BindTextdomain("example", "./examples/")
445+ Textdomain("example")
446+
447+ t1 := Gettext("Hello, world!")
448+
449+ fmt.Println(t1)
450+
451+ if t1 != "Hallo, Welt!" {
452+ t.Errorf("Failed translation.")
453+ }
454+
455+ t2 := Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage")
456+
457+ fmt.Println(t2)
458+
459+ if t2 != "Ein Apfel" {
460+ t.Errorf("Failed translation.")
461+ }
462+
463+ t3 := Sprintf(NGettext("An apple", "%d apples", 3), 3)
464+
465+ fmt.Println(t3)
466+
467+ if t3 != "3 Äpfel" {
468+ t.Errorf("Failed translation.")
469+ }
470+
471+ t4 := Gettext("Good morning")
472+
473+ fmt.Println(t4)
474+
475+ if t4 != "Guten morgen" {
476+ t.Errorf("Failed translation.")
477+ }
478+
479+ t5 := Gettext("Good bye!")
480+
481+ fmt.Println(t5)
482+
483+ if t5 != "Aufwiedersehen!" {
484+ t.Errorf("Failed translation.")
485+ }
486+
487+}
488
489=== modified file 'internal/vendor.json'
490--- internal/vendor.json 2015-07-30 14:22:57 +0000
491+++ internal/vendor.json 2015-08-27 16:20:17 +0000
492@@ -1,68 +1,76 @@
493 {
494 "comment": "",
495+ "ignore": "",
496 "package": [
497 {
498 "canonical": "github.com/AlekSi/gocov-xml",
499 "comment": "",
500- "local": "launchpad.net/unity-scope-snappy/internal/github.com/AlekSi/gocov-xml",
501+ "local": "github.com/AlekSi/gocov-xml",
502 "revision": "d2f6da892a0d5e0b587526abf51349ad654ade51",
503 "revisionTime": "2013-09-03T17:40:06+04:00"
504 },
505 {
506 "canonical": "github.com/axw/gocov",
507 "comment": "",
508- "local": "launchpad.net/unity-scope-snappy/internal/github.com/axw/gocov",
509+ "local": "github.com/axw/gocov",
510 "revision": "3b045e0eb61013ff134e6752184febc47d119f3a",
511 "revisionTime": "2014-11-11T18:30:33+08:00"
512 },
513 {
514 "canonical": "github.com/axw/gocov/gocov",
515 "comment": "",
516- "local": "launchpad.net/unity-scope-snappy/internal/github.com/axw/gocov/gocov",
517+ "local": "github.com/axw/gocov/gocov",
518 "revision": "3b045e0eb61013ff134e6752184febc47d119f3a",
519 "revisionTime": "2014-11-11T18:30:33+08:00"
520 },
521 {
522 "canonical": "github.com/axw/gocov/gocovutil",
523 "comment": "",
524- "local": "launchpad.net/unity-scope-snappy/internal/github.com/axw/gocov/gocovutil",
525+ "local": "github.com/axw/gocov/gocovutil",
526 "revision": "3b045e0eb61013ff134e6752184febc47d119f3a",
527 "revisionTime": "2014-11-11T18:30:33+08:00"
528 },
529 {
530 "canonical": "github.com/dustin/go-humanize",
531 "comment": "",
532- "local": "launchpad.net/unity-scope-snappy/internal/github.com/dustin/go-humanize",
533+ "local": "github.com/dustin/go-humanize",
534 "revision": "c128122e0b9b93799aef8181a537e5d8fd7081d6",
535 "revisionTime": "2015-06-22T22:54:03-07:00"
536 },
537 {
538 "canonical": "github.com/godbus/dbus",
539 "comment": "",
540- "local": "launchpad.net/unity-scope-snappy/internal/github.com/godbus/dbus",
541+ "local": "github.com/godbus/dbus",
542 "revision": "25c3068a42a0b50b877953fb249dbcffc6bd1bca",
543 "revisionTime": "2015-07-29T16:15:27-07:00"
544 },
545 {
546 "canonical": "github.com/godbus/dbus/introspect",
547 "comment": "",
548- "local": "launchpad.net/unity-scope-snappy/internal/github.com/godbus/dbus/introspect",
549+ "local": "github.com/godbus/dbus/introspect",
550 "revision": "25c3068a42a0b50b877953fb249dbcffc6bd1bca",
551 "revisionTime": "2015-07-29T16:15:27-07:00"
552 },
553 {
554+ "canonical": "github.com/gosexy/gettext",
555+ "comment": "",
556+ "local": "github.com/gosexy/gettext",
557+ "revision": "98b7b91596d20b96909e6b60d57411547dd9959c",
558+ "revisionTime": "2013-02-21T06:21:43-05:00"
559+ },
560+ {
561 "canonical": "golang.org/x/tools/cover",
562 "comment": "",
563- "local": "launchpad.net/unity-scope-snappy/internal/golang.org/x/tools/cover",
564+ "local": "golang.org/x/tools/cover",
565 "revision": "af817890aa7b628234075a6cb01a3a435fb8317d",
566 "revisionTime": "2015-06-17T17:25:35-07:00"
567 },
568 {
569 "canonical": "launchpad.net/go-unityscopes/v2",
570 "comment": "",
571- "local": "launchpad.net/unity-scope-snappy/internal/launchpad.net/go-unityscopes/v2",
572+ "local": "launchpad.net/go-unityscopes/v2",
573 "revision": "69",
574 "revisionTime": "2015-06-02T10:39:20+02:00"
575 }
576 ]
577-}
578\ No newline at end of file
579+}

Subscribers

People subscribed via source and target branches