localite 0.3 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Manifest +44 -0
  2. data/VERSION +1 -1
  3. data/bin/list-tr +10 -0
  4. data/lib/localite.rb +161 -43
  5. data/lib/localite/filter.rb +23 -64
  6. data/lib/localite/format.rb +36 -0
  7. data/lib/localite/node_filter.rb +197 -0
  8. data/lib/localite/scopes.rb +93 -0
  9. data/lib/localite/settings.rb +139 -17
  10. data/lib/localite/storage.rb +132 -0
  11. data/lib/localite/template.rb +29 -25
  12. data/lib/localite/tr.rb +292 -0
  13. data/lib/localite/translate.rb +46 -20
  14. data/localite.gemspec +9 -6
  15. data/localite.tmproj +3 -99
  16. data/tasks/echoe.rake +1 -1
  17. data/test/i18n/de.tr +5 -0
  18. data/test/i18n/en.tr +16 -0
  19. data/test/rails/Rakefile +10 -0
  20. data/test/rails/app/controllers/application_controller.rb +10 -0
  21. data/test/rails/app/controllers/localite_controller.rb +20 -0
  22. data/test/rails/app/views/localite/index.html.erb +19 -0
  23. data/test/rails/app/views/localite/template.de.html.erb +1 -0
  24. data/test/rails/app/views/localite/template.en.html.erb +1 -0
  25. data/test/rails/config/boot.rb +110 -0
  26. data/test/rails/config/environment.rb +50 -0
  27. data/test/rails/config/environments/development.rb +17 -0
  28. data/test/rails/config/environments/production.rb +28 -0
  29. data/test/rails/config/environments/test.rb +28 -0
  30. data/test/rails/config/initializers/new_rails_defaults.rb +21 -0
  31. data/test/rails/config/initializers/session_store.rb +15 -0
  32. data/test/rails/config/locales/de.yml +4 -0
  33. data/test/rails/config/locales/en.yml +4 -0
  34. data/test/rails/config/routes.rb +13 -0
  35. data/test/rails/script/console +3 -0
  36. data/test/rails/script/server +3 -0
  37. data/test/rails/test/functional/localite_controller_test.rb +56 -0
  38. data/test/rails/test/test_helper.rb +38 -0
  39. data/test/test.rb +4 -1
  40. metadata +51 -11
  41. data/lib/localite/scope.rb +0 -140
  42. data/test/i18n/de.yml +0 -15
