traducto 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +7 -0
- data/README.md +87 -0
- data/Rakefile +11 -0
- data/lib/traducto/base.rb +74 -0
- data/lib/traducto/engine.rb +4 -0
- data/lib/traducto/helpers.rb +12 -0
- data/lib/traducto/railtie.rb +7 -0
- data/lib/traducto.rb +6 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/examples_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +18 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/standard_rails_initializers.rb +9 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/traducto/base_spec.rb +67 -0
- data/spec/traducto/helpers_spec.rb +15 -0
- data/spec/traducto_spec.rb +4 -0
- data/traducto.gemspec +23 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99dd1a918d0bfe64138e0533d10b197279bc5950
|
4
|
+
data.tar.gz: cbfa96614c21a4ae3843812cf1faf0bf22e5e79b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45fd895070fdcbd1b32ea034d8fb00a2b024e3d26bc147d816e058187d81af431000f59977d3ad6819a2e844ffc20e6275eeb795ff6ce08220741680d010fa46
|
7
|
+
data.tar.gz: 2a65ae1f35c75ff27e40e1469bb5f6e333032ccd141eb67de8e722c7fe1234f79be5ea50bc7bbe5349d08749c48ff26bec2db5e566b1cb936a31830e14c1e316
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 Alchimik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
Traducto [](http://travis-ci.org/alchimikweb/traducto) [](https://codeclimate.com/repos/527c039556b10201a000874c/feed) [](https://coveralls.io/r/alchimikweb/traducto)
|
2
|
+
===============
|
3
|
+
|
4
|
+
Rails helpers collection to simplify the localization code.
|
5
|
+
|
6
|
+
Install
|
7
|
+
-------
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install traducto
|
11
|
+
```
|
12
|
+
|
13
|
+
or add the following line to Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'traducto'
|
17
|
+
```
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
This gem will overwrite the helper method ```t``` in Rails. It will mostly stay the same except for the following modifications :
|
23
|
+
|
24
|
+
### Lazy Lookup
|
25
|
+
The lazy lookup will check three more path. Here's the full stack of checkup if you call the following :
|
26
|
+
|
27
|
+
```erb
|
28
|
+
<%# app/views/persons/index.html.erb %>
|
29
|
+
|
30
|
+
t('.title')
|
31
|
+
```
|
32
|
+
|
33
|
+
```yaml
|
34
|
+
en:
|
35
|
+
views:
|
36
|
+
persons:
|
37
|
+
index:
|
38
|
+
title: "Title"
|
39
|
+
```
|
40
|
+
|
41
|
+
```yaml
|
42
|
+
en:
|
43
|
+
views:
|
44
|
+
persons:
|
45
|
+
title: "Title"
|
46
|
+
```
|
47
|
+
|
48
|
+
```yaml
|
49
|
+
en:
|
50
|
+
views:
|
51
|
+
title: "Title"
|
52
|
+
```
|
53
|
+
|
54
|
+
```yaml
|
55
|
+
# Rails default
|
56
|
+
en:
|
57
|
+
persons:
|
58
|
+
index:
|
59
|
+
title: "Title"
|
60
|
+
```
|
61
|
+
|
62
|
+
### Formatting
|
63
|
+
You can also provide the format options to wrap the content by paragraphs.
|
64
|
+
|
65
|
+
```yaml
|
66
|
+
en:
|
67
|
+
description:
|
68
|
+
intro: "Let me start by ..."
|
69
|
+
main:
|
70
|
+
- "A lot of ..."
|
71
|
+
- "Paragraphs that needs to be ..."
|
72
|
+
- "Separated by p tags."
|
73
|
+
```
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
t('description.intro', format: :text)
|
77
|
+
#--> <p>Let me start by</p>
|
78
|
+
|
79
|
+
t('description.main', format: :text)
|
80
|
+
#--> <p>A lot of ...</p><p>Paragraphs that needs to be ...</p><p>Separated by p tags.</p>
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
Copyright
|
85
|
+
---------
|
86
|
+
|
87
|
+
Copyright (c) 2013 Alchimik. See LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Traducto
|
2
|
+
#*************************************************************************************
|
3
|
+
# Base helper methods to add path to lazy lookup and allow formatting.
|
4
|
+
#*************************************************************************************
|
5
|
+
class Base
|
6
|
+
attr_reader :rails_helpers
|
7
|
+
|
8
|
+
delegate :content_tag, to: :rails_helpers
|
9
|
+
delegate :request, to: :rails_helpers
|
10
|
+
|
11
|
+
def initialize(rails_helpers)
|
12
|
+
@rails_helpers = rails_helpers
|
13
|
+
|
14
|
+
init_state
|
15
|
+
end
|
16
|
+
|
17
|
+
def translate(key, options={})
|
18
|
+
init_state key, options
|
19
|
+
|
20
|
+
lazy_translate if lazy_lookup?
|
21
|
+
|
22
|
+
i18n_translate @base_key if translation_missing?
|
23
|
+
|
24
|
+
format_text if format?
|
25
|
+
|
26
|
+
return @text.html_safe
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def action
|
32
|
+
request[:action]
|
33
|
+
end
|
34
|
+
|
35
|
+
def controller
|
36
|
+
request[:controller]
|
37
|
+
end
|
38
|
+
|
39
|
+
def format?
|
40
|
+
@options[:format] ? true : false
|
41
|
+
end
|
42
|
+
|
43
|
+
def format_text
|
44
|
+
@text = [@text] if not @text.is_a? Array
|
45
|
+
|
46
|
+
@text = @text.map { |x| content_tag(:p, x) }.join.html_safe
|
47
|
+
end
|
48
|
+
|
49
|
+
def i18n_translate(key)
|
50
|
+
@text = I18n.translate(key, @options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def init_state(key='', options={})
|
54
|
+
@options = options.reverse_merge default: '', format: nil
|
55
|
+
|
56
|
+
@base_key = key
|
57
|
+
@text = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def lazy_lookup?
|
61
|
+
@base_key[0,1] == '.'
|
62
|
+
end
|
63
|
+
|
64
|
+
def lazy_translate
|
65
|
+
i18n_translate "views.#{controller}.#{action}#{@base_key}"
|
66
|
+
i18n_translate "views.#{controller}#{@base_key}" if translation_missing?
|
67
|
+
i18n_translate "views#{@base_key}" if translation_missing?
|
68
|
+
end
|
69
|
+
|
70
|
+
def translation_missing?
|
71
|
+
@text.blank? or @text.include? 'translation missing'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#*************************************************************************************
|
2
|
+
# Methods that will be inserted in the ActionView.
|
3
|
+
#*************************************************************************************
|
4
|
+
module Traducto::Helpers
|
5
|
+
def t(key, options={})
|
6
|
+
@traducto ||= Traducto::Base.new(self)
|
7
|
+
|
8
|
+
return @traducto.translate(key, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
::ActionView::Base.send :include, self
|
12
|
+
end
|
data/lib/traducto.rb
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
# require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
Bundler.require(*Rails.groups)
|
11
|
+
|
12
|
+
require "traducto"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# Code is not reloaded between requests.
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both thread web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on.
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
|
+
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
+
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
|
20
|
+
# config.action_dispatch.rack_cache = true
|
21
|
+
|
22
|
+
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
+
config.serve_static_assets = false
|
24
|
+
|
25
|
+
# Compress JavaScripts and CSS.
|
26
|
+
config.assets.js_compressor = :uglifier
|
27
|
+
# config.assets.css_compressor = :sass
|
28
|
+
|
29
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
30
|
+
config.assets.compile = false
|
31
|
+
|
32
|
+
# Generate digests for assets URLs.
|
33
|
+
config.assets.digest = true
|
34
|
+
|
35
|
+
# Version of your assets, change this if you want to expire all your assets.
|
36
|
+
config.assets.version = '1.0'
|
37
|
+
|
38
|
+
# Specifies the header that your server uses for sending files.
|
39
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
40
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
41
|
+
|
42
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
43
|
+
# config.force_ssl = true
|
44
|
+
|
45
|
+
# Set to :debug to see everything in the log.
|
46
|
+
config.log_level = :info
|
47
|
+
|
48
|
+
# Prepend all log lines with the following tags.
|
49
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
50
|
+
|
51
|
+
# Use a different logger for distributed setups.
|
52
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
53
|
+
|
54
|
+
# Use a different cache store in production.
|
55
|
+
# config.cache_store = :mem_cache_store
|
56
|
+
|
57
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
58
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
59
|
+
|
60
|
+
# Precompile additional assets.
|
61
|
+
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
62
|
+
# config.assets.precompile += %w( search.js )
|
63
|
+
|
64
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
65
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
66
|
+
# config.action_mailer.raise_delivery_errors = false
|
67
|
+
|
68
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
69
|
+
# the I18n.default_locale when a translation can not be found).
|
70
|
+
config.i18n.fallbacks = true
|
71
|
+
|
72
|
+
# Send deprecation notices to registered listeners.
|
73
|
+
config.active_support.deprecation = :notify
|
74
|
+
|
75
|
+
# Disable automatic flushing of the log to improve performance.
|
76
|
+
# config.autoflush_log = false
|
77
|
+
|
78
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
79
|
+
config.log_formatter = ::Logger::Formatter.new
|
80
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_assets = true
|
17
|
+
config.static_cache_control = "public, max-age=3600"
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
+
# The :test delivery method accumulates sent emails in the
|
31
|
+
# ActionMailer::Base.deliveries array.
|
32
|
+
config.action_mailer.delivery_method = :test
|
33
|
+
|
34
|
+
# Print deprecation notices to the stderr.
|
35
|
+
config.active_support.deprecation = :stderr
|
36
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Rails.application.config.filter_parameters += [:password]
|
2
|
+
|
3
|
+
Dummy::Application.config.secret_key_base = 'ae3cad0b2a7fe9cf1620b58b3629d5238578e36ba303b9821fb22ac023c9dc1b07ef16f27b74e96c4294f1e02c5bfc83f2dc89c02c9fc24d1b3974f6d7c14701'
|
4
|
+
|
5
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
6
|
+
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
require 'simplecov-rcov-text'
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
SimpleCov::Formatter::RcovTextFormatter
|
9
|
+
]
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter "spec/dummy"
|
12
|
+
add_filter "spec/support"
|
13
|
+
add_filter "spec/traducto_spec.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'rspec/autorun'
|
20
|
+
|
21
|
+
require 'coveralls'
|
22
|
+
Coveralls.wear!
|
23
|
+
|
24
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.mock_with :rspec
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Traducto::Base do
|
4
|
+
|
5
|
+
describe "#translate" do
|
6
|
+
before { I18n.stub('translate').and_return('') }
|
7
|
+
|
8
|
+
context "with the key views.persons.index.welcome having a 'Hello!' value" do
|
9
|
+
before { I18n.stub('translate').with('views.persons.index.welcome', anything()).and_return('Hello!') }
|
10
|
+
|
11
|
+
context "when calling from persons#index" do
|
12
|
+
before do
|
13
|
+
rails_helper = double()
|
14
|
+
rails_helper.stub(:request).and_return({ controller: 'persons', action: 'index' })
|
15
|
+
|
16
|
+
@base = Traducto::Base.new(rails_helper)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when asking the key 'views.persons.index.welcome'" do
|
20
|
+
specify { @base.translate('views.persons.index.welcome').should eql 'Hello!' }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when asking the key 'persons.index.welcome'" do
|
24
|
+
specify { @base.translate('persons.index.welcome').should eql '' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when asking the key '.welcome'" do
|
28
|
+
specify { @base.translate('.welcome').should eql 'Hello!' }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when calling from persons#show" do
|
33
|
+
before do
|
34
|
+
rails_helper = double()
|
35
|
+
rails_helper.stub(:request).and_return({ controller: 'persons', action: 'show' })
|
36
|
+
|
37
|
+
@base = Traducto::Base.new(rails_helper)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when asking the key '.welcome'" do
|
41
|
+
specify { @base.translate('.welcome').should eql '' }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with the key views.persons.title having a 'Human' value" do
|
45
|
+
before { I18n.stub('translate').with('views.persons.title', anything()).and_return('Human') }
|
46
|
+
|
47
|
+
context "when asking the key '.title'" do
|
48
|
+
specify { @base.translate('.title').should eql 'Human' }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with the key intro having the value ['par1', 'par2', 'par3']" do
|
55
|
+
before { I18n.stub('translate').with('intro', anything()).and_return(['par1', 'par2', 'par3']) }
|
56
|
+
|
57
|
+
context "when translating the key 'intro' with a text format" do
|
58
|
+
before { @base = Traducto::Base.new(ActionView::Base.new) }
|
59
|
+
|
60
|
+
subject { @base.translate('intro', format: :text) }
|
61
|
+
|
62
|
+
it { should eql '<p>par1</p><p>par2</p><p>par3</p>' }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Traducto::Helpers do
|
4
|
+
describe "#t" do
|
5
|
+
let(:action_view) { ActionView::Base.new }
|
6
|
+
|
7
|
+
context "with the key welcome" do
|
8
|
+
before { I18n.stub('translate').with('welcome', anything()).and_return('Hello!') }
|
9
|
+
|
10
|
+
subject { action_view.t('welcome', format: :text) }
|
11
|
+
|
12
|
+
it { should eql '<p>Hello!</p>' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/traducto.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "traducto"
|
3
|
+
gem.description = "Rails helpers collection to simplify the localization code."
|
4
|
+
gem.summary = "Rails helpers collection to simplify the localization code."
|
5
|
+
gem.homepage = "https://github.com/alchimikweb/traducto"
|
6
|
+
gem.version = "1.0.0"
|
7
|
+
gem.licenses = ["MIT"]
|
8
|
+
|
9
|
+
gem.authors = ["Sebastien Rosa"]
|
10
|
+
gem.email = ["srosa@alchimik.com"]
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_dependency "rails", ['>= 4.0.0']
|
18
|
+
gem.add_development_dependency "sqlite3"
|
19
|
+
gem.add_development_dependency "rspec-rails"
|
20
|
+
gem.add_development_dependency "simplecov"
|
21
|
+
gem.add_development_dependency "simplecov-rcov-text"
|
22
|
+
gem.add_development_dependency "coveralls"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traducto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastien Rosa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
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: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov-rcov-text
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Rails helpers collection to simplify the localization code.
|
98
|
+
email:
|
99
|
+
- srosa@alchimik.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/traducto.rb
|
111
|
+
- lib/traducto/base.rb
|
112
|
+
- lib/traducto/engine.rb
|
113
|
+
- lib/traducto/helpers.rb
|
114
|
+
- lib/traducto/railtie.rb
|
115
|
+
- spec/dummy/Rakefile
|
116
|
+
- spec/dummy/app/controllers/application_controller.rb
|
117
|
+
- spec/dummy/app/controllers/examples_controller.rb
|
118
|
+
- spec/dummy/app/helpers/application_helper.rb
|
119
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
120
|
+
- spec/dummy/bin/bundle
|
121
|
+
- spec/dummy/bin/rails
|
122
|
+
- spec/dummy/bin/rake
|
123
|
+
- spec/dummy/config.ru
|
124
|
+
- spec/dummy/config/application.rb
|
125
|
+
- spec/dummy/config/boot.rb
|
126
|
+
- spec/dummy/config/database.yml
|
127
|
+
- spec/dummy/config/environment.rb
|
128
|
+
- spec/dummy/config/environments/development.rb
|
129
|
+
- spec/dummy/config/environments/production.rb
|
130
|
+
- spec/dummy/config/environments/test.rb
|
131
|
+
- spec/dummy/config/initializers/standard_rails_initializers.rb
|
132
|
+
- spec/dummy/config/routes.rb
|
133
|
+
- spec/dummy/db/test.sqlite3
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- spec/traducto/base_spec.rb
|
136
|
+
- spec/traducto/helpers_spec.rb
|
137
|
+
- spec/traducto_spec.rb
|
138
|
+
- traducto.gemspec
|
139
|
+
homepage: https://github.com/alchimikweb/traducto
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.0.3
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Rails helpers collection to simplify the localization code.
|
163
|
+
test_files:
|
164
|
+
- spec/dummy/Rakefile
|
165
|
+
- spec/dummy/app/controllers/application_controller.rb
|
166
|
+
- spec/dummy/app/controllers/examples_controller.rb
|
167
|
+
- spec/dummy/app/helpers/application_helper.rb
|
168
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
169
|
+
- spec/dummy/bin/bundle
|
170
|
+
- spec/dummy/bin/rails
|
171
|
+
- spec/dummy/bin/rake
|
172
|
+
- spec/dummy/config.ru
|
173
|
+
- spec/dummy/config/application.rb
|
174
|
+
- spec/dummy/config/boot.rb
|
175
|
+
- spec/dummy/config/database.yml
|
176
|
+
- spec/dummy/config/environment.rb
|
177
|
+
- spec/dummy/config/environments/development.rb
|
178
|
+
- spec/dummy/config/environments/production.rb
|
179
|
+
- spec/dummy/config/environments/test.rb
|
180
|
+
- spec/dummy/config/initializers/standard_rails_initializers.rb
|
181
|
+
- spec/dummy/config/routes.rb
|
182
|
+
- spec/dummy/db/test.sqlite3
|
183
|
+
- spec/spec_helper.rb
|
184
|
+
- spec/traducto/base_spec.rb
|
185
|
+
- spec/traducto/helpers_spec.rb
|
186
|
+
- spec/traducto_spec.rb
|