Merge lp:~mvo/snappy/snappy-gettext into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt on 2015-06-17
Status: Merged
Approved by: John Lenton on 2015-06-29
Approved revision: 513
Merged at revision: 527
Proposed branch: lp:~mvo/snappy/snappy-gettext
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Diff against target: 336 lines (+147/-9)
17 files modified
cmd/snappy/cmd_config.go (+1/-1)
cmd/snappy/cmd_install.go (+3/-2)
debian/control (+1/-0)
debian/rules (+5/-0)
debian/ubuntu-snappy-cli.install (+2/-0)
dependencies.tsv (+1/-0)
i18n/i18n.go (+45/-0)
partition/bootloader_uboot_test.go (+1/-1)
partition/partition.go (+1/-1)
po/de.po (+21/-0)
po/snappy.pot (+24/-0)
run-checks (+9/-0)
snappy/click.go (+3/-1)
snappy/click_test.go (+1/-2)
snappy/dirs.go (+3/-0)
snappy/errors.go (+1/-1)
update-pot (+25/-0)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-gettext
Reviewer Review Type Date Requested Status
John Lenton 2015-06-17 Approve on 2015-06-29
Review via email: mp+262202@code.launchpad.net

Commit Message

Add support for gettext.

Description of the Change

This branch adds gettext support. Based on the excellent work from Mike Terry, thanks a bunch.

