Permalink
Browse files

Merge branch 'master' of github.com:rails/rails

  • Loading branch information...
2 parents c74cddc + 0f1da1c commit 3b0b6dfc86ba87145be28eca2c1b0500caca4f37 @jeremy jeremy committed Nov 9, 2009
View
@@ -1,7 +1,7 @@
clear_sources
source 'http://gemcutter.org'
-gem "rails", "3.0.pre", :path => "railties"
+gem "rails", "3.0.pre", :vendored_at => "railties"
%w(
activesupport
activemodel
@@ -10,9 +10,8 @@ gem "rails", "3.0.pre", :path => "railties"
activerecord
activeresource
).each do |lib|
- gem lib, '3.0.pre', :path => lib
+ gem lib, '3.0.pre', :vendored_at => lib
end
-gem "i18n", "0.2.0"
gem "rack", "1.0.1"
gem "rack-mount", :git => "git://github.com/rails/rack-mount.git"
gem "rack-test", "~> 0.5.0"
@@ -5,7 +5,7 @@
You may redistribute it and/or modify it under the same license terms as Ruby.
=end
-if RUBY_VERSION < '1.9' && !"".respond_to?(:interpolate_without_ruby_19_syntax)
+if RUBY_VERSION < '1.9'
require 'active_support/core_ext/string/bytesize'
# KeyError is raised by String#% when the string contains a named placeholder
@@ -4,7 +4,7 @@ def ActiveSupport.requirable?(file)
$LOAD_PATH.any? { |p| Dir.glob("#{p}/#{file}.*").any? }
end
-[%w(builder 2.1.2), %w(memcache-client 1.7.5), %w(tzinfo 0.3.15)].each do |lib, version|
+[%w(builder 2.1.2), %w(i18n 0.1.3), %w(memcache-client 1.7.5), %w(tzinfo 0.3.15)].each do |lib, version|
# If the lib is not already requirable
unless ActiveSupport.requirable? lib
# Try to activate a gem ~> satisfying the requested version first.
@@ -0,0 +1,20 @@
+Copyright (c) 2008 The Ruby I18n team
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
@@ -0,0 +1,20 @@
+h1. Ruby I18n gem
+
+I18n and localization solution for Ruby.
+
+For information please refer to http://rails-i18n.org
+
+h2. Authors
+
+* "Matt Aimonetti":http://railsontherun.com
+* "Sven Fuchs":http://www.artweb-design.de
+* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
+* "Saimon Moore":http://saimonmoore.net
+* "Stephan Soller":http://www.arkanis-development.de
+
+h2. License
+
+MIT License. See the included MIT-LICENCE file.
+
+
+
@@ -0,0 +1,5 @@
+task :default => [:test]
+
+task :test do
+ ruby "test/all.rb"
+end
@@ -0,0 +1,27 @@
+Gem::Specification.new do |s|
+ s.name = "i18n"
+ s.version = "0.1.3"
+ s.date = "2009-01-09"
+ s.summary = "Internationalization support for Ruby"
+ s.email = "rails-i18n@googlegroups.com"
+ s.homepage = "http://rails-i18n.org"
+ s.description = "Add Internationalization support to your Ruby application."
+ s.has_rdoc = false
+ s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
+ s.files = [
+ 'i18n.gemspec',
+ 'lib/i18n/backend/simple.rb',
+ 'lib/i18n/exceptions.rb',
+ 'lib/i18n.rb',
+ 'MIT-LICENSE',
+ 'README.textile'
+ ]
+ s.test_files = [
+ 'test/all.rb',
+ 'test/i18n_exceptions_test.rb',
+ 'test/i18n_test.rb',
+ 'test/locale/en.rb',
+ 'test/locale/en.yml',
+ 'test/simple_backend_test.rb'
+ ]
+end
@@ -0,0 +1,204 @@
+#--
+# Authors:: Matt Aimonetti (http://railsontherun.com/),
+# Sven Fuchs (http://www.artweb-design.de),
+# Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
+# Saimon Moore (http://saimonmoore.net),
+# Stephan Soller (http://www.arkanis-development.de/)
+# Copyright:: Copyright (c) 2008 The Ruby i18n Team
+# License:: MIT
+#++
+
+module I18n
+ autoload :ArgumentError, 'i18n/exceptions'
+ module Backend
+ autoload :Simple, 'i18n/backend/simple'
+ end
+
+ @@backend = nil
+ @@load_path = nil
+ @@default_locale = :'en'
+ @@exception_handler = :default_exception_handler
+
+ class << self
+ # Returns the current backend. Defaults to +Backend::Simple+.
+ def backend
+ @@backend ||= Backend::Simple.new
+ end
+
+ # Sets the current backend. Used to set a custom backend.
+ def backend=(backend)
+ @@backend = backend
+ end
+
+ # Returns the current default locale. Defaults to :'en'
+ def default_locale
+ @@default_locale
+ end
+
+ # Sets the current default locale. Used to set a custom default locale.
+ def default_locale=(locale)
+ @@default_locale = locale
+ end
+
+ # Returns the current locale. Defaults to I18n.default_locale.
+ def locale
+ Thread.current[:locale] ||= default_locale
+ end
+
+ # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
+ def locale=(locale)
+ Thread.current[:locale] = locale
+ end
+
+ # Returns an array of locales for which translations are available
+ def available_locales
+ backend.available_locales
+ end
+
+ # Sets the exception handler.
+ def exception_handler=(exception_handler)
+ @@exception_handler = exception_handler
+ end
+
+ # Allow clients to register paths providing translation data sources. The
+ # backend defines acceptable sources.
+ #
+ # E.g. the provided SimpleBackend accepts a list of paths to translation
+ # files which are either named *.rb and contain plain Ruby Hashes or are
+ # named *.yml and contain YAML data. So for the SimpleBackend clients may
+ # register translation files like this:
+ # I18n.load_path << 'path/to/locale/en.yml'
+ def load_path
+ @@load_path ||= []
+ end
+
+ # Sets the load path instance. Custom implementations are expected to
+ # behave like a Ruby Array.
+ def load_path=(load_path)
+ @@load_path = load_path
+ end
+
+ # Tells the backend to reload translations. Used in situations like the
+ # Rails development environment. Backends can implement whatever strategy
+ # is useful.
+ def reload!
+ backend.reload!
+ end
+
+ # Translates, pluralizes and interpolates a given key using a given locale,
+ # scope, and default, as well as interpolation values.
+ #
+ # *LOOKUP*
+ #
+ # Translation data is organized as a nested hash using the upper-level keys
+ # as namespaces. <em>E.g.</em>, ActionView ships with the translation:
+ # <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
+ #
+ # Translations can be looked up at any level of this hash using the key argument
+ # and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
+ # returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
+ #
+ # Key can be either a single key or a dot-separated key (both Strings and Symbols
+ # work). <em>E.g.</em>, the short format can be looked up using both:
+ # I18n.t 'date.formats.short'
+ # I18n.t :'date.formats.short'
+ #
+ # Scope can be either a single key, a dot-separated key or an array of keys
+ # or dot-separated keys. Keys and scopes can be combined freely. So these
+ # examples will all look up the same short date format:
+ # I18n.t 'date.formats.short'
+ # I18n.t 'formats.short', :scope => 'date'
+ # I18n.t 'short', :scope => 'date.formats'
+ # I18n.t 'short', :scope => %w(date formats)
+ #
+ # *INTERPOLATION*
+ #
+ # Translations can contain interpolation variables which will be replaced by
+ # values passed to #translate as part of the options hash, with the keys matching
+ # the interpolation variable names.
+ #
+ # <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
+ # value for the key +bar+ will be interpolated into the translation:
+ # I18n.t :foo, :bar => 'baz' # => 'foo baz'
+ #
+ # *PLURALIZATION*
+ #
+ # Translation data can contain pluralized translations. Pluralized translations
+ # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
+ #
+ # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
+ # pluralization rules. Other algorithms can be supported by custom backends.
+ #
+ # This returns the singular version of a pluralized translation:
+ # I18n.t :foo, :count => 1 # => 'Foo'
+ #
+ # These both return the plural version of a pluralized translation:
+ # I18n.t :foo, :count => 0 # => 'Foos'
+ # I18n.t :foo, :count => 2 # => 'Foos'
+ #
+ # The <tt>:count</tt> option can be used both for pluralization and interpolation.
+ # <em>E.g.</em>, with the translation
+ # <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
+ # be interpolated to the pluralized translation:
+ # I18n.t :foo, :count => 1 # => '1 foo'
+ #
+ # *DEFAULTS*
+ #
+ # This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
+ # I18n.t :foo, :default => 'default'
+ #
+ # This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
+ # translation for <tt>:foo</tt> was found:
+ # I18n.t :foo, :default => :bar
+ #
+ # Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
+ # or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
+ # I18n.t :foo, :default => [:bar, 'default']
+ #
+ # <b>BULK LOOKUP</b>
+ #
+ # This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
+ # I18n.t [:foo, :bar]
+ #
+ # Can be used with dot-separated nested keys:
+ # I18n.t [:'baz.foo', :'baz.bar']
+ #
+ # Which is the same as using a scope option:
+ # I18n.t [:foo, :bar], :scope => :baz
+ def translate(key, options = {})
+ locale = options.delete(:locale) || I18n.locale
+ backend.translate(locale, key, options)
+ rescue I18n::ArgumentError => e
+ raise e if options[:raise]
+ send(@@exception_handler, e, locale, key, options)
+ end
+ alias :t :translate
+
+ # Localizes certain objects, such as dates and numbers to local formatting.
+ def localize(object, options = {})
+ locale = options[:locale] || I18n.locale
+ format = options[:format] || :default
+ backend.localize(locale, object, format)
+ end
+ alias :l :localize
+
+ protected
+ # Handles exceptions raised in the backend. All exceptions except for
+ # MissingTranslationData exceptions are re-raised. When a MissingTranslationData
+ # was caught and the option :raise is not set the handler returns an error
+ # message string containing the key/scope.
+ def default_exception_handler(exception, locale, key, options)
+ return exception.message if MissingTranslationData === exception
+ raise exception
+ end
+
+ # Merges the given locale, key and scope into a single array of keys.
+ # Splits keys that contain dots into multiple keys. Makes sure all
+ # keys are Symbols.
+ def normalize_translation_keys(locale, key, scope)
+ keys = [locale] + Array(scope) + [key]
+ keys = keys.map { |k| k.to_s.split(/\./) }
+ keys.flatten.map { |k| k.to_sym }
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 3b0b6df

Please sign in to comment.