@@ -0,0 +1,50 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '2.3.6' unless defined? RAILS_GEM_VERSION
5
+
6
+ require "rubygems"
7
+ require "#{File.dirname(__FILE__)}/../../../lib/localite"
8
+
9
+ # Bootstrap the Rails environment, frameworks, and default configuration
10
+ require File.join(File.dirname(__FILE__), 'boot')
11
+
12
+ Rails::Initializer.run do |config|
13
+ # Settings in config/environments/* take precedence over those specified here.
14
+ # Application configuration should go into files in config/initializers
15
+ # -- all .rb files in that directory are automatically loaded.
16
+
17
+ # Add additional load paths for your own custom dirs
18
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
19
+
20
+ # Specify gems that this application depends on and have them installed with rake gems:install
21
+ # config.gem "bj"
22
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
23
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
24
+ # config.gem "aws-s3", :lib => "aws/s3"
25
+
26
+ # Only load the plugins named here, in the order given (default is alphabetical).
27
+ # :all can be used as a placeholder for all plugins not explicitly named
28
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
29
+
30
+ # Skip frameworks you're not going to use. To use Rails without a database,
31
+ # you must remove the Active Record framework.
32
+ config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
33
+
34
+ # Activate observers that should always be running
35
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
36
+
37
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
38
+ # Run "rake -D time" for a list of tasks for finding time zone names.
39
+ config.time_zone = 'UTC'
40
+
41
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
42
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
43
+ # config.i18n.default_locale = :de
44
+ config.i18n.load_path += Dir["#{File.dirname(__FILE__)}/i18n/*.yml"]
45
+ end
46
+
47
+ I18n.backend = Localite::Backend::Simple.new
48
+
49
+ #
50
+ # Load localite from gem source; load localite translations from test dir.
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = 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
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -0,0 +1,21 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ ActionController::Routing.generate_best_match = false
15
+
16
+ # Use ISO 8601 format for JSON serialized times and dates.
17
+ ActiveSupport.use_standard_json_time_format = true
18
+
19
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
+ # if you're including raw json in an HTML page.
21
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_rails_session',
9
+ :secret => '3286d3682ef470a644341b5576323f0b8a2fa265caf91bb210e9d95f0251036629e86bcb0d7a32d3bb43f76f65b365db012622546a82acbdc24b0a540c8129b1'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,4 @@
1
+ title: "Das ist Hypertext! (in HTML)"
2
+
3
+ paragraph: |
4
+ Was ich schon immer mal loswerden wollte...
@@ -0,0 +1,4 @@
1
+ title: "This is hypertext! (as HTML)"
2
+
3
+ paragraph: |
4
+ What I always wanted to tell you...
@@ -0,0 +1,13 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
4
+ map.root :controller => "localite"
5
+
6
+ # See how all your routes lay out with "rake routes"
7
+
8
+ # Install the default routes as the lowest priority.
9
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
10
+ # consider removing or commenting them out if you're using named routes and resources.
11
+ map.connect ':controller/:action/:id'
12
+ map.connect ':controller/:action/:id.:format'
13
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,56 @@
1
+ require "#{File.dirname(__FILE__)}/../test_helper"
2
+
3
+ class LocaliteControllerTest < ActionController::TestCase
4
+ attr :response
5
+
6
+ def body
7
+ response.body
8
+ end
9
+
10
+ # Replace this with your real tests.
11
+ def test_index_en
12
+ get :index
13
+
14
+ assert body.index("This is hypertext! (as HTML)")
15
+ assert body.index("What I always wanted to tell you...")
16
+
17
+ assert body.index("string:error")
18
+ assert body.index("locale:en")
19
+ end
20
+
21
+ def test_index_de
22
+ get :index, :lang => "de"
23
+
24
+ assert body.index("Das ist Hypertext! (in HTML)")
25
+ assert body.index("Was ich schon immer mal loswerden wollte...")
26
+
27
+ assert body.index("string:error")
28
+ assert body.index("locale:de")
29
+ end
30
+
31
+ def test_index_unknown
32
+ get :index, :lang => "un" # must be 2 chars!
33
+
34
+ assert body.index("string:error")
35
+ assert body.index("locale:en")
36
+ end
37
+
38
+ def test_auto
39
+ get :auto
40
+
41
+ assert body.index("string:error")
42
+ assert body.index("locale:de")
43
+ end
44
+
45
+ def test_template_selection_english
46
+ get :template
47
+
48
+ assert body.index("english")
49
+ end
50
+
51
+ def test_template_selection_de
52
+ get :template, :lang => "de"
53
+
54
+ assert body.index("deutsch")
55
+ end
56
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ # self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ # self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ # fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -6,13 +6,16 @@ Dir.chdir(DIRNAME)
6
6
  # initialize the gem and the test runner
7
7
  require "rubygems"
8
8
  require '../lib/localite'
9
+ require '../lib/localite/node_filter'
9
10
 
10
11
  require 'logger'
11
12
  require 'ruby-debug'
13
+ require "mocha"
12
14
 
13
15
  require "#{DIRNAME}/initializers/fake_rails.rb"
14
16
 
15
- I18n.load_path += Dir["#{DIRNAME}/i18n/*.yml"]
17
+ I18n.backend = Localite::Backend::Simple.new
18
+ I18n.load_path += Dir["#{DIRNAME}/i18n/*.tr"]
16
19
 
17
20
  # ---------------------------------------------------------------------
18
21
 
metadata CHANGED
@@ -1,11 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localite
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 3
8
- version: "0.3"
8
+ - 5
9
+ - 6
10
+ version: 0.5.6
9
11
  platform: ruby
10
12
  authors:
11
13
  - pboy
@@ -13,16 +15,18 @@ autorequire:
13
15
  bindir: bin
14
16
  cert_chain: []
15
17
 
16
- date: 2010-05-23 00:00:00 +02:00
18
+ date: 2010-06-18 00:00:00 +02:00
17
19
  default_executable:
18
20
  dependencies:
19
21
  - !ruby/object:Gem::Dependency
