handlebars_assets_i18n 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/handlebars_assets_i18n.gemspec +24 -0
- data/lib/handlebars_assets_i18n.rb +7 -0
- data/lib/handlebars_assets_i18n/config.rb +11 -0
- data/lib/handlebars_assets_i18n/rails.rb +1 -0
- data/lib/handlebars_assets_i18n/template_path.rb +15 -0
- data/lib/handlebars_assets_i18n/tilt_handlebars.rb +25 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a360e8a35ef6c275d7a69679d3a59f4384d781f
|
4
|
+
data.tar.gz: e00c51da92aed8c2734642331088f13816343080
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: beecb9d905624977c3a1aff1143e1c1ac8f1c59fd46d1b4e552d205c4cbdc8a29ae8d67651a873d8066ccc61e92ebc85a6eed752c2abb3ec3951d8ae52f24251
|
7
|
+
data.tar.gz: 6423e6a3a62a5994b3d9fa7425213a80143d0d4222acc430631b3992f67d610af497f0e964c9359fc2964ba238e010a980152d031482b7466e59a18a8079cc6c
|
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
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andriy Yanko
|
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,86 @@
|
|
1
|
+
# HandlebarsAssetsI18n
|
2
|
+
|
3
|
+
Very simple [handlebars_assets](https://github.com/leshill/handlebars_assets) internationalization for `.hamlbars` and `.slimbars` that allows your to have precompiled translated templates for each desired locale. So that you don't need translate it on client side on the fly.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'handlebars_assets_i18n'
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
By default templates will be precompiled with all available locales.
|
14
|
+
You can restrict it using `locales` configuration option:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
HandlebarsAssets::Config.locales = [:en, :de]
|
18
|
+
```
|
19
|
+
|
20
|
+
## How it works
|
21
|
+
|
22
|
+
If you file is `app/javascripts/templates/shared/errors.hamlbars` or `app/javascripts/templates/shared/errors.slimbars` and your locales are `:en` and `:de` then the assets pipeline will compile code for each locale and store it under corresponding names `HandlebarsAssets['shared/errors_en']` and `HandlebarsAssets['shared/errors_de']`.
|
23
|
+
|
24
|
+
|
25
|
+
## Using with Marionette
|
26
|
+
|
27
|
+
Export current locale in your `layouts/application.html.haml` to client side:
|
28
|
+
|
29
|
+
```haml
|
30
|
+
...
|
31
|
+
:javascript
|
32
|
+
MyApp.locale = '#{I18n.locale}'
|
33
|
+
...
|
34
|
+
```
|
35
|
+
|
36
|
+
Internationalize your Marionette renderer:
|
37
|
+
|
38
|
+
```coffee
|
39
|
+
|
40
|
+
Marionette.Renderer.render = (template, context) ->
|
41
|
+
template = "#{template}_#{MyApp.locale}"
|
42
|
+
|
43
|
+
unless HandlebarsTemplates[template]
|
44
|
+
throw "Template '#{template}' not found!"
|
45
|
+
|
46
|
+
HandlebarsTemplates[template](data)
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
That's all.
|
51
|
+
|
52
|
+
Now you can use `I18n.translate` and `I18n.localize` helpers in `.hamlbars` or `.slimbars`.
|
53
|
+
Also if you use this gem with `rails` then you can use rails `t` and `l` helpers`:
|
54
|
+
|
55
|
+
|
56
|
+
```hamlbars
|
57
|
+
%h2
|
58
|
+
=t 'title.errors'
|
59
|
+
|
60
|
+
%ul
|
61
|
+
{{#each errors}}
|
62
|
+
%li {{.}
|
63
|
+
{{/each}}
|
64
|
+
```
|
65
|
+
|
66
|
+
## Benefits
|
67
|
+
|
68
|
+
* Easy to plug in.
|
69
|
+
* Fast due to precompiled templates with translations.
|
70
|
+
* No I18n javascript code required.
|
71
|
+
* Translation keys are not exported to client side.
|
72
|
+
|
73
|
+
## Penalty of Simplicity
|
74
|
+
|
75
|
+
* Please remember that translation is performed on precompilation phase. Not at runtime.
|
76
|
+
* You must recompile templates if you changed translations in `config/locales`.
|
77
|
+
* You can't use interpolation features.
|
78
|
+
|
79
|
+
## Author
|
80
|
+
|
81
|
+
[Andriy Yanko](http://ayanko.github.io/)
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
* Copyright (c) 2014 Railsware [www.railsware.com](http://www.railsware.com)
|
86
|
+
* [MIT](www.opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "handlebars_assets_i18n"
|
7
|
+
spec.version = "0.1"
|
8
|
+
spec.authors = ["Andriy Yanko"]
|
9
|
+
spec.email = ["andriy.yanko@gmail.com"]
|
10
|
+
spec.summary = %q{handlebars assets simple internationalization}
|
11
|
+
spec.homepage = "https://github.com/railsware/handlebars_assets_i18n"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'handlebars_assets', '>=0.13.0'
|
23
|
+
spec.add_runtime_dependency 'i18n', '>= 0.6.9'
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Sprockets::Rails::Helper.send :include, ActionView::Helpers::TranslationHelper
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module HandlebarsAssets
|
2
|
+
class TiltHandlebars
|
3
|
+
|
4
|
+
alias_method :evaluate_without_i18n, :evaluate
|
5
|
+
|
6
|
+
def evaluate_with_i18n(scope, locals, &block)
|
7
|
+
HandlebarsAssets::Config.locales.map do |locale|
|
8
|
+
I18n.with_locale(locale) do
|
9
|
+
evaluate_without_i18n(scope, locals, &block)
|
10
|
+
end
|
11
|
+
end.join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
template_path = TemplatePath.new(scope)
|
16
|
+
|
17
|
+
if template_path.i18n? and not HandlebarsAssets::Config.locales.empty?
|
18
|
+
evaluate_with_i18n(scope, locals, &block)
|
19
|
+
else
|
20
|
+
evaluate_without_i18n(scope, locals, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handlebars_assets_i18n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andriy Yanko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-15 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: handlebars_assets
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.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.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.9
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.9
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- andriy.yanko@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- handlebars_assets_i18n.gemspec
|
82
|
+
- lib/handlebars_assets_i18n.rb
|
83
|
+
- lib/handlebars_assets_i18n/config.rb
|
84
|
+
- lib/handlebars_assets_i18n/rails.rb
|
85
|
+
- lib/handlebars_assets_i18n/template_path.rb
|
86
|
+
- lib/handlebars_assets_i18n/tilt_handlebars.rb
|
87
|
+
homepage: https://github.com/railsware/handlebars_assets_i18n
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: handlebars assets simple internationalization
|
111
|
+
test_files: []
|