gettext-setup 0.10 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84bde18372c4c8e6e9284ab8a2b08d40114d779a
4
- data.tar.gz: fc28ee6ae71e5e5113325a563ebaa9c0a489a723
3
+ metadata.gz: 7c5ec999e9e07642d3bc10efa9a6e0acfeef995d
4
+ data.tar.gz: 11b5919a0c12d5911c73bb79de5d78d43a4e49db
5
5
  SHA512:
6
- metadata.gz: aed2ca08cbbcd8254a95bdf4bc9798a69d0a9ef6550663031cf177e378a57727b4054a58ea7bfd4031be2cb84f62ef456dc32a691bc677aa8425ee7ffd56ba92
7
- data.tar.gz: fa302dc3515258ab8693f691f7eb8d4eee83ad92a74643251cbc764081127e6030776649c52ca4574048afc07a78a7c04946dd0f80ca64a4f076b0e05dcfc798
6
+ metadata.gz: 68067a707c35788e682e74abe89afc11cdc580b6dddec91e34663afe5b1e9bcc384e7472e6781aae9bbbc6844037aa615d7c3e85f53879f2087e2548dff7a63d
7
+ data.tar.gz: d8e73f312ab6690ddc336ef336469d9a56e7e7103d2885f18c330f0993bef9d69683b720ff50ba5491f6d5c01855f4d1de622e9f18d59e56d96c6071ed49d89b
data/README.md CHANGED
@@ -12,11 +12,11 @@ This project sets the default locale to English. If the user has set a different
12
12
 
13
13
  **PO file** - A bilingual file containing the source English strings (msgid) and target language strings (msgstr). This file is generated from the POT file and is where translated strings are added. A PO file is generated for each language.
14
14
 
15
- **Transifex** - A translation management system. When PO files are updated, the updates are pulled into Transifex and translated there.
15
+ **Transifex** - A translation management system. When POT files are updated, the updates are pushed to Transifex. Transifex generates a PO file for each language that has been set up in the Transifex project. Translators enter the string translations in the PO for their language.
16
16
 
17
17
  ## Setup for your project
18
18
 
19
- These are the poingant bits of this example that you need to replicate in
19
+ These are the poignant bits of this example that you need to replicate in
20
20
  your project:
21
21
 
22
22
  1. Add `gem 'gettext-setup'` to your `Gemfile`.
@@ -24,18 +24,21 @@ your project:
24
24
  `locales` directory as `config.yaml`.
25
25
  1. Edit `locales/config.yaml` and make the necessary changes for your
26
26
  project
27
- 1. Add these three lines to your `Rakefile`:
27
+ 1. Add these three lines to your `Rakefile`, ensuring the `locales`
28
+ directory is found by the last line:
28
29
  ```
29
30
  spec = Gem::Specification.find_by_name 'gettext-setup'
30
31
  load "#{spec.gem_dir}/lib/tasks/gettext.rake"
31
32
  GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
32
33
  ```
33
- 1. Add this line to the top of your `app.rb`:
34
+ 1. Add these lines at the start of your app (`app.rb` for server-side, the executable binary for CLI applications):
34
35
  `require 'gettext-setup'`
