gettext-setup 0.29 → 0.30

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: f8da8fd9251397ed014f16b48dea5b14640d800c
4
- data.tar.gz: d627fbab3ccae583c2762a035138446afb01648e
3
+ metadata.gz: 55e7c36131dbc622484fd2d752352dc235c82cf7
4
+ data.tar.gz: ef5a82547c41f8336cbcaa251ba4e1c0a0278d89
5
5
  SHA512:
6
- metadata.gz: 1e628881df88dfc63c0626b1aa807175c8a3d9cb12a42da9e10fef82beb7fd8fb7b7e3f7c4c032eeea1cf58397eccdb9bf8da94f34174a4d810d07c6ab839b56
7
- data.tar.gz: 22de28a46e580a41f0e8322b0ebf88349f8de4ac46124537b579d8406ce837a0ebd52cb8021765e59a1879fb9981f6fc4e54dbddde3396b4477300ae3b74dbcf
6
+ metadata.gz: 634692fe3c69bc1ab9dca17f1460dc3013ac32054757c7553531e316dd7de6fbe937396d898db50cfb155d3315bb6119c000642f07e15fd5862dd803f5f4e335
7
+ data.tar.gz: 9e9b644e6baa63327de33e7ce2ca46cebeda5533f28acea6cc9afc47289065db878c9d2a28672b0e7762b50fad2bc8218f09a27b1702268d2dc09df7c667602b
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # gettext-setup gem
2
2
 