Note that this can only be merged once the build-depdenency get accepted (https://launchpad.net/ubuntu/wily/+queue)

To post a comment you must log in.
Sergio Schvezov (sergiusens) wrote :

Looks good, can we add a simple test here or is it better to integration test translations?

Michael Vogt (mvo) wrote :

Fwiw, I uploaded the packaged golang-gettext package to wily now.

lp:~mvo/snappy/snappy-gettext updated on 2015-06-18
513. By Michael Vogt on 2015-06-18

cmd/snappy/cmd_config.go: remove spaces at the end

Michael Vogt (mvo) wrote :

Thanks, I addressed the comments. I also added a lp:~mvo/snappy/snappy-gettext2 with a unittest test. I will file a separate MP for this.

John Lenton (chipaca) :
review: Approve
John Lenton (chipaca) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/snappy/cmd_config.go'
2--- cmd/snappy/cmd_config.go 2015-05-19 14:09:19 +0000
3+++ cmd/snappy/cmd_config.go 2015-06-18 07:23:41 +0000
4@@ -38,7 +38,7 @@
5
6 const shortConfigHelp = `Set configuration for an installed package.`
7
8-const longConfigHelp = `Configures a package. The configuration is a YAML file, provided in the specified file which can be "-" for stdin. Output of the command is the current configuration, so running this command with no input file provides a snapshot of the app's current config. `
9+const longConfigHelp = "Configures a package. The configuration is a YAML file, provided in the specified file which can be \"-\" for stdin. Output of the command is the current configuration, so running this command with no input file provides a snapshot of the app's current config."
10
11 func init() {
12 _, err := parser.AddCommand("config",
13
14=== modified file 'cmd/snappy/cmd_install.go'
15--- cmd/snappy/cmd_install.go 2015-06-15 07:38:57 +0000
16+++ cmd/snappy/cmd_install.go 2015-06-18 07:23:41 +0000
17@@ -24,6 +24,7 @@
18 "fmt"
19 "os"
20
21+ "launchpad.net/snappy/i18n"
22 "launchpad.net/snappy/logger"
23 "launchpad.net/snappy/progress"
24 "launchpad.net/snappy/snappy"
25@@ -40,8 +41,8 @@
26
27 func init() {
28 _, err := parser.AddCommand("install",
29- "Install a snap package",
30- "Install a snap package",
31+ i18n.G("Install a snap package"),
32+ i18n.G("Install a snap package"),
33 &cmdInstall{})
34 if err != nil {
35 logger.Panicf("Unable to install: %v", err)
36
37=== modified file 'debian/control'
38--- debian/control 2015-06-02 20:46:07 +0000
39+++ debian/control 2015-06-18 07:23:41 +0000
40@@ -9,6 +9,7 @@
41 fakeroot,
42 golang-ar-dev,
43 golang-check.v1-dev,
44+ golang-gettext-dev,
45 golang-go,
46 golang-go-flags-dev,
47 golang-go.crypto-dev,
48
49=== modified file 'debian/rules'
50--- debian/rules 2015-04-14 16:46:57 +0000
51+++ debian/rules 2015-06-18 07:23:41 +0000
52@@ -50,6 +50,11 @@
53 -pubuntu-snappy \
54 snappy-autopilot.service
55
56+override_dh_auto_build:
57+ # this will update the i18n stuff
58+ go generate ./snappy
59+ dh_auto_build
60+
61 override_dh_auto_install:
62 dh_auto_install -O--buildsystem=golang
63 # Making the packages private
64
65=== modified file 'debian/ubuntu-snappy-cli.install'
66--- debian/ubuntu-snappy-cli.install 2015-03-27 08:28:08 +0000
67+++ debian/ubuntu-snappy-cli.install 2015-06-18 07:23:41 +0000
68@@ -1,2 +1,4 @@
69 /usr/bin/snappy
70 data/completion/snappy /usr/share/bash-completion/completions/
71+# i18n stuff
72+share /usr
73\ No newline at end of file
74
75=== modified file 'dependencies.tsv'
76--- dependencies.tsv 2015-06-02 20:46:07 +0000
77+++ dependencies.tsv 2015-06-18 07:23:41 +0000
78@@ -1,6 +1,7 @@
79 code.google.com/p/go.crypto hg 69e2a90ed92d03812364aeb947b7068dc42e561e 235
80 github.com/blakesmith/ar git c9a977dd0cc1392b023382c7bfa5a22af8d3b730 2013-02-19T04:59:55Z
81 github.com/cheggaaa/pb git e8c7cc515bfde3e267957a3b110080ceed51354e 2014-12-02T07:01:21Z
82+github.com/gosexy/gettext git 98b7b91596d20b96909e6b60d57411547dd9959c 2013-02-21T11:21:43Z
83 github.com/jessevdk/go-flags git 15347ef417a300349807983f15af9e65cd2e1b3a 2015-01-25T08:53:51Z
84 github.com/mvo5/goconfigparser git 26426272dda20cc76aa1fa44286dc743d2972fe8 2015-02-12T09:37:50Z
85 gopkg.in/check.v1 git 64131543e7896d5bcc6bd5a76287eb75ea96c673 2014-10-24T13:38:53Z
86
87=== added directory 'i18n'
88=== added file 'i18n/i18n.go'
89--- i18n/i18n.go 1970-01-01 00:00:00 +0000
90+++ i18n/i18n.go 2015-06-18 07:23:41 +0000
91@@ -0,0 +1,45 @@
92+// -*- Mode: Go; indent-tabs-mode: t -*-
93+
94+/*
95+ * Copyright (C) 2014-2015 Canonical Ltd
96+ *
97+ * This program is free software: you can redistribute it and/or modify
98+ * it under the terms of the GNU General Public License version 3 as
99+ * published by the Free Software Foundation.
100+ *
101+ * This program is distributed in the hope that it will be useful,
102+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
103+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104+ * GNU General Public License for more details.
105+ *
106+ * You should have received a copy of the GNU General Public License
107+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
108+ *
109+ */
110+
111+package i18n
112+
113+//go:generate ../update-pot
114+
115+import (
116+ "github.com/gosexy/gettext"
117+)
118+
119+// Note that we have to use dgettext() here because we are a library
120+// and we can not use getext.Textdomain() as this would override the
121+// applications default
122+const TEXTDOMAIN = "snappy"
123+
124+// G is the shorthand for Gettext
125+var G = func(msgid string) string {
126+ return gettext.DGettext(TEXTDOMAIN, msgid)
127+}
128+
129+// NG is the shorthand for NGettext
130+var NG = func(msgid string, msgid_plural string, n uint64) string {
131+ return gettext.DNGettext(TEXTDOMAIN, msgid, msgid_plural, n)
132+}
133+
134+func init() {
135+ gettext.SetLocale(gettext.LC_ALL, "")
136+}
137
138=== modified file 'partition/bootloader_uboot_test.go'
139--- partition/bootloader_uboot_test.go 2015-06-12 05:23:40 +0000
140+++ partition/bootloader_uboot_test.go 2015-06-18 07:23:41 +0000
141@@ -56,7 +56,7 @@
142 snappy_stamp=snappy-stamp.txt
143 # either "regular" (normal boot) or "try" when trying a new version
144 snappy_mode=regular
145-# if we're trying a new version, check if stamp file is already there to revert
146+# if we are trying a new version, check if stamp file is already there to revert
147 # to other version
148 snappy_boot=if test "${snappy_mode}" = "try"; then if test -e mmc ${bootpart} ${snappy_stamp}; then if test "${snappy_ab}" = "a"; then setenv snappy_ab "b"; else setenv snappy_ab "a"; fi; else fatwrite mmc ${mmcdev}:${mmcpart} 0x0 ${snappy_stamp} 0; fi; fi; run loadfiles; setenv mmcroot /dev/disk/by-label/system-${snappy_ab} ${snappy_cmdline}; run mmcargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} ${fdtaddr}
149 `
150
151=== modified file 'partition/partition.go'
152--- partition/partition.go 2015-06-09 17:43:20 +0000
153+++ partition/partition.go 2015-06-18 07:23:41 +0000
154@@ -386,7 +386,7 @@
155 name := tmp[0]
156
157 // remove quotes
158- value := strings.Trim(tmp[1], `"`)
159+ value := strings.Trim(tmp[1], "\"")
160
161 // store
162 fields[name] = value
163
164=== added directory 'po'
165=== added file 'po/de.po'
166--- po/de.po 1970-01-01 00:00:00 +0000
167+++ po/de.po 2015-06-18 07:23:41 +0000
168@@ -0,0 +1,21 @@
169+# SOME DESCRIPTIVE TITLE.
170+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
171+# This file is distributed under the same license as the PACKAGE package.
172+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
173+#
174+#, fuzzy
175+msgid ""
176+msgstr "Project-Id-Version: snappy\n"
177+ "Report-Msgid-Bugs-To: snappy-devel@lists.ubuntu.com\n"
178+ "POT-Creation-Date: 2015-06-16 09:08+0200\n"
179+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
180+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
181+ "Language-Team: LANGUAGE <LL@li.org>\n"
182+ "Language: \n"
183+ "MIME-Version: 1.0\n"
184+ "Content-Type: text/plain; charset=CHARSET\n"
185+ "Content-Transfer-Encoding: 8bit\n"
186+
187+#. TRANSLATORS: the first %q is the file that can not be read and %v is the error message
188+msgid "Can't read hook file %q: %v"
189+msgstr "Kann die Hook Datei %q nicht lesen: %v"
190
191=== added file 'po/snappy.pot'
192--- po/snappy.pot 1970-01-01 00:00:00 +0000
193+++ po/snappy.pot 2015-06-18 07:23:41 +0000
194@@ -0,0 +1,24 @@
195+# SOME DESCRIPTIVE TITLE.
196+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
197+# This file is distributed under the same license as the PACKAGE package.
198+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
199+#
200+#, fuzzy
201+msgid ""
202+msgstr "Project-Id-Version: snappy\n"
203+ "Report-Msgid-Bugs-To: snappy-devel@lists.ubuntu.com\n"
204+ "POT-Creation-Date: 2015-06-17 14:01+0200\n"
205+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
206+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
207+ "Language-Team: LANGUAGE <LL@li.org>\n"
208+ "Language: \n"
209+ "MIME-Version: 1.0\n"
210+ "Content-Type: text/plain; charset=CHARSET\n"
211+ "Content-Transfer-Encoding: 8bit\n"
212+
213+#. TRANSLATORS: the first %q is the file that can not be read and %v is the error message
214+msgid "Can't read hook file %q: %v"
215+msgstr ""
216+
217+msgid "Install a snap package"
218+msgstr ""
219
220=== modified file 'run-checks'
221--- run-checks 2015-06-09 15:35:35 +0000
222+++ run-checks 2015-06-18 07:23:41 +0000
223@@ -55,6 +55,15 @@
224 exit 1
225 fi
226
227+# pot file
228+TMPF="$(mktemp)"
229+./update-pot "$TMPF"
230+trap "rm -f $TMPF" 0
231+if ! diff --ignore-matching-lines=.*POT-Creation-Date.* po/snappy.pot $TMPF; then
232+ echo "You need to run ./update-pot"
233+ exit 1
234+fi
235+
236 # integration tests
237 if which adt-run >/dev/null 2>&1; then
238 echo "Running integration tests"
239
240=== modified file 'snappy/click.go'
241--- snappy/click.go 2015-06-10 09:25:34 +0000
242+++ snappy/click.go 2015-06-18 07:23:41 +0000
243@@ -43,6 +43,7 @@
244
245 "launchpad.net/snappy/clickdeb"
246 "launchpad.net/snappy/helpers"
247+ "launchpad.net/snappy/i18n"
248 "launchpad.net/snappy/logger"
249 "launchpad.net/snappy/pkg"
250 "launchpad.net/snappy/progress"
251@@ -158,7 +159,8 @@
252 for _, f := range hookFiles {
253 hook, err := readClickHookFile(f)
254 if err != nil {
255- logger.Noticef("Can't read hook file %q: %v", f, err)
256+ //TRANSLATORS: the first %q is the file that can not be read and %v is the error message
257+ logger.Noticef(i18n.G("Can't read hook file %q: %v"), f, err)
258 continue
259 }
260 hooks[hook.name] = hook
261
262=== modified file 'snappy/click_test.go'
263--- snappy/click_test.go 2015-06-10 09:25:34 +0000
264+++ snappy/click_test.go 2015-06-18 07:23:41 +0000
265@@ -1311,8 +1311,7 @@
266
267 func (s *SnapTestSuite) TestServiceWhitelistError(c *C) {
268 err := verifyServiceYaml(Service{Name: "x\n"})
269- c.Assert(err.Error(), Equals, `services description field 'Name' contains illegal 'x
270-' (legal: '^[A-Za-z0-9/. _#:-]*$')`)
271+ c.Assert(err.Error(), Equals, "services description field 'Name' contains illegal 'x\n' (legal: '^[A-Za-z0-9/. _#:-]*$')")
272 }
273
274 func (s *SnapTestSuite) TestBinariesWhitelistSimple(c *C) {
275
276=== modified file 'snappy/dirs.go'
277--- snappy/dirs.go 2015-05-15 13:33:27 +0000
278+++ snappy/dirs.go 2015-06-18 07:23:41 +0000
279@@ -32,6 +32,7 @@
280 snapAppArmorDir string
281 snapSeccompDir string
282 snapUdevRulesDir string
283+ localeDir string
284
285 snapBinariesDir string
286 snapServicesDir string
287@@ -62,4 +63,6 @@
288 cloudMetaDataFile = filepath.Join(rootdir, "/var/lib/cloud/seed/nocloud-net/meta-data")
289
290 snapUdevRulesDir = filepath.Join(rootdir, "/etc/udev/rules.d")
291+
292+ localeDir = filepath.Join(rootdir, "/usr/share/locale")
293 }
294
295=== modified file 'snappy/errors.go'
296--- snappy/errors.go 2015-06-04 22:21:51 +0000
297+++ snappy/errors.go 2015-06-18 07:23:41 +0000
298@@ -90,7 +90,7 @@
299
300 // ErrInvalidFrameworkSpecInYaml is returned if a package.yaml
301 // has both frameworks and framework entries.
302- ErrInvalidFrameworkSpecInYaml = errors.New(`yaml can't have both "frameworks" and (deprecated) "framework" keys`)
303+ ErrInvalidFrameworkSpecInYaml = errors.New("yaml can't have both \"frameworks\" and (deprecated) \"framework\" keys")
304
305 // ErrSnapNotActive is returned if you try to unset a snap from
306 // active to inactive
307
308=== added file 'update-pot'
309--- update-pot 1970-01-01 00:00:00 +0000
310+++ update-pot 2015-06-18 07:23:41 +0000
311@@ -0,0 +1,25 @@
312+#!/bin/sh
313+# -*- Mode: sh; indent-tabs-mode: t -*-
314+
315+set -e
316+
317+HERE="$(dirname $0)"
318+
319+OUTPUT="$HERE/po/snappy.pot"
320+if [ -n "$1" ]; then
321+ OUTPUT="$1"
322+fi
323+
324+xgettext -d snappy -o "$OUTPUT" --c++ --from-code=UTF-8 \
325+ --indent --add-comments --no-location --sort-output \
326+ --package-name=snappy \
327+ --msgid-bugs-address=snappy-devel@lists.ubuntu.com \
328+ --keyword=NG:1,2 --keyword=G \
329+ $HERE/*/*.go $HERE/cmd/*/*.go
330+
331+# language packs
332+for p in po/*.po; do
333+ lang=$(basename $p .po)
334+ mkdir -p $HERE/share/locale/$lang/LC_MESSAGES
335+ msgfmt -v -o $HERE/share/locale/$lang/LC_MESSAGES/snappy.mo $p 2>/dev/null
336+done

Subscribers

People subscribed via source and target branches