locale_js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +4 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/ChangeLog.rdoc +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +26 -0
- data/Rakefile +41 -0
- data/app/.DS_Store +0 -0
- data/app/controllers/locale_controller.rb +33 -0
- data/app/views/locale/i18n.js.erb +27 -0
- data/config/routes.rb +3 -0
- data/lib/locale_js/engine.rb +7 -0
- data/lib/locale_js/version.rb +4 -0
- data/lib/locale_js.rb +2 -0
- data/locale_js.gemspec +22 -0
- data/spec/locale_js_spec.rb +8 -0
- data/spec/spec_helper.rb +5 -0
- metadata +99 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/ChangeLog.rdoc
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 jbutler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= locale_js
|
2
|
+
|
3
|
+
* {Homepage}[https://rubygems.org/gems/locale_js]
|
4
|
+
* {Documentation}[http://rubydoc.info/gems/locale_js/frames]
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
TODO: Description
|
9
|
+
|
10
|
+
== Features
|
11
|
+
|
12
|
+
== Examples
|
13
|
+
|
14
|
+
require 'locale_js'
|
15
|
+
|
16
|
+
== Requirements
|
17
|
+
|
18
|
+
== Install
|
19
|
+
|
20
|
+
$ gem install locale_js
|
21
|
+
|
22
|
+
== Copyright
|
23
|
+
|
24
|
+
Copyright (c) 2012 jbutler
|
25
|
+
|
26
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
gem 'rubygems-tasks', '~> 0.2'
|
8
|
+
require 'rubygems/tasks'
|
9
|
+
|
10
|
+
Gem::Tasks.new
|
11
|
+
rescue LoadError => e
|
12
|
+
warn e.message
|
13
|
+
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
gem 'rdoc', '~> 3.0'
|
18
|
+
require 'rdoc/task'
|
19
|
+
|
20
|
+
RDoc::Task.new do |rdoc|
|
21
|
+
rdoc.title = "locale_js"
|
22
|
+
end
|
23
|
+
rescue LoadError => e
|
24
|
+
warn e.message
|
25
|
+
warn "Run `gem install rdoc` to install 'rdoc/task'."
|
26
|
+
end
|
27
|
+
task :doc => :rdoc
|
28
|
+
|
29
|
+
begin
|
30
|
+
gem 'rspec', '~> 2.4'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
|
33
|
+
RSpec::Core::RakeTask.new
|
34
|
+
rescue LoadError => e
|
35
|
+
task :spec do
|
36
|
+
abort "Please run `gem install rspec` to install RSpec."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :spec
|
41
|
+
task :default => :spec
|
data/app/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class LocaleController < ApplicationController
|
2
|
+
|
3
|
+
# remember to add the locales route
|
4
|
+
# map.connect '/locale/:action.:format', :controller => :locale
|
5
|
+
# then add this to your layout <%= javascript_include_tag "/locale/#{I18n.locale}.js" %>
|
6
|
+
# your locale will be available in a javascript global: I18n
|
7
|
+
|
8
|
+
rescue_from AbstractController::ActionNotFound, :with => :action_mising
|
9
|
+
|
10
|
+
# this method searches the locales dir and then defines methods on this class for each locale
|
11
|
+
Dir.glob(File.join(Rails.root,'config/locales/*.yml')).map do |file|
|
12
|
+
locale = File.basename(file).match(/(.+)\.yml/)[1]
|
13
|
+
define_method(locale) do
|
14
|
+
generate_locale(locale)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def generate_locale(locale)
|
20
|
+
expires(30.days.from_now)
|
21
|
+
I18n.locale = locale
|
22
|
+
# initialize i18n
|
23
|
+
I18n.translate :hello
|
24
|
+
@locale = I18n.backend.send(:translations)[I18n.locale]
|
25
|
+
render :template => 'locale/i18n'
|
26
|
+
end
|
27
|
+
|
28
|
+
def action_missing(action)
|
29
|
+
logger.debug("No config/locales/#{action}.yml exists! Reverting to #{I18n.default_locale}")
|
30
|
+
generate_locale(I18n.default_locale)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
!function(exports){
|
2
|
+
var locale = <%=raw @locale.to_json %>;
|
3
|
+
|
4
|
+
function get_key(key, context){
|
5
|
+
var path = key.split('.'), k = null;
|
6
|
+
while(k = path.shift()){
|
7
|
+
if(context.hasOwnProperty(k)){
|
8
|
+
context = context[k];
|
9
|
+
}
|
10
|
+
else{
|
11
|
+
throw Error('Translation missing: ' + key);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
return context;
|
15
|
+
}
|
16
|
+
|
17
|
+
exports.I18n = {
|
18
|
+
t: function(key, context){
|
19
|
+
var str = get_key(key, locale);
|
20
|
+
for(key in context){
|
21
|
+
str = str.replace("%{"+key+"}", context[key]);
|
22
|
+
}
|
23
|
+
return str;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
}(window);
|
data/config/routes.rb
ADDED
data/lib/locale_js.rb
ADDED
data/locale_js.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/locale_js/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "locale_js"
|
7
|
+
gem.version = LocaleJS::VERSION
|
8
|
+
gem.summary = %q{Make Rails i18n available in javascript}
|
9
|
+
gem.description = %q{Make Rails i18n available in javascript}
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["John Butler"]
|
12
|
+
gem.homepage = "https://github.com/johnnypez/locale_js"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_development_dependency "rubygems-tasks", "~> 0.2"
|
20
|
+
gem.add_development_dependency "rdoc", "~> 3.0"
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.4"
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: locale_js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Butler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-26 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rubygems-tasks
|
17
|
+
requirement: &70110792044140 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.2'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70110792044140
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rdoc
|
28
|
+
requirement: &70110792043540 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70110792043540
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70110792042960 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.4'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70110792042960
|
48
|
+
description: Make Rails i18n available in javascript
|
49
|
+
email:
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .document
|
55
|
+
- .gitignore
|
56
|
+
- .rspec
|
57
|
+
- ChangeLog.rdoc
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.rdoc
|
60
|
+
- Rakefile
|
61
|
+
- app/.DS_Store
|
62
|
+
- app/controllers/locale_controller.rb
|
63
|
+
- app/views/locale/i18n.js.erb
|
64
|
+
- config/routes.rb
|
65
|
+
- lib/locale_js.rb
|
66
|
+
- lib/locale_js/engine.rb
|
67
|
+
- lib/locale_js/version.rb
|
68
|
+
- locale_js.gemspec
|
69
|
+
- spec/locale_js_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: https://github.com/johnnypez/locale_js
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.6.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Make Rails i18n available in javascript
|
97
|
+
test_files:
|
98
|
+
- spec/locale_js_spec.rb
|
99
|
+
- spec/spec_helper.rb
|