Skip to content

Commit

Permalink
started adding rdoc formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmh committed Jun 23, 2008
1 parent fa5d958 commit 5f4c3b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
.DS_Store
test/rails/fixtures
test/rails/fixtures
doc
98 changes: 53 additions & 45 deletions lib/i18n.rb
@@ -1,3 +1,10 @@
# 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
require 'i18n/core_ext'
require 'i18n/backend/simple'

Expand All @@ -6,7 +13,7 @@ module I18n
@@default_locale = 'en-US'

class << self
# Returns the current backend. Defaults to Backend::Simple.
# Returns the current backend. Defaults to +Backend::Simple+.
def backend
@@backend
end
Expand Down Expand Up @@ -37,84 +44,85 @@ def locale=(locale)
end

# Translates, pluralizes and interpolates a given key using a given locale,
# scope, default as well as interpolation values.
# scope, and default, as well as interpolation values.
#
# LOOKUP
# *LOOKUP*
#
# Translation data is organized as a nested hash using the locales as toplevel
# keys. Upper-level keys can be used as namespaces. E.g. ActionView ships with
# the translation: :'en-US' => {:date => {:formats => {:short => "%b %d"}}}
# 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. E.g., in this example :date.t 'en-US' returns the whole
# translations hash {:formats => {:short => "%b %d"}}
# and the scope option. <em>E.g.</em>, in this example <tt>:date.t 'en-US'</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). E.g. the short format can be looked up using both of:
# 'date.formats.short'.t 'en-US'
# :'date.formats.short'.t 'en-US'
# work). <em>E.g.</em>, the short format can be looked up using both:
# 'date.formats.short'.t 'en-US'
# :'date.formats.short'.t 'en-US'
#
# 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:
# 'date.formats.short'.t 'en-US'
# 'formats.short'.t 'en-US', :scope => 'date'
# 'short'.t 'en-US', :scope => 'date.formats'
# 'short'.t 'en-US', :scope => %w(date formats)
# 'date.formats.short'.t 'en-US'
# 'formats.short'.t 'en-US', :scope => 'date'
# 'short'.t 'en-US', :scope => 'date.formats'
# 'short'.t 'en-US', :scope => %w(date formats)
#
# INTERPOLATION
# *INTERPOLATION*
#
# Translations can contain interpolation variables which will be replaced by
# values passed #translate as part of the options hash with the keys matching
# values passed to #translate as part of the options hash, with the keys matching
# the interpolation variable names.
#
# E.g. with a translation :foo => "foo {{bar}}" the option value for the key
# bar will be interpolated to the translation:
# :foo.t :bar => 'baz' # => 'foo baz'
# <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:
# :foo.t :bar => 'baz' # => 'foo baz'
#
# PLURALIZATION
# *PLURALIZATION*
#
# Translation data can contain pluralized translations. Pluralized translations
# are arrays of singluar/plural versions of translations like ['Foo', 'Foos'].
# are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
#
# Note that the I18n::Backend::Simple only supports an algorithm for English
# Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
# pluralization rules. Other algorithms can be supported by custom backends.
#
# Returns the singular version of a pluralized translation:
# :foo, :count => 1 # => 'Foo'
# This returns the singular version of a pluralized translation:
# :foo, :count => 1 # => 'Foo'
#
# Both return the plural version of a pluralized translation:
# :foo, :count => 0 # => 'Foos'
# :foo, :count => 2 # => 'Foos'
# These both return the plural version of a pluralized translation:
# :foo, :count => 0 # => 'Foos'
# :foo, :count => 2 # => 'Foos'
#
# The :count option can be used both for pluralization and interpolation. E.g.
# with the translation :foo => ['{{count}} foo', '{{count}} foos'] count will
# 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:
# :foo, :count => 1 # => '1 foo'
# :foo, :count => 1 # => '1 foo'
#
# DEFAULTS
# *DEFAULTS*
#
# Returns the translation for :foo or 'default' if no translation was found.
# :foo.t :default => 'default'
# This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
# :foo.t :default => 'default'
#
# Returns the translation for :foo or the translation for :bar if no
# translation for :foo was found.
# :foo.t :default => :bar
# This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
# translation for <tt>:foo</tt> was found:
# :foo.t :default => :bar
#
# Returns the translation for :foo or the translation for :bar or 'default' if
# no translations for :foo and :bar were found.
# :foo.t :default => [:bar, 'default']
# 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.
# :foo.t :default => [:bar, 'default']
#
# BULK LOOKUP
# <b>BULK LOOKUP</b>
#
# Returns an array with the translations for :foo and :bar.
# I18n.t [:foo, :bar]
# 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']
# I18n.t [:'baz.foo', :'baz.bar']
#
# Which is the same as using a scope option:
# I18n.t [:foo, :bar], :scope => :baz
# I18n.t [:foo, :bar], :scope => :baz
def translate(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
key = args.shift
Expand Down

0 comments on commit 5f4c3b5

Please sign in to comment.