35
- 1. Add these lines inside the class declared in your `app.rb`:
36
+ `GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))`
37
+ (Note that the second line may require modification to find the `locales` directory.
38
+ 1. For client-side applications, add this line:
39
+ `FastGettext.locale = GettextSetup.negotiate_locale(GettextSetup.candidate_locales)`
40
+ 1. For server-side applications, add these lines:
36
41
  ```
37
- include FastGettext::Translation
38
- GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
39
42
  before do
40
43
  FastGettext.locale = GettextSetup.negotiate_locale(env["HTTP_ACCEPT_LANGUAGE"])
41
44
  end
@@ -78,26 +81,21 @@ The `msgid_plural` is the plural version of the English source string.
78
81
 
79
82
  The two `msgstr` lines show that German has two rules for pluralization. The indices map to the `Plural-Forms: nplurals=2; plural=(n > 1);` rule that we specified in the PO file. The `[0]` index represents `plural=(n > 1)` and the `[1]` index represents all other pluralization cases (in other words, when the count equals 0 or 1).
80
83
 
84
+ When Transifex generates a PO file for a specific language, it automatically adds the appropriate pluralization rules in the PO file.
85
+
81
86
  ### Comments
82
- To provide translators with some contextual information or instructions about a string, precede the string with a comment. Start the comment with "TRANSLATOR: " to make it obvious that you are providing instructions for the translator. The comment gets pulled in to the POT file and will show up as a comment in Transifex.
87
+ To provide translators with some contextual information or instructions about a string, precede the string with a comment using `#. `. The comment gets pulled in to the POT file and will show up as a comment in Transifex.
83
88
 
84
- E.g. `# TRANSLATOR: The placeholder in this string represents the name of a parameter.`
89
+ E.g. `#. The placeholder in this string represents the name of a parameter.`
85
90
 
86
91
  ## Translation workflow
87
92
 
88
93
  1. Wrap the translation function around translatable strings in code files
89
94
 
90
- 2. Run `rake gettext:pot` to parse the source code and extract translatable strings into the message catalog in `locales/<project_name>.pot`. If a POT file already exists, this rake task will update the POT file. Do this before making a pull request that includes changes to user-facing strings.
91
-
92
- 3. Run `rake gettext:po[<lang>]` to create/update language-specific PO files. This step will be managed by the localization team, and will usually happen prior to a new release.
93
-
94
- 4. When a PO file is updated, a git hook is used to automatically pull the new/updated strings into Transifex ready for translation.
95
-
96
- 5. When the PO file reaches 100% translated and reviewed in Transifex, it is pulled back into the locale folder.
95
+ 2. A CI job checks code commits to see if any changes have been made to user-facing strings. If changes have been made, the CI job parses the source code and extracts translatable strings into a POT file. If a POT file already exists, the CI job will update the existing POT file. (If the CI job hasn't already been added to your pipeline, you will need to add it.)
97
96
 
98
- 6. PE checks the user's locale settings (the browser settings for web apps, or the system settings for the CLI). If we support the preferred locale, PE uses the PO file for that locale. Otherwise, it uses the default locale (en_US).
97
+ 3. When a POT file is updated, the Transifex webhook pushes the new POT file to Transifex ready for translation. (If your POT file hasn't been added to the Transifex integration yet, you will need to get it added.)
99
98
 
100
- ## TODO
99
+ 4. When a PO file reaches 100% translated and reviewed, a webhook pushes it back to the source repo ready to be consumed by your app.
101
100
 
102
- 1. Locale-specific formatting of numbers, dates, etc.
103
- 2. Separate out the locales that are supported for testing/dev and production so we can add test translations without shipping them.
101
+ 5. Your app checks the user's locale settings (the browser settings for web apps, or the system settings for the CLI). If we support the user's preferred locale, the app will display strings in the user's language. Otherwise, it defaults to English.
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'fast_gettext'
3
3
  require 'yaml'
4
+ require 'locale'
4
5
 
5
6
  module GettextSetup
6
7
  @@config = nil
@@ -32,6 +33,8 @@ module GettextSetup
32
33
  # Likewise, be explicit in our default language choice.
33
34
  FastGettext.default_locale = default_locale
34
35
  FastGettext.default_available_locales = locales
36
+
37
+ Locale.set_default(default_locale)
35
38
  end
36
39
 
37
40
  def self.locales_path
@@ -46,6 +49,12 @@ module GettextSetup
46
49
  config['default_locale'] || "en"
47
50
  end
48
51
 
52
+ # Returns the locale for the current machine. This is most useful for shell
53
+ # applications that need an ACCEPT-LANGUAGE header set.
54
+ def self.candidate_locales
55
+ Locale.candidates(type: :cldr).join(',')
56
+ end
57
+
49
58
  def self.locales
50
59
  explicit = Dir.glob(File::absolute_path('*/*.po', locales_path)).map do |x|
51
60
  File::basename(File::dirname(x))
@@ -34,13 +34,20 @@ namespace :gettext do
34
34
 
35
35
  desc "Update pot files"
36
36
  task :pot do
37
- package_name = GettextSetup.config['package_name']
38
- project_name = GettextSetup.config['project_name']
39
- bugs_address = GettextSetup.config['bugs_address']
40
- copyright_holder = GettextSetup.config['copyright_holder']
37
+ config = GettextSetup.config
38
+ package_name = config['package_name']
39
+ project_name = config['project_name']
40
+ bugs_address = config['bugs_address']
41
+ copyright_holder = config['copyright_holder']
42
+ # Done this way to allow the user to enter an empty string in the config.
43
+ if config.has_key?('comments_tag')
44
+ comments_tag = config['comments_tag']
45
+ else
46
+ comments_tag = 'TRANSLATORS'
47
+ end
41
48
  version=`git describe`
42
49
  system("rxgettext -o locales/#{project_name}.pot --no-wrap --sort-by-file " +
43
- "--no-location --add-comments --msgid-bugs-address '#{bugs_address}' " +
50
+ "--no-location --add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " +
44
51
  "--package-name '#{package_name}' " +
45
52
  "--package-version '#{version}' " +
46
53
  "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
@@ -15,6 +15,10 @@ gettext:
15
15
  bugs_address: docs@puppetlabs.com
16
16
  # The holder of the copyright.
17
17
  copyright_holder: Puppet Labs, LLC.
18
+ # This determines which comments in code should be eligible for translation.
19
+ # Any comments that start with this string will be externalized. (Leave
20
+ # empty to include all.)
21
+ comments_tag: TRANSLATORS
18
22
  # Patterns for +Dir.glob+ used to find all files that might contain
19
23
  # translatable content, relative to the project root directory
20
24
  source_files:
metadata CHANGED
@@ -1,167 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext-setup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.10'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: gettext
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - '>='
17
+ - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: 3.0.2
19
- name: gettext
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.2
27
27
  - !ruby/object:Gem::Dependency
28
+ name: fast_gettext
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: 1.1.0
33
- name: fast_gettext
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.0
41
41
  - !ruby/object:Gem::Dependency
42
+ name: locale
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ~>
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: '1.3'
47
- name: bundler
47
+ version: '0'
48
+ type: :runtime
48
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
49
62
  type: :development
63
+ prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
70
+ name: rake
56
71
  requirement: !ruby/object:Gem::Requirement
57
72
  requirements:
58
- - - '>='
73
+ - - ">="
59
74
  - !ruby/object:Gem::Version
60
75
  version: '0'
61
- name: rake
62
- prerelease: false
63
76
  type: :development
77
+ prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
84
+ name: rack-test
70
85
  requirement: !ruby/object:Gem::Requirement
71
86
  requirements:
72
- - - '>='
87
+ - - ">="
73
88
  - !ruby/object:Gem::Version
74
89
  version: '0'
75
- name: rack-test
76
- prerelease: false
77
90
  type: :development
91
+ prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
98
+ name: rspec
84
99
  requirement: !ruby/object:Gem::Requirement
85
100
  requirements:
86
- - - ~>
101
+ - - "~>"
87
102
  - !ruby/object:Gem::Version
88
103
  version: '3.1'
89
- name: rspec
90
- prerelease: false
91
104
  type: :development
105
+ prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ~>
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3.1'
97
111
  - !ruby/object:Gem::Dependency
112
+ name: rspec-core
98
113
  requirement: !ruby/object:Gem::Requirement
99
114
  requirements:
100
- - - ~>
115
+ - - "~>"
101
116
  - !ruby/object:Gem::Version
102
117
  version: '3.1'
103
- name: rspec-core
104
- prerelease: false
105
118
  type: :development
119
+ prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ~>
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '3.1'
111
125
  - !ruby/object:Gem::Dependency
126
+ name: rspec-expectations
112
127
  requirement: !ruby/object:Gem::Requirement
113
128
  requirements:
114
- - - ~>
129
+ - - "~>"
115
130
  - !ruby/object:Gem::Version
116
131
  version: '3.1'
117
- name: rspec-expectations
118
- prerelease: false
119
132
  type: :development
133
+ prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ~>
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '3.1'
125
139
  - !ruby/object:Gem::Dependency
140
+ name: rspec-mocks
126
141
  requirement: !ruby/object:Gem::Requirement
127
142
  requirements:
128
- - - ~>
143
+ - - "~>"
129
144
  - !ruby/object:Gem::Version
130
145
  version: '3.1'
131
- name: rspec-mocks
132
- prerelease: false
133
146
  type: :development
147
+ prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ~>
150
+ - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: '3.1'
139
153
  - !ruby/object:Gem::Dependency
154
+ name: simplecov
140
155
  requirement: !ruby/object:Gem::Requirement
141
156
  requirements:
142
- - - '>='
157
+ - - ">="
143
158
  - !ruby/object:Gem::Version
144
159
  version: '0'
145
- name: simplecov
146
- prerelease: false
147
160
  type: :development
161
+ prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - '>='
164
+ - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  - !ruby/object:Gem::Dependency
168
+ name: webmock
154
169
  requirement: !ruby/object:Gem::Requirement
155
170
  requirements:
156
- - - '>='
171
+ - - ">="
157
172
  - !ruby/object:Gem::Version
158
173
  version: '0'
159
- name: webmock
160
- prerelease: false
161
174
  type: :development
175
+ prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
- - - '>='
178
+ - - ">="
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0'
167
181
  description: A gem to ease i18n
@@ -186,29 +200,29 @@ homepage: https://github.com/puppetlabs/gettext-setup-gem
186
200
  licenses:
187
201
  - Apache-2.0
188
202
  metadata: {}
189
- post_install_message:
203
+ post_install_message:
190
204
  rdoc_options: []
191
205
  require_paths:
192
206
  - lib
193
207
  required_ruby_version: !ruby/object:Gem::Requirement
194
208
  requirements:
195
- - - '>='
209
+ - - ">="
196
210
  - !ruby/object:Gem::Version
197
211
  version: '0'
198
212
  required_rubygems_version: !ruby/object:Gem::Requirement
199
213
  requirements:
200
- - - '>='
214
+ - - ">="
201
215
  - !ruby/object:Gem::Version
202
216
  version: '0'
203
217
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.4.5
206
- signing_key:
218
+ rubyforge_project:
219
+ rubygems_version: 2.2.2
220
+ signing_key:
207
221
  specification_version: 4
208
222
  summary: A gem to ease internationalization with fast_gettext
209
223
  test_files:
210
- - spec/spec_helper.rb
211
224
  - spec/fixtures/locales/config.yaml
212
- - spec/fixtures/locales/sinatra-i18n.pot
213
225
  - spec/fixtures/locales/de/sinatra-i18n.po
226
+ - spec/fixtures/locales/sinatra-i18n.pot
214
227
  - spec/lib/gettext_setup_spec.rb
228
+ - spec/spec_helper.rb