g11n 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ - ree
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in g11n.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "rake"
8
+ end
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # G11n is Globalization
2
+ [![Build Status](https://secure.travis-ci.org/Fetcher/g11n.png)](http://travis-ci.org/Fetcher/g11n) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Fetcher/g11n)
2
3
 
3
4
  Globalization (g11n) is a Ruby Gem for easy language file handling aimed at internationalized projects.
4
5
 
@@ -10,27 +11,31 @@ G11n assumes you will have a series of language files written in YAML in an acce
10
11
 
11
12
  The default path for that folder is `translations/`. So, for example, if you have a file named `translations/it.yaml` that reads as...
12
13
 
13
- # ./translations/it.yaml
14
- home:
15
- title: La pasta di la nonna
16
- menu:
17
- preparation: Comme farla
18
- eating: Comme si mangia
19
- wine: Con che si accompagna
14
+ ```yaml
15
+ # ./translations/it.yaml
16
+ home:
17
+ title: La pasta della nonna
18
+ menu:
19
+ preparation: Comme farla
20
+ eating: Comme si mangia
21
+ wine: Con che si accompagna
22
+ ```
20
23
 
21
24
  ... you can, in your project, insert the following code and get the internationalized strings:
22
25
 
23
- # .script.rb
24
- require "g11n"
25
-
26
- G11n.locale :it # Configures G11n to use italian. Default is "en"
27
-
28
- G11n.t.home.title # => "La pasta di la nonna"
29
- G11n.t.home.menu.wine # => "Con che si accompagna"
26
+ ```ruby
27
+ # .script.rb
28
+ require "g11n"
29
+
30
+ G11n.locale :it # Configures G11n to use italian. Default is "en"
31
+
32
+ G11n.t.home.title # => "La pasta della nonna"
33
+ G11n.t.home.menu.wine # => "Con che si accompagna"
34
+ ```
30
35
 
31
36
  ## Installation
32
37
 
33
- $ gem install g11n
38
+ gem install g11n
34
39
 
35
40
  ### Or when using Bundler
36
41
 
@@ -40,22 +45,31 @@ Add this line to your application's Gemfile:
40
45
 
41
46
  And then execute:
42
47
 
43
- $ bundle
48
+ bundle install
44
49
 
45
50
  ## Configuring
46
51
 
47
52
  Configuration is straight forward. You are using another directory for your language files? Just `G11n.path "your/path"`. You want to change the locale? `G11n.locale :yours`.
48
53
 
49
- # ./translations/ru.yml
50
- home:
51
- land: Российская Федерация
52
-
53
- require "g11n"
54
-
55
- G11n.path "i18ns"
56
- G11n.locale :ru
57
-
58
- G11n.t.home.land # => "Российская Федерация"
54
+ For example, a translations file in a non-standard folder:
55
+
56
+ ```yaml
57
+ # ./i18ns/ru.yml
58
+ home:
59
+ land: Российская Федерация
60
+ ```
61
+
62
+ And a script in the base folder:
63
+
64
+ ```ruby
65
+ # ./script.rb
66
+ require "g11n"
67
+
68
+ G11n.path "i18ns"
69
+ G11n.locale :ru
70
+
71
+ G11n.t.home.land # => "Российская Федерация"
72
+ ```
59
73
 
60
74
  Also, the `G11n::DSL` module can be included in any object of class you want to use the `#t` method more confortably.
61
75
 
@@ -65,8 +79,6 @@ Also, the `G11n::DSL` module can be included in any object of class you want to
65
79
 
66
80
  Cucumber features and RSpec specs are provided to check functionality.
67
81
 
68
- An exception is the G11n::Dictionary class, which is just a subclass of SymbolTable that recursively converts all hashes passed as argument to the initializer into Dictionaries. This is really handy.
69
-
70
82
  ## License
71
83
 
72
84
  Copyright (C) 2012 Fetcher
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = "./spec/**/*_spec.rb"
9
+ end
10
+
11
+ task :default => :spec
data/g11n.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.summary = %q{Internationalization library focused in simplicity of implementation}
9
9
  gem.homepage = "http://github.com/Fetcher/g11n"
10
10
 
11
- gem.add_dependency "symboltable"
11
+ gem.add_dependency "symbolmatrix"
12
12
 
13
13
  gem.add_development_dependency "rspec"
14
14
  gem.add_development_dependency "cucumber"
@@ -32,9 +32,9 @@ module G11n
32
32
  def dictionary_for the_locale
33
33
  return @dictionaries[the_locale] if @dictionaries.has_key? the_locale # In case is already loaded
34
34
  if File.exists? "#{@translations_path}#{the_locale}.yaml"
35
- @dictionaries[the_locale] = Dictionary.new YAML.load_file "#{@translations_path}#{the_locale}.yaml"
35
+ @dictionaries[the_locale] = SymbolMatrix.new "#{@translations_path}#{the_locale}.yaml"
36
36
  elsif File.exists? "#{@translations_path}#{the_locale}.yml"
37
- @dictionaries[the_locale] = Dictionary.new YAML.load_file "#{@translations_path}#{the_locale}.yml"
37
+ @dictionaries[the_locale] = SymbolMatrix.new "#{@translations_path}#{the_locale}.yml"
38
38
  else
39
39
  raise NoTranslationAvailable, "There is no translation file available for the '#{the_locale}' locale, check the tranlations source directory configuration"
40
40
  end
data/lib/g11n/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module G11n
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/g11n.rb CHANGED
@@ -2,12 +2,11 @@
2
2
  require "singleton"
3
3
 
4
4
  # Third-party
5
- require "symboltable"
5
+ require "symbolmatrix"
6
6
 
7
7
  # Local
8
8
  require "g11n/version"
9
9
  require "g11n/translator"
10
- require "g11n/dictionary"
11
10
  require "g11n/exceptions"
12
11
  require "g11n/dsl"
13
12
  require "g11n/configuration"
@@ -1,6 +1,7 @@
1
1
  require "g11n"
2
2
  require "fast/fast"
3
3
  require "pry"
4
+ require "yaml"
4
5
 
5
6
  def low_level_deconfigurate!
6
7
  Fast.dir.delete! :translations
@@ -61,9 +62,9 @@ describe G11n::Translator do
61
62
  Fast.file.write "translations/en.yaml", { :hello => "Text", :nested => { :is => "good" } }.to_yaml
62
63
  end
63
64
 
64
- it "should return the G11n::Dictionary object with the information from the YAML file" do
65
+ it "should return the SymbolMatrix object with the information from the YAML file" do
65
66
  dictionary = G11n::Translator.instance.dictionary_for :en
66
- dictionary.should be_a G11n::Dictionary
67
+ dictionary.should be_a SymbolMatrix
67
68
  dictionary.should have_key :hello
68
69
  end
69
70
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g11n
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Xavier Via
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-24 00:00:00 Z
18
+ date: 2012-07-31 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: symboltable
22
- prerelease: false
21
+ type: :runtime
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
@@ -29,11 +28,11 @@ dependencies:
29
28
  segments:
30
29
  - 0
31
30
  version: "0"
32
- type: :runtime
33
31
  version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
32
  prerelease: false
33
+ name: symbolmatrix
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
37
36
  requirement: &id002 !ruby/object:Gem::Requirement
38
37
  none: false
39
38
  requirements:
@@ -43,11 +42,11 @@ dependencies:
43
42
  segments:
44
43
  - 0
45
44
  version: "0"
46
- type: :development
47
45
  version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: cucumber
50
46
  prerelease: false
47
+ name: rspec
48
+ - !ruby/object:Gem::Dependency
49
+ type: :development
51
50
  requirement: &id003 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
@@ -57,11 +56,11 @@ dependencies:
57
56
  segments:
58
57
  - 0
59
58
  version: "0"
60
- type: :development
61
59
  version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: fast
64
60
  prerelease: false
61
+ name: cucumber
62
+ - !ruby/object:Gem::Dependency
63
+ type: :development
65
64
  requirement: &id004 !ruby/object:Gem::Requirement
66
65
  none: false
67
66
  requirements:
@@ -71,11 +70,11 @@ dependencies:
71
70
  segments:
72
71
  - 0
73
72
  version: "0"
74
- type: :development
75
73
  version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: pry
78
74
  prerelease: false
75
+ name: fast
76
+ - !ruby/object:Gem::Dependency
77
+ type: :development
79
78
  requirement: &id005 !ruby/object:Gem::Requirement
80
79
  none: false
81
80
  requirements:
@@ -85,8 +84,9 @@ dependencies:
85
84
  segments:
86
85
  - 0
87
86
  version: "0"
88
- type: :development
89
87
  version_requirements: *id005
88
+ prerelease: false
89
+ name: pry
90
90
  description: Internationalization library focused in simplicity of implementation
91
91
  email:
92
92
  - xavier.via.canel@gmail.com
@@ -98,6 +98,7 @@ extra_rdoc_files: []
98
98
 
99
99
  files:
100
100
  - .gitignore
101
+ - .travis.yml
101
102
  - Gemfile
102
103
  - LICENSE
103
104
  - README.md
@@ -111,7 +112,6 @@ files:
111
112
  - g11n.gemspec
112
113
  - lib/g11n.rb
113
114
  - lib/g11n/configuration.rb
114
- - lib/g11n/dictionary.rb
115
115
  - lib/g11n/dsl.rb
116
116
  - lib/g11n/exceptions.rb
117
117
  - lib/g11n/translator.rb
@@ -158,4 +158,3 @@ test_files:
158
158
  - features/support/env.rb
159
159
  - features/support/hooks.rb
160
160
  - spec/g11n/translator_spec.rb
161
- has_rdoc:
@@ -1,21 +0,0 @@
1
- # Stupid but really useful class:
2
- # Inherits from SymbolTable (https://github.com/mjijackson/symboltable), but when it is initialized
3
- # it simply... well, recursively converts all Hashes into dictionaries
4
- module G11n
5
- class Dictionary < SymbolTable
6
-
7
- def initialize *args
8
- super *args
9
- _symbolize!
10
- end
11
-
12
- private
13
- def _symbolize!
14
- each_key do |key|
15
- if self[key].instance_of? Hash
16
- self[key] = Dictionary.new self[key]
17
- end
18
- end
19
- end
20
- end
21
- end