i18n-globals 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzdhMTA2MTE1N2U3NjdkMzU0M2U2ZjA4YWY4MzRkMDQ3Y2Y3N2E4NQ==
5
+ data.tar.gz: !binary |-
6
+ NWMyMGQzNTkxMTFjNDZhMTAxOWExNmRhZjczZmE0Mzk5ZDE0ZDgyNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YWQ3ODNjMTJkZjhjYTBiYTlmNGYzOTAzYmMzOWRiNDg2MTI3NzU4ZWU0MjBi
10
+ ZTllMTA2NDFiMjJjN2YwZWJiY2U2ZjA0YWZkN2Q2NDY4NTZiODNjYTA2OTFm
11
+ ODZhZWVjMWY0ZjMzMDNlNDg4N2Q0ZmQzNWU0OTdhNTQwMTdjYzk=
12
+ data.tar.gz: !binary |-
13
+ Njc2NTVjMDU1ZjFjZGY3NmFhY2U4ZDJlMzE5ODMzZDlhZDM4MzI5YTYyMDcz
14
+ YWUyNGYxYWE1NzJkMzBmMDJlYzIwMjY5ZDEyZWJjYzNjZGJjN2Q4MGFlN2Iz
15
+ ZjU1OTJjODMzOTA3Y2I4NjZkNWYxZDZiZWY2ZjRjODA2NGNmZWU=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in i18n-globals.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Attila Horvath
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # I18n::Globals
2
+
3
+ Adds support for I18n global variables, which will be available for interpolation into every translation.
4
+
5
+ ## Description
6
+
7
+ Extends the Ruby I18n gem with global variables. The globals will be available for interpolation in every translation without explicitly specifying them in a call to `I18n.translate`. The variables can be accessed through `I18n.config.globals`.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'i18n-globals'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install i18n-globals
22
+
23
+ ## Usage
24
+
25
+ Add your global variables to the `I18n.config.globals` hash:
26
+
27
+ I18n.config.globals[:company] = "Initech"
28
+
29
+ Your global variables will then be automatically interpolated into every translation:
30
+
31
+ # If the value of 'greeting' is 'Welcome to %{company}!'
32
+ I18n.t "greeting" # Returns 'Welcome to Initech!'
33
+
34
+ You can override the globals:
35
+
36
+ I18n.t "greeting", company: "Initrode" # Returns 'Welcome to Initrode!'
37
+
38
+ It's also possible to mix globals and ordinary variables:
39
+
40
+ # If the value of 'signature' is '%{president}, President of %{company}'
41
+ I18n.t "signature", president: "Bill Lumbergh" # Returns 'Bill Lumbergh, President of Initech'
42
+
43
+ If you're using Rails, it can be useful to specify your globals in a `before_filter`:
44
+
45
+ class EmployeesController < ApplicationController
46
+ before_filter :set_i18n_globals
47
+
48
+ # ...
49
+
50
+ private
51
+
52
+ def set_i18n_globals
53
+ I18n.config.globals[:company] = Company.current.name
54
+ end
55
+ end
56
+
57
+ Now you can interpolate the `user_name` variable into every translation in your template:
58
+
59
+ <%= t "greeting" %>
60
+ <%= t "signature", president: "Bill Lumbergh" %>
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/attilahorvath/i18n-globals/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'i18n/globals/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "i18n-globals"
8
+ spec.version = I18n::Globals::VERSION
9
+ spec.authors = ["Attila Horvath"]
10
+ spec.email = ["hun.ati500@gmail.com"]
11
+ spec.summary = %q{Adds support for I18n global variables, which will be available for interpolation into every translation.}
12
+ spec.description = %q{Extends the Ruby I18n gem with global variables. The globals will be available for interpolation in every translation without explicitly specifying them in a call to I18n.translate. The variables can be accessed through I18n.config.globals.}
13
+ spec.homepage = "https://github.com/attilahorvath/i18n-globals"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "i18n"
25
+ end
@@ -0,0 +1 @@
1
+ require "i18n/globals"
@@ -0,0 +1,24 @@
1
+ require "i18n/globals/version"
2
+
3
+ module I18n
4
+ class Config
5
+ def globals
6
+ @globals ||= {}
7
+ end
8
+
9
+ def globals=(globals)
10
+ @globals = globals
11
+ end
12
+ end
13
+
14
+ class << self
15
+ def translate(*args)
16
+ if args.last.is_a?(Hash)
17
+ args[-1] = config.globals.merge(args.last)
18
+ else
19
+ args << config.globals
20
+ end
21
+ super(*args)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module Globals
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-globals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Attila Horvath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Extends the Ruby I18n gem with global variables. The globals will be
56
+ available for interpolation in every translation without explicitly specifying them
57
+ in a call to I18n.translate. The variables can be accessed through I18n.config.globals.
58
+ email:
59
+ - hun.ati500@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - i18n-globals.gemspec
70
+ - lib/i18n-globals.rb
71
+ - lib/i18n/globals.rb
72
+ - lib/i18n/globals/version.rb
73
+ homepage: https://github.com/attilahorvath/i18n-globals
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Adds support for I18n global variables, which will be available for interpolation
97
+ into every translation.
98
+ test_files: []