Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update activesupport/vendor i18n gem

  • Loading branch information...
commit 78677cf6af339a6e23a93a45c905d6d1545ccc33 1 parent aae9f91
Sven Fuchs svenfuchs authored
10 activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
View
@@ -56,8 +56,14 @@ def populate(&block)
backend.populate(&block)
end
- def load_translations(filename)
- backend.load_translations filename
+ # Allows client libraries to pass arguments that specify a source for
+ # translation data to be loaded by the backend. 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.)
+ def load_translations(*args)
+ backend.load_translations *args
end
# Stores translations for the given locale in the backend.
13 activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
View
@@ -12,7 +12,10 @@ class << self
def populate(&block)
yield
end
-
+
+ # Accepts a list of paths to translation files. Loads translations from
+ # plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml
+ # for details.
def load_translations(*filenames)
filenames.each {|filename| load_file filename }
end
@@ -135,6 +138,10 @@ def interpolate(locale, string, values = {})
s.string
end
+ # Loads a single translations file by delegating to #load_rb or
+ # #load_yml depending on the file extension and directly merges the
+ # data to the existing translations. Raises I18n::UnknownFileType
+ # for all other file extensions.
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
raise UnknownFileType.new(type, filename) unless respond_to? :"load_#{type}"
@@ -144,10 +151,14 @@ def load_file(filename)
end
end
+ # Loads a plain Ruby translations file. eval'ing the file must yield
+ # a Hash containing translation data with locales as toplevel keys.
def load_rb(filename)
eval IO.read(filename), binding, filename
end
+ # Loads a YAML translations file. The data must have locales as
+ # toplevel keys.
def load_yml(filename)
YAML::load IO.read(filename)
end
Please sign in to comment.
Something went wrong with that request. Please try again.