3
- This is a simple gem to set up i18n for Ruby projects (including [Sinatra](www.sinatrarb.com/) web apps) using gettext and fast gettext.
3
+ This is a simple gem to set up i18n for Ruby projects (including [Sinatra](http://www.sinatrarb.com/) web apps) using gettext and fast gettext.
4
4
 
5
5
  This project sets the default locale to English. If the user has set a different locale in their browser preferences, and we support the user's preferred locale, strings and data formatting will be customized for that locale.
6
6
 
@@ -16,34 +16,34 @@ This project sets the default locale to English. If the user has set a different
16
16
 
17
17
  ## Setup for your project
18
18
 
19
- These are the poignant bits of this example that you need to replicate in
20
- your project:
19
+ These are the poignant bits of this example that you need to replicate in your project:
21
20
 
22
21
  1. Add `gem 'gettext-setup'` to your `Gemfile`.
23
- 1. Copy `locales/config-sample.yaml` to your project and put it into a
22
+ 2. Copy `locales/config-sample.yaml` to your project and put it into a
24
23
  `locales` directory as `config.yaml`.
25
- 1. Edit `locales/config.yaml` and make the necessary changes for your
26
- project
27
- 1. Add these three lines to your `Rakefile`, ensuring the `locales`
28
- directory is found by the last line:
29
- ```
30
- spec = Gem::Specification.find_by_name 'gettext-setup'
31
- load "#{spec.gem_dir}/lib/tasks/gettext.rake"
32
- GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
33
- ```
34
- 1. Add these lines at the start of your app (`app.rb` for server-side, the executable binary for CLI applications):
35
- `require 'gettext-setup'`
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
- `GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)`
40
- 1. For server-side applications, add these lines:
41
- ```
42
- before do
43
- GettextSetup.negotiate_locale!(env["HTTP_ACCEPT_LANGUAGE"])
44
- end
45
- ```
46
-
24
+ 3. Edit `locales/config.yaml` and make the necessary changes for your project
25
+ 4. Add these three lines to your `Rakefile`, ensuring the `locales` directory is found by the last line:
26
+ ```ruby
27
+ spec = Gem::Specification.find_by_name 'gettext-setup'
28
+ load "#{spec.gem_dir}/lib/tasks/gettext.rake"
29
+ GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
30
+ ```
31
+ 5. Add these lines at the start of your app (`app.rb` for server-side, the executable binary for CLI applications):
32
+ ```ruby
33
+ require 'gettext-setup'
34
+ GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
35
+ ```
36
+ Note that the second line may require modification to find the `locales` directory.
37
+ 6. For client-side applications, add this line:
38
+ ```ruby
39
+ GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)
40
+ ```
41
+ 7. For server-side applications, add these lines:
42
+ ```ruby
43
+ before do
44
+ GettextSetup.negotiate_locale!(env["HTTP_ACCEPT_LANGUAGE"])
45
+ end
46
+ ```
47
47
  ## Writing translatable code
48
48
 
49
49
  ### Use full sentences
@@ -67,13 +67,16 @@ E.g. `n_("There is %{count} bicycle in %{city}", "There are %{count} bicycles in
67
67
 
68
68
  Pluralization rules vary across languages. The pluralization rules are specified in the PO file and look something like this `Plural-Forms: nplurals=2; plural=(n > 1);`. This is the pluralization rule for German. It means that German has two pluralization rules. The first rule is `plural=n > 1)` and the second rule is all other counts.
69
69
 
70
- Plurals are selected from the PO file by index. Here's an example of how a
71
- pluralized string is handled in a PO file:
70
+ Plurals are selected from the PO file by index.
71
+
72
+ Here's an example of how a pluralized string is handled in a PO file:
72
73
 
73
- `msgid "%{count} file"
74
- `msgid_plural "%{count} files"
75
- `msgstr[0] "%{count} Dateien"
76
- `msgstr[1] "%{count} Datei"
74
+ ```
75
+ msgid "%{count} file"
76
+ msgid_plural "%{count} files"
77
+ msgstr[0] "%{count} Dateien"
78
+ msgstr[1] "%{count} Datei"
79
+ ```
77
80
 
78
81
  The `msgid` is the singular version of the English source string that's pulled in to the POT file and PO from the code file.
79
82
 
@@ -102,11 +105,11 @@ E.g. `#. The placeholder in this string represents the name of a parameter.`
102
105
 
103
106
  ## Merge Pot files rake task
104
107
 
105
- The rake task that merges .pot files is present for the internationalisation of a module. This task uses 'msgcat', which is only natively present on OSes that are GNU based. For running this task locally on another OS you will need to download the gettext pkg and install it locally:
108
+ The rake task that merges .pot files is present for the internationalisation of a module. This task uses 'msgcat', which is only natively present on OSes that are GNU based. For running this task locally on another OS, you will need to download the gettext pkg and install it locally:
106
109
  https://pkgs.org/download/gettext
107
110
 
108
111
  This task will run within the gettext setup locales_path provided by GettextSetup. The result will be a merged pot file created from all pot files kept in this location.
109
112
 
110
- By default the merged pot file is locales_path/project_name.pot. This can be overridden when calling the method by providing a chosen path.
113
+ By default, the merged pot file is locales_path/project_name.pot. This can be overridden when calling the method by providing a chosen path.
111
114
 
112
115
  Please note: Since the default merged file name is project_name.pot, it will override anything of that name within the locales directory.
@@ -11,7 +11,6 @@ module GettextSetup
11
11
 
12
12
  @config = nil
13
13
  @translation_repositories = {}
14
- FastGettext.default_available_locales = []
15
14
 
16
15
  # `locales_path` should include:
17
16
  # - config.yaml
@@ -36,9 +35,11 @@ module GettextSetup
36
35
  FastGettext.add_text_domain('master_domain', type: :chain, chain: @translation_repositories.values)
37
36
  FastGettext.default_text_domain = 'master_domain'
38
37
 
39
- # Likewise, be explicit in our default language choice.
38
+ # Likewise, be explicit in our default language choice. Available locales
39
+ # must be set prior to setting the default_locale since default locale must
40
+ # available.
41
+ FastGettext.default_available_locales = (FastGettext.default_available_locales || []) | locales
40
42
  FastGettext.default_locale = default_locale
41
- FastGettext.default_available_locales = FastGettext.default_available_locales | locales
42
43
 
43
44
  Locale.set_default(default_locale)
44
45
  end
@@ -10,6 +10,15 @@ describe GettextSetup do
10
10
  before(:each) do
11
11
  GettextSetup.initialize(locales_path)
12
12
  end
13
+ after(:each) do
14
+ FastGettext.default_text_domain = nil
15
+ FastGettext.default_available_locales = nil
16
+ FastGettext.default_locale = nil
17
+
18
+ FastGettext.text_domain = nil
19
+ FastGettext.available_locales = nil
20
+ FastGettext.locale = nil
21
+ end
13
22
  let(:config) do
14
23
  GettextSetup.config
15
24
  end
@@ -79,7 +88,7 @@ describe GettextSetup do
79
88
  end
80
89
  context 'multiple locales' do
81
90
  # locales/ loads the de locale and fixture_locales/ loads the jp locale
82
- before(:all) do
91
+ before(:each) do
83
92
  GettextSetup.initialize(fixture_locales_path)
84
93
  end
85
94
  it 'can aggregate locales across projects' do
@@ -95,7 +104,7 @@ describe GettextSetup do
95
104
  end
96
105
  end
97
106
  context 'translation repository chain' do
98
- before(:all) do
107
+ before(:each) do
99
108
  GettextSetup.initialize(fixture_locales_path)
100
109
  end
101
110
  it 'chain is not nil' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext-setup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.29'
4
+ version: '0.30'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_gettext