20
22
  name: i18n
21
23
  prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
29
+ hash: 3
26
30
  segments:
27
31
  - 0
28
32
  version: "0"
@@ -30,36 +34,67 @@ dependencies:
30
34
  version_requirements: *id001
31
35
  description: An easy to use localization gem.
32
36
  email: eno-pboy@open-lab.org
33
- executables: []
34
-
37
+ executables:
38
+ - list-tr
35
39
  extensions: []
36
40
 
37
41
  extra_rdoc_files:
42
+ - bin/list-tr
38
43
  - lib/localite.rb
39
44
  - lib/localite/filter.rb
40
- - lib/localite/scope.rb
45
+ - lib/localite/format.rb
46
+ - lib/localite/node_filter.rb
47
+ - lib/localite/scopes.rb
41
48
  - lib/localite/settings.rb
49
+ - lib/localite/storage.rb
42
50
  - lib/localite/template.rb
51
+ - lib/localite/tr.rb
43
52
  - lib/localite/translate.rb
44
53
  - tasks/echoe.rake
45
54
  files:
46
55
  - Manifest
47
56
  - Rakefile
48
57
  - VERSION
58
+ - bin/list-tr
49
59
  - config/dependencies.rb
50
60
  - config/gem.yml
51
61
  - lib/localite.rb
52
62
  - lib/localite/filter.rb
53
- - lib/localite/scope.rb
63
+ - lib/localite/format.rb
64
+ - lib/localite/node_filter.rb
65
+ - lib/localite/scopes.rb
54
66
  - lib/localite/settings.rb
67
+ - lib/localite/storage.rb
55
68
  - lib/localite/template.rb
69
+ - lib/localite/tr.rb
56
70
  - lib/localite/translate.rb
57
71
  - localite.tmproj
58
72
  - script/console
59
73
  - script/rebuild
60
74
  - tasks/echoe.rake
61
- - test/i18n/de.yml
75
+ - test/i18n/de.tr
76
+ - test/i18n/en.tr
62
77
  - test/initializers/fake_rails.rb
78
+ - test/rails/Rakefile
79
+ - test/rails/app/controllers/application_controller.rb
80
+ - test/rails/app/controllers/localite_controller.rb
81
+ - test/rails/app/views/localite/index.html.erb
82
+ - test/rails/app/views/localite/template.de.html.erb
83
+ - test/rails/app/views/localite/template.en.html.erb
84
+ - test/rails/config/boot.rb
85
+ - test/rails/config/environment.rb
86
+ - test/rails/config/environments/development.rb
87
+ - test/rails/config/environments/production.rb
88
+ - test/rails/config/environments/test.rb
89
+ - test/rails/config/initializers/new_rails_defaults.rb
90
+ - test/rails/config/initializers/session_store.rb
91
+ - test/rails/config/locales/de.yml
92
+ - test/rails/config/locales/en.yml
93
+ - test/rails/config/routes.rb
94
+ - test/rails/script/console
95
+ - test/rails/script/server
96
+ - test/rails/test/functional/localite_controller_test.rb
97
+ - test/rails/test/test_helper.rb
63
98
  - test/test.rb
64
99
  - localite.gemspec
65
100
  has_rdoc: true
@@ -75,16 +110,20 @@ rdoc_options:
75
110
  require_paths:
76
111
  - lib
77
112
  required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
78
114
  requirements:
79
115
  - - ">="
80
116
  - !ruby/object:Gem::Version
117
+ hash: 3
81
118
  segments:
82
119
  - 0
83
120
  version: "0"
84
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
85
123
  requirements:
86
124
  - - ">="
87
125
  - !ruby/object:Gem::Version
126
+ hash: 11
88
127
  segments:
89
128
  - 1
90
129
  - 2
@@ -92,9 +131,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
131
  requirements: []
93
132
 
94
133
  rubyforge_project: localite
95
- rubygems_version: 1.3.6
134
+ rubygems_version: 1.3.7
96
135
  signing_key:
97
136
  specification_version: 3
98
137
  summary: An easy to use localization gem.
99
- test_files: []
100
-
138
+ test_files:
139
+ - test/rails/test/functional/localite_controller_test.rb
140
+ - test/rails/test/test_helper.rb