activeldap 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +17 -0
- data/README +7 -1
- data/Rakefile +2 -1
- data/benchmark/bench-al.rb +3 -3
- data/examples/al-admin/app/helpers/users_helper.rb +1 -1
- data/examples/al-admin/config/environment.rb +4 -3
- data/examples/al-admin/config/initializers/gettext.rb +1 -0
- data/examples/al-admin/config/session_secret.txt +1 -1
- data/examples/al-admin/po/al-admin.pot +344 -0
- data/examples/al-admin/public/images/active-ldap.png +0 -0
- data/examples/al-admin/vendor/locale_rails/.gitignore +6 -0
- data/examples/al-admin/vendor/locale_rails/COPYING +56 -0
- data/examples/al-admin/vendor/locale_rails/ChangeLog +35 -0
- data/examples/al-admin/vendor/locale_rails/README.rdoc +62 -0
- data/examples/al-admin/vendor/locale_rails/Rakefile +73 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails.rb +18 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/action_controller.rb +15 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/action_controller/base.rb +82 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/action_controller/caching.rb +51 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/action_controller/test_process.rb +44 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/action_view.rb +53 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/i18n.rb +67 -0
- data/examples/al-admin/vendor/locale_rails/lib/locale_rails/version.rb +4 -0
- data/examples/al-admin/vendor/locale_rails/sample/README +22 -0
- data/examples/al-admin/vendor/locale_rails/sample/Rakefile +10 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/controllers/application.rb +42 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/controllers/samples_controller.rb +30 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/helpers/application_helper.rb +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/layouts/samples.html.erb +20 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/_part.html.erb +68 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/_part_nl.html.erb +2 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/cached_action.html.erb +6 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/index.html.erb +33 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/index.pt.html.erb +16 -0
- data/examples/al-admin/vendor/locale_rails/sample/app/views/samples/index_uz_UZ.html.erb +16 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/boot.rb +109 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/environment.rb +25 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/environments/development.rb +17 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/environments/production.rb +24 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/environments/test.rb +22 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/initializers/inflections.rb +10 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/initializers/mime_types.rb +5 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/initializers/new_rails_defaults.rb +17 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/locales/en.yml +2 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/locales/ja.yml +2 -0
- data/examples/al-admin/vendor/locale_rails/sample/config/routes.rb +13 -0
- data/examples/al-admin/vendor/locale_rails/sample/db/schema.rb +10 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/404.html +30 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/422.html +30 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/500.html +33 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/dispatch.cgi +10 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/dispatch.fcgi +24 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/dispatch.rb +10 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/favicon.ico +0 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/images/rails.png +0 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/javascripts/application.js +2 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/javascripts/controls.js +963 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/javascripts/dragdrop.js +972 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/javascripts/effects.js +1120 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/javascripts/prototype.js +4221 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/robots.txt +5 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/stylesheets/locale.css +81 -0
- data/examples/al-admin/vendor/locale_rails/sample/public/stylesheets/scaffold.css +74 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/about +4 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/console +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/dbconsole +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/destroy +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/generate +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/performance/benchmarker +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/performance/profiler +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/performance/request +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/plugin +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/process/inspector +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/process/reaper +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/process/spawner +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/runner +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/script/server +3 -0
- data/examples/al-admin/vendor/locale_rails/sample/test/performance/browsing_test.rb +9 -0
- data/examples/al-admin/vendor/locale_rails/sample/test/test_helper.rb +38 -0
- data/examples/al-admin/vendor/locale_rails/test/README +243 -0
- data/examples/al-admin/vendor/locale_rails/test/Rakefile +10 -0
- data/examples/al-admin/vendor/locale_rails/test/app/controllers/application_controller.rb +10 -0
- data/examples/al-admin/vendor/locale_rails/test/app/controllers/articles_controller.rb +17 -0
- data/examples/al-admin/vendor/locale_rails/test/app/helpers/application_helper.rb +3 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/index.html.erb +1 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/index_de.html.erb +1 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/index_fr_FR.html.erb +1 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/index_ja.html.erb +1 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/list.html.erb +1 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/show.html.erb +0 -0
- data/examples/al-admin/vendor/locale_rails/test/app/views/articles/show.js.rjs +0 -0
- data/examples/al-admin/vendor/locale_rails/test/config/boot.rb +110 -0
- data/examples/al-admin/vendor/locale_rails/test/config/environment.rb +42 -0
- data/examples/al-admin/vendor/locale_rails/test/config/environments/development.rb +17 -0
- data/examples/al-admin/vendor/locale_rails/test/config/environments/production.rb +28 -0
- data/examples/al-admin/vendor/locale_rails/test/config/environments/test.rb +35 -0
- data/examples/al-admin/vendor/locale_rails/test/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/al-admin/vendor/locale_rails/test/config/initializers/inflections.rb +10 -0
- data/examples/al-admin/vendor/locale_rails/test/config/initializers/mime_types.rb +5 -0
- data/examples/al-admin/vendor/locale_rails/test/config/initializers/new_rails_defaults.rb +19 -0
- data/examples/al-admin/vendor/locale_rails/test/config/initializers/session_store.rb +15 -0
- data/examples/al-admin/vendor/locale_rails/test/config/locales/en.yml +5 -0
- data/examples/al-admin/vendor/locale_rails/test/config/routes.rb +46 -0
- data/examples/al-admin/vendor/locale_rails/test/db/schema.rb +0 -0
- data/examples/al-admin/vendor/locale_rails/test/public/404.html +30 -0
- data/examples/al-admin/vendor/locale_rails/test/public/422.html +30 -0
- data/examples/al-admin/vendor/locale_rails/test/public/500.html +30 -0
- data/examples/al-admin/vendor/locale_rails/test/public/favicon.ico +0 -0
- data/examples/al-admin/vendor/locale_rails/test/public/images/rails.png +0 -0
- data/examples/al-admin/vendor/locale_rails/test/public/index.html +275 -0
- data/examples/al-admin/vendor/locale_rails/test/public/javascripts/application.js +2 -0
- data/examples/al-admin/vendor/locale_rails/test/public/javascripts/controls.js +963 -0
- data/examples/al-admin/vendor/locale_rails/test/public/javascripts/dragdrop.js +973 -0
- data/examples/al-admin/vendor/locale_rails/test/public/javascripts/effects.js +1128 -0
- data/examples/al-admin/vendor/locale_rails/test/public/javascripts/prototype.js +4320 -0
- data/examples/al-admin/vendor/locale_rails/test/public/robots.txt +5 -0
- data/examples/al-admin/vendor/locale_rails/test/script/about +4 -0
- data/examples/al-admin/vendor/locale_rails/test/script/console +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/dbconsole +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/destroy +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/generate +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/performance/benchmarker +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/performance/profiler +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/plugin +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/runner +3 -0
- data/examples/al-admin/vendor/locale_rails/test/script/server +3 -0
- data/examples/al-admin/vendor/locale_rails/test/test/functional/articles_controller_test.rb +161 -0
- data/examples/al-admin/vendor/locale_rails/test/test/performance/browsing_test.rb +9 -0
- data/examples/al-admin/vendor/locale_rails/test/test/test_helper.rb +38 -0
- data/lib/active_ldap.rb +9 -4
- data/lib/active_ldap/adapter/base.rb +3 -3
- data/lib/active_ldap/adapter/jndi.rb +1 -1
- data/lib/active_ldap/adapter/jndi_connection.rb +1 -3
- data/lib/active_ldap/adapter/ldap.rb +11 -11
- data/lib/active_ldap/adapter/ldap_ext.rb +25 -3
- data/lib/active_ldap/adapter/net_ldap.rb +9 -2
- data/lib/active_ldap/association/collection.rb +14 -2
- data/lib/active_ldap/base.rb +13 -5
- data/lib/active_ldap/configuration.rb +1 -0
- data/lib/active_ldap/ldap_error.rb +3 -3
- data/lib/active_ldap/ldif.rb +1 -1
- data/lib/active_ldap/operations.rb +2 -0
- data/lib/active_ldap/schema/syntaxes.rb +2 -2
- data/lib/active_ldap/validations.rb +37 -26
- data/lib/active_ldap/xml.rb +2 -0
- data/po/active-ldap.pot +38 -58
- data/test-unit/COPYING +56 -0
- data/test-unit/GPL +340 -0
- data/test-unit/History.txt +65 -3
- data/test-unit/Manifest.txt +5 -0
- data/test-unit/PSFL +271 -0
- data/test-unit/README.txt +6 -1
- data/test-unit/lib/test/unit.rb +6 -1
- data/test-unit/lib/test/unit/assertions.rb +129 -13
- data/test-unit/lib/test/unit/autorunner.rb +21 -16
- data/test-unit/lib/test/unit/collector.rb +1 -8
- data/test-unit/lib/test/unit/collector/dir.rb +1 -1
- data/test-unit/lib/test/unit/collector/load.rb +15 -7
- data/test-unit/lib/test/unit/color-scheme.rb +6 -2
- data/test-unit/lib/test/unit/diff.rb +17 -1
- data/test-unit/lib/test/unit/error.rb +4 -0
- data/test-unit/lib/test/unit/failure.rb +4 -0
- data/test-unit/lib/test/unit/notification.rb +8 -4
- data/test-unit/lib/test/unit/omission.rb +4 -0
- data/test-unit/lib/test/unit/pending.rb +4 -0
- data/test-unit/lib/test/unit/priority.rb +2 -3
- data/test-unit/lib/test/unit/testcase.rb +18 -7
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +5 -3
- data/test-unit/lib/test/unit/util/backtracefilter.rb +1 -0
- data/test-unit/lib/test/unit/util/output.rb +31 -0
- data/test-unit/lib/test/unit/version.rb +1 -1
- data/test-unit/test/collector/test-descendant.rb +2 -4
- data/test-unit/test/collector/test-load.rb +121 -8
- data/test-unit/test/collector/test_objectspace.rb +7 -5
- data/test-unit/test/test-color-scheme.rb +4 -2
- data/test-unit/test/test-testcase.rb +48 -38
- data/test-unit/test/test_assertions.rb +87 -5
- data/test-unit/test/util/test-output.rb +11 -0
- data/test/al-test-utils.rb +6 -1
- data/test/fixtures/lower_case_object_class_schema.rb +802 -0
- data/test/test_associations.rb +20 -1
- data/test/test_base.rb +50 -3
- data/test/test_ldif.rb +10 -1
- data/test/test_syntax.rb +12 -0
- data/test/test_validation.rb +0 -2
- metadata +225 -56
@@ -0,0 +1,53 @@
|
|
1
|
+
=begin
|
2
|
+
locale_rails/lib/action_view.rb - Ruby/Locale for "Ruby on Rails"
|
3
|
+
|
4
|
+
Copyright (C) 2008-2009 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby or LGPL.
|
8
|
+
|
9
|
+
Original: Ruby-GetText-Package-1.92.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'action_view'
|
14
|
+
|
15
|
+
module ActionView #:nodoc:
|
16
|
+
class PathSet < Array
|
17
|
+
def _find_template_internal(file_name, format, html_fallback = false)
|
18
|
+
begin
|
19
|
+
return find_template_without_locale_rails(file_name, format, html_fallback)
|
20
|
+
rescue MissingTemplate => e
|
21
|
+
end
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_template_with_locale_rails(original_template_path, format = nil, html_fallback = true)
|
26
|
+
return original_template_path if original_template_path.respond_to?(:render)
|
27
|
+
|
28
|
+
path = original_template_path.sub(/^\//, '')
|
29
|
+
if m = path.match(/(.*)\.(\w+)$/)
|
30
|
+
template_file_name, template_file_extension = m[1], m[2]
|
31
|
+
else
|
32
|
+
template_file_name = path
|
33
|
+
end
|
34
|
+
|
35
|
+
default = Locale.default.to_common
|
36
|
+
Locale.candidates.each do |v|
|
37
|
+
file_name = "#{template_file_name}_#{v}"
|
38
|
+
file_name += ".#{template_file_extension}" if template_file_extension
|
39
|
+
ret = _find_template_internal(file_name, format)
|
40
|
+
return ret if ret
|
41
|
+
if v == default
|
42
|
+
# When the user locale is the default locale, find no locale file such as index.html.erb.
|
43
|
+
ret = _find_template_internal(path, format)
|
44
|
+
end
|
45
|
+
return ret if ret
|
46
|
+
end
|
47
|
+
find_template_without_locale_rails(original_template_path, format, html_fallback)
|
48
|
+
end
|
49
|
+
alias_method_chain :find_template, :locale_rails
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
=begin
|
2
|
+
locale_rails/lib/i18n.rb - Ruby/Locale for "Ruby on Rails"
|
3
|
+
|
4
|
+
Copyright (C) 2008,2009 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby or LGPL.
|
8
|
+
|
9
|
+
=end
|
10
|
+
|
11
|
+
module I18n
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Gets the supported locales.
|
15
|
+
def supported_locales
|
16
|
+
::Locale.app_language_tags
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sets the supported locales.
|
20
|
+
# I18n.set_supported_locales("ja-JP", "ko-KR", ...)
|
21
|
+
def set_supported_locales(*tags)
|
22
|
+
::Locale.set_app_language_tags(*tags)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sets the supported locales as an Array.
|
26
|
+
# I18n.supported_locales = ["ja-JP", "ko-KR", ...]
|
27
|
+
def supported_locales=(tags)
|
28
|
+
::Locale.set_app_language_tags(*tags)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Sets the ::Locale.
|
32
|
+
# I18n.locale = "ja-JP"
|
33
|
+
def locale_with_locale_rails=(tag)
|
34
|
+
::Locale.clear
|
35
|
+
tag = ::Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
|
36
|
+
::Locale.current = tag
|
37
|
+
self.locale_without_locale_rails = ::Locale.candidates(:type => :rfc)[0].to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets the default ::Locale.
|
41
|
+
# I18n.default_locale = "ja"
|
42
|
+
def default_locale=(tag)
|
43
|
+
tag = ::Locale::Tag::Rfc.parse(tag.to_s) if tag.kind_of? Symbol
|
44
|
+
::Locale.default = tag
|
45
|
+
@@default_locale = tag
|
46
|
+
end
|
47
|
+
|
48
|
+
class << self
|
49
|
+
alias_method_chain :locale=, :locale_rails
|
50
|
+
|
51
|
+
# MissingTranslationData is overrided to fallback messages in candidate locales.
|
52
|
+
def locale_rails_exception_handler(exception, locale, key, options) #:nodoc:
|
53
|
+
ret = nil
|
54
|
+
::Locale.candidates(:type => :rfc).each do |loc|
|
55
|
+
begin
|
56
|
+
ret = backend.translate(loc, key, options)
|
57
|
+
break
|
58
|
+
rescue I18n::MissingTranslationData
|
59
|
+
ret = I18n.default_exception_handler(exception, locale, key, options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
ret
|
63
|
+
end
|
64
|
+
I18n.exception_handler = :locale_rails_exception_handler
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
== Ruby-Locale for Ruby on Rails sample application
|
2
|
+
This is the sample application for localization.
|
3
|
+
|
4
|
+
=== Includes
|
5
|
+
1. How to get current language.
|
6
|
+
2. Auto-Detect the locale from the WWW browser
|
7
|
+
3. Set locale as the "lang" parameter
|
8
|
+
4. Set "lang" as the cookie value
|
9
|
+
5. Localized Routes
|
10
|
+
6. Action caching
|
11
|
+
7. Separate Localized View template file
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
1. Instal rails-2.2.x.
|
16
|
+
2. Install sqlite3-ruby
|
17
|
+
gem install sqlite3-ruby
|
18
|
+
3. Install locale_rails
|
19
|
+
gem install locale_rails
|
20
|
+
4. rake db:create
|
21
|
+
5. ruby script/server
|
22
|
+
6. Access http://localhost:3000/ from the WWW browser.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
|
7
|
+
# See ActionController::RequestForgeryProtection for details
|
8
|
+
# Uncomment the :secret if you're not using the cookie session store
|
9
|
+
protect_from_forgery # :secret => '639df270d82028344f5a50f543530c57'
|
10
|
+
|
11
|
+
# See ActionController::Base for details
|
12
|
+
# Uncomment this to filter the contents of submitted sensitive data parameters
|
13
|
+
# from your application log (in this case, all fields with names like "password").
|
14
|
+
# filter_parameter_logging :password
|
15
|
+
|
16
|
+
# Set the charset of Content-Type.
|
17
|
+
# This is not Ruby-Locale method but useful.
|
18
|
+
# self.default_charset = "iso8859-1"
|
19
|
+
# I18n.supported_locales = ["en", "ja", "fr"]
|
20
|
+
|
21
|
+
=begin
|
22
|
+
def before_init_i18n
|
23
|
+
# Initialize other i18n libraries before init_locale if you need.
|
24
|
+
# Or set "lang" to it's own value before initializing Locale.
|
25
|
+
if (cookies["lang"].nil? or cookies["lang"].empty?)
|
26
|
+
params["lang"] = "ko_KR"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
before_init_locale :before_init_i18n
|
30
|
+
|
31
|
+
def after_init_i18n
|
32
|
+
# Initialize other i18n libraries after init_locale if you need.
|
33
|
+
#
|
34
|
+
# LocalizeFoo.locale = Locale.current
|
35
|
+
# I18n.locale is set in init_locale, but other I18n features
|
36
|
+
# is not set by Ruby-Locale. So you may need to add the code to work your
|
37
|
+
# Rails i18n plugins.
|
38
|
+
end
|
39
|
+
after_init_locale :after_init_i18n
|
40
|
+
=end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class SamplesController < ApplicationController
|
2
|
+
caches_action :cached_action
|
3
|
+
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_cookie
|
8
|
+
flash[:notice] = "Cookie lang value is: " + params[:id]
|
9
|
+
|
10
|
+
cookies["lang"] = params[:id]
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.html { redirect_to :action => "index" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_cookie
|
18
|
+
cookies["lang"] = nil
|
19
|
+
|
20
|
+
flash[:notice] = "Cookie lang value is cleared. "
|
21
|
+
respond_to do |format|
|
22
|
+
format.html { redirect_to :action => "index" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cached_action
|
27
|
+
p "cached_action. This is shown first time only."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= Locale.current.to_rfc %>" lang="<%= Locale.current.to_rfc %>">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=<%= Locale.charset %>" />
|
7
|
+
<title>Ruby-Locale Sample on Ruby on Rails: <%= controller.action_name %></title>
|
8
|
+
<%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
<%= stylesheet_link_tag 'locale' %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<p style="color: red"><%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%= yield %>
|
15
|
+
|
16
|
+
<div class="copyright">
|
17
|
+
Copyright (C) 2008 Masao Mutoh
|
18
|
+
</div>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<%
|
2
|
+
app_lang_tags = ["ja_JP", "fr", "pt_BR", "zh_CN", "en_Latn_US_NYNORSK", "uz_UZ", "nl"]
|
3
|
+
%>
|
4
|
+
|
5
|
+
<h2>Get the current locale</h2>
|
6
|
+
<h3>Locale.candidates(with no option)</h3>
|
7
|
+
<p>Requested Locales order by the priority. This method is added by Ruby-Locale for Ruby on Rails.</p>
|
8
|
+
<div class="result">
|
9
|
+
<%=h Locale.candidates.inspect %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<h3>I18n.locale (with inspect)</h3>
|
13
|
+
<p>I18n.locale is set the result(Locale::TagList) of Locale.candidates(:type => :rfc).<br/>
|
14
|
+
This method is extended by Ruby-Locale for Ruby on Rails and returns all candidates as the Locale::TagList.
|
15
|
+
</p>
|
16
|
+
<div class="result">
|
17
|
+
<%=h I18n.locale.inspect %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<h3>I18n.locale (without inspect)</h3>
|
21
|
+
<p>Locale::TagList(the result of I18n.locale) can behave like a single tag string to follow I18n.locale specification.</p>
|
22
|
+
<div class="result">
|
23
|
+
<%=h I18n.locale %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<h2>Auto-Detect the locale from the WWW browser</h2>
|
27
|
+
<p><a href="<%= samples_path %>">Reload this URL</a></p>
|
28
|
+
|
29
|
+
<h2>Set locale as the "lang" parameter</h2>
|
30
|
+
|
31
|
+
<ol>
|
32
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
33
|
+
url = samples_path(:lang => lang) %>
|
34
|
+
<li><%= link_to h(url), url %> [<%= lang %>]</li>
|
35
|
+
<% end %>
|
36
|
+
</ol>
|
37
|
+
|
38
|
+
<h2>Set "lang" as the cookie value.</h2>
|
39
|
+
<p>Click one of the link below, and then click "Auto-Detect the locale from the WWW browser".</p>
|
40
|
+
|
41
|
+
<ol>
|
42
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
43
|
+
url = url_for(:controller => :samples, :action => :set_cookie, :id => lang) %>
|
44
|
+
<li><%= link_to h(url), {:action => :set_cookie, :id => lang} %> [<%= lang %>]</li>
|
45
|
+
<% end %>
|
46
|
+
<li><%= link_to "Clear cookie", :action => :clear_cookie %> </li>
|
47
|
+
</ol>
|
48
|
+
|
49
|
+
<h2>Localized Routes</h2>
|
50
|
+
<p>See config/routes.rb</p>
|
51
|
+
|
52
|
+
<ol>
|
53
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
54
|
+
url = url_for(:controller => :samples, :lang => lang, :action => :index) %>
|
55
|
+
<li><%= link_to h(url),:controller => :samples, :lang => lang, :action => :index %> [<%= lang %>]</li>
|
56
|
+
<% end %>
|
57
|
+
</ol>
|
58
|
+
|
59
|
+
<h2>Caching</h2>
|
60
|
+
<p>Fragment/Action caching is supported. Here is the sample for action caching. <br/>
|
61
|
+
Click the links then check %{RAILS_ROOT}/tmp/cache/ where Cached file is stored.
|
62
|
+
</p>
|
63
|
+
<ol>
|
64
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
65
|
+
url = url_for(:controller => :samples, :action => :cached_action, :lang => lang) %>
|
66
|
+
<li><%= link_to h(url), {:controller => :samples, :action => :cached_action, :lang => lang} %> [<%= lang %>]</li>
|
67
|
+
<% end %>
|
68
|
+
</ol>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<p style="color:red">This page is cached for [<%= I18n.locale %>]. <br/>
|
5
|
+
See %{RAILS_ROOT}/tmp/cache/*.</p>
|
6
|
+
<p><%= link_to "[BACK]", samples_path %></p>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<h2>The values from Rails</h2>
|
5
|
+
<table border="1" cellspacing="0" cellpadding="2">
|
6
|
+
<tr><th>Variables</th><th>Values</th></tr>
|
7
|
+
<tr><td>HTTP_ACCEPT_LANGUAGE</td><td> <%= request.accept_language %></td></tr>
|
8
|
+
<tr><td>HTTP_ACCEPT_CHARSET</td><td> <%= request.accept_charset %></td></tr>
|
9
|
+
<tr><td>QUERY_STRING</td><td> <%= request.query_string %></td></tr>
|
10
|
+
<tr><td>params[:lang]</td><td><%= params[:lang] %></td></tr>
|
11
|
+
<tr><td>cookies[:lang]</td><td> <%= cookies[:lang] %></td></tr>
|
12
|
+
<tr><td>I18n.t :hello (*1)</td><td> <%= I18n.t :hello %></td></tr>
|
13
|
+
</table>
|
14
|
+
<p>
|
15
|
+
(*1) Fallback to "en" if the localized message is not found in the locale.
|
16
|
+
Currently, <%= Dir.glob(File.join(RAILS_ROOT, "config/locales/*.yml")).collect {|v| File.basename(v, ".yml")}.inspect %> are available.
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<%= render :partial => 'part' %>
|
20
|
+
|
21
|
+
<h2>Separate Localized View template file in each languages</h2>
|
22
|
+
<p>View template can be separeted with language tags.</p>
|
23
|
+
<ol>
|
24
|
+
<li><%= link_to "uz_UZ has special index page(index_uz_UZ.html.erb)", :controller => :samples, :action => :index, :lang => "uz_UZ" %></li>
|
25
|
+
<li><%= link_to "uz uses normal index page", :controller => :samples, :action => :index, :lang => "uz" %></li>
|
26
|
+
<li><%= link_to "nl has special _part page(_part_nl.html.erb)", :controller => :samples, :action => :index, :lang => "nl" %></li>
|
27
|
+
<li><%= link_to "nl_BE also uses the special _part page(_part_nl.html.erb)", :controller => :samples, :action => :index, :lang => "nl_BE" %></li>
|
28
|
+
</ol>
|
29
|
+
<p>View template by Rails-2.3.x is also supported. </p>
|
30
|
+
<ol>
|
31
|
+
<li><%= link_to "pt has special index page(index.pt.html.erb)", :controller => :samples, :action => :index, :lang => "pt" %></li>
|
32
|
+
<li><%= link_to "pt_BR uses normal index page", :controller => :samples, :action => :index, :lang => "pt_BR" %></li>
|
33
|
+
</ol>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<h2>The values from Rails</h2>
|
5
|
+
<table border="1" cellspacing="0" cellpadding="2">
|
6
|
+
<tr><th>Variables</th><th>Values</th></tr>
|
7
|
+
<tr><td>HTTP_ACCEPT_LANGUAGE</td><td> <%= request.accept_language %></td></tr>
|
8
|
+
<tr><td>HTTP_ACCEPT_CHARSET</td><td> <%= request.accept_charset %></td></tr>
|
9
|
+
<tr><td>QUERY_STRING</td><td> <%= request.query_string %></td></tr>
|
10
|
+
<tr><td>params[:lang]</td><td><%= params[:lang] %></td></tr>
|
11
|
+
<tr><td>cookies[:lang]</td><td> <%= cookies[:lang] %></td></tr>
|
12
|
+
<tr><td>I18n.t :hello (*1)</td><td> <%= I18n.t :hello %></td></tr>
|
13
|
+
</table>
|
14
|
+
|
15
|
+
<p style="color:red">This page is for pt only. See app/views/samples/index.pt.html.erb. This format is supported by Rails-2.3.x as default.</p>
|
16
|
+
<p><%= link_to "[BACK]", samples_path %></p>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<h2>The values from Rails</h2>
|
5
|
+
<table border="1" cellspacing="0" cellpadding="2">
|
6
|
+
<tr><th>Variables</th><th>Values</th></tr>
|
7
|
+
<tr><td>HTTP_ACCEPT_LANGUAGE</td><td> <%= request.accept_language %></td></tr>
|
8
|
+
<tr><td>HTTP_ACCEPT_CHARSET</td><td> <%= request.accept_charset %></td></tr>
|
9
|
+
<tr><td>QUERY_STRING</td><td> <%= request.query_string %></td></tr>
|
10
|
+
<tr><td>params[:lang]</td><td><%= params[:lang] %></td></tr>
|
11
|
+
<tr><td>cookies[:lang]</td><td> <%= cookies[:lang] %></td></tr>
|
12
|
+
<tr><td>I18n.t :hello (*1)</td><td> <%= I18n.t :hello %></td></tr>
|
13
|
+
</table>
|
14
|
+
|
15
|
+
<p style="color:red">This page is for uz_UZ only. See app/views/samples/index_uz_UZ.html.erb.</p>
|
16
|
+
<p><%= link_to "[BACK]", samples_path %></p>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class GemBoot < Boot
|
51
|
+
def load_initializer
|
52
|
+
self.class.load_rubygems
|
53
|
+
load_rails_gem
|
54
|
+
require 'initializer'
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_rails_gem
|
58
|
+
if version = self.class.gem_version
|
59
|
+
gem 'rails', version
|
60
|
+
else
|
61
|
+
gem 'rails'
|
62
|
+
end
|
63
|
+
rescue Gem::LoadError => load_error
|
64
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def rubygems_version
|
70
|
+
Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
|
71
|
+
end
|
72
|
+
|
73
|
+
def gem_version
|
74
|
+
if defined? RAILS_GEM_VERSION
|
75
|
+
RAILS_GEM_VERSION
|
76
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
77
|
+
ENV['RAILS_GEM_VERSION']
|
78
|
+
else
|
79
|
+
parse_gem_version(read_environment_rb)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_rubygems
|
84
|
+
require 'rubygems'
|
85
|
+
min_version = '1.1.1'
|
86
|
+
unless rubygems_version >= min_version
|
87
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue LoadError
|
92
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_gem_version(text)
|
97
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def read_environment_rb
|
102
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# All that for this:
|
109
|
+
Rails.boot!
|