polish 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +14 -0
- data/README.md +9 -10
- data/Rakefile +25 -46
- data/VERSION +1 -0
- data/lib/polish.rb +5 -64
- data/lib/polish/locale/actionview.yml +5 -1
- data/lib/polish/locale/activerecord.yml +6 -1
- data/lib/polish/locale/datetime.rb +44 -0
- data/lib/polish/locale/datetime.yml +6 -15
- data/lib/polish/locale/pluralize.rb +16 -11
- data/lib/polish/proxies.rb +45 -0
- data/lib/proxies.rb +2 -0
- data/polish.gemspec +75 -0
- data/rails/init.rb +1 -0
- data/spec/fixtures/en.yml +2 -1
- data/spec/i18n/locale/datetime_spec.rb +30 -13
- data/spec/locale_spec.rb +23 -10
- data/spec/polish_spec.rb +11 -59
- data/spec/proxies_spec.rb +66 -0
- data/spec/spec_helper.rb +2 -0
- metadata +44 -79
- data/init.rb +0 -1
- data/lib/polish/backend/advanced.rb +0 -107
- data/lib/vendor/i18n/CHANGELOG.textile +0 -57
- data/lib/vendor/i18n/MIT-LICENSE +0 -20
- data/lib/vendor/i18n/README.textile +0 -42
- data/lib/vendor/i18n/Rakefile +0 -21
- data/lib/vendor/i18n/VERSION +0 -1
- data/lib/vendor/i18n/i18n.gemspec +0 -141
- data/lib/vendor/i18n/lib/i18n.rb +0 -270
- data/lib/vendor/i18n/lib/i18n/backend/base.rb +0 -251
- data/lib/vendor/i18n/lib/i18n/backend/cache.rb +0 -71
- data/lib/vendor/i18n/lib/i18n/backend/chain.rb +0 -64
- data/lib/vendor/i18n/lib/i18n/backend/fallbacks.rb +0 -53
- data/lib/vendor/i18n/lib/i18n/backend/gettext.rb +0 -65
- data/lib/vendor/i18n/lib/i18n/backend/pluralization.rb +0 -56
- data/lib/vendor/i18n/lib/i18n/backend/simple.rb +0 -23
- data/lib/vendor/i18n/lib/i18n/exceptions.rb +0 -61
- data/lib/vendor/i18n/lib/i18n/gettext.rb +0 -25
- data/lib/vendor/i18n/lib/i18n/helpers/gettext.rb +0 -35
- data/lib/vendor/i18n/lib/i18n/locale/fallbacks.rb +0 -100
- data/lib/vendor/i18n/lib/i18n/locale/tag.rb +0 -27
- data/lib/vendor/i18n/lib/i18n/locale/tag/parents.rb +0 -24
- data/lib/vendor/i18n/lib/i18n/locale/tag/rfc4646.rb +0 -78
- data/lib/vendor/i18n/lib/i18n/locale/tag/simple.rb +0 -44
- data/lib/vendor/i18n/lib/i18n/string.rb +0 -95
- data/lib/vendor/i18n/test/all.rb +0 -5
- data/lib/vendor/i18n/test/api/basics.rb +0 -15
- data/lib/vendor/i18n/test/api/interpolation.rb +0 -85
- data/lib/vendor/i18n/test/api/lambda.rb +0 -52
- data/lib/vendor/i18n/test/api/link.rb +0 -47
- data/lib/vendor/i18n/test/api/localization/date.rb +0 -65
- data/lib/vendor/i18n/test/api/localization/date_time.rb +0 -63
- data/lib/vendor/i18n/test/api/localization/lambda.rb +0 -26
- data/lib/vendor/i18n/test/api/localization/time.rb +0 -63
- data/lib/vendor/i18n/test/api/pluralization.rb +0 -37
- data/lib/vendor/i18n/test/api/translation.rb +0 -51
- data/lib/vendor/i18n/test/backend/cache/cache_test.rb +0 -57
- data/lib/vendor/i18n/test/backend/chain/api_test.rb +0 -80
- data/lib/vendor/i18n/test/backend/chain/chain_test.rb +0 -64
- data/lib/vendor/i18n/test/backend/fallbacks/api_test.rb +0 -79
- data/lib/vendor/i18n/test/backend/fallbacks/fallbacks_test.rb +0 -29
- data/lib/vendor/i18n/test/backend/pluralization/api_test.rb +0 -81
- data/lib/vendor/i18n/test/backend/pluralization/pluralization_test.rb +0 -39
- data/lib/vendor/i18n/test/backend/simple/all.rb +0 -5
- data/lib/vendor/i18n/test/backend/simple/api_test.rb +0 -90
- data/lib/vendor/i18n/test/backend/simple/lookup_test.rb +0 -24
- data/lib/vendor/i18n/test/backend/simple/setup.rb +0 -147
- data/lib/vendor/i18n/test/backend/simple/translations_test.rb +0 -89
- data/lib/vendor/i18n/test/fixtures/locales/de.po +0 -61
- data/lib/vendor/i18n/test/fixtures/locales/en.rb +0 -3
- data/lib/vendor/i18n/test/fixtures/locales/en.yml +0 -3
- data/lib/vendor/i18n/test/fixtures/locales/plurals.rb +0 -112
- data/lib/vendor/i18n/test/gettext/api_test.rb +0 -78
- data/lib/vendor/i18n/test/gettext/backend_test.rb +0 -35
- data/lib/vendor/i18n/test/i18n_exceptions_test.rb +0 -97
- data/lib/vendor/i18n/test/i18n_load_path_test.rb +0 -23
- data/lib/vendor/i18n/test/i18n_test.rb +0 -163
- data/lib/vendor/i18n/test/locale/fallbacks_test.rb +0 -128
- data/lib/vendor/i18n/test/locale/tag/rfc4646_test.rb +0 -147
- data/lib/vendor/i18n/test/locale/tag/simple_test.rb +0 -35
- data/lib/vendor/i18n/test/string_test.rb +0 -94
- data/lib/vendor/i18n/test/test_helper.rb +0 -71
- data/lib/vendor/i18n/test/with_options.rb +0 -34
- data/lib/vendor/i18n/vendor/po_parser.rb +0 -329
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'polish'
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module I18n
|
4
|
-
module Backend
|
5
|
-
# Advanced I18n backend.
|
6
|
-
#
|
7
|
-
# Extends Simple backend. Allows usage of "standalone" keys
|
8
|
-
# for DateTime localization and usage of user-defined Proc (lambda) pluralization
|
9
|
-
# methods in translation tables.
|
10
|
-
class Advanced < Simple
|
11
|
-
LOCALIZE_ABBR_MONTH_NAMES_MATCH = /(%d|%e)(.*)(%b)/
|
12
|
-
LOCALIZE_MONTH_NAMES_MATCH = /(%d|%e)(.*)(%B)/
|
13
|
-
LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH = /^%a/
|
14
|
-
LOCALIZE_STANDALONE_DAY_NAMES_MATCH = /^%A/
|
15
|
-
|
16
|
-
# Acts the same as +strftime+, but returns a localized version of the
|
17
|
-
# formatted date string. Takes a key from the date/time formats
|
18
|
-
# translations as a format argument (<em>e.g.</em>, <tt>:short</tt> in <tt>:'date.formats'</tt>).
|
19
|
-
#
|
20
|
-
# Note that it differs from <tt>localize</tt> in Simple< backend by checking for
|
21
|
-
# "standalone" month name/day name keys in translation and using them if available.
|
22
|
-
#
|
23
|
-
# <tt>options</tt> parameter added for i18n-0.3 compliance.
|
24
|
-
def localize(locale, object, format = :default, options = nil)
|
25
|
-
raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
|
26
|
-
type = object.respond_to?(:sec) ? 'time' : 'date'
|
27
|
-
# TODO only translate these if format is a String?
|
28
|
-
formats = translate(locale, :"#{type}.formats")
|
29
|
-
format = formats[format.to_sym] if formats && formats[format.to_sym]
|
30
|
-
# TODO raise exception unless format found?
|
31
|
-
format = format.to_s.dup
|
32
|
-
|
33
|
-
# TODO only translate these if the format string is actually present
|
34
|
-
# TODO check which format strings are present, then bulk translate then, then replace them
|
35
|
-
|
36
|
-
if lookup(locale, :"date.standalone_abbr_day_names")
|
37
|
-
format.gsub!(LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH,
|
38
|
-
translate(locale, :"date.standalone_abbr_day_names")[object.wday])
|
39
|
-
end
|
40
|
-
format.gsub!(/%a/, translate(locale, :"date.abbr_day_names")[object.wday])
|
41
|
-
|
42
|
-
if lookup(locale, :"date.standalone_day_names")
|
43
|
-
format.gsub!(LOCALIZE_STANDALONE_DAY_NAMES_MATCH,
|
44
|
-
translate(locale, :"date.standalone_day_names")[object.wday])
|
45
|
-
end
|
46
|
-
format.gsub!(/%A/, translate(locale, :"date.day_names")[object.wday])
|
47
|
-
|
48
|
-
if lookup(locale, :"date.standalone_abbr_month_names")
|
49
|
-
format.gsub!(LOCALIZE_ABBR_MONTH_NAMES_MATCH) do
|
50
|
-
$1 + $2 + translate(locale, :"date.abbr_month_names")[object.mon]
|
51
|
-
end
|
52
|
-
format.gsub!(/%b/, translate(locale, :"date.standalone_abbr_month_names")[object.mon])
|
53
|
-
else
|
54
|
-
format.gsub!(/%b/, translate(locale, :"date.abbr_month_names")[object.mon])
|
55
|
-
end
|
56
|
-
|
57
|
-
if lookup(locale, :"date.standalone_month_names")
|
58
|
-
format.gsub!(LOCALIZE_MONTH_NAMES_MATCH) do
|
59
|
-
$1 + $2 + translate(locale, :"date.month_names")[object.mon]
|
60
|
-
end
|
61
|
-
format.gsub!(/%B/, translate(locale, :"date.standalone_month_names")[object.mon])
|
62
|
-
else
|
63
|
-
format.gsub!(/%B/, translate(locale, :"date.month_names")[object.mon])
|
64
|
-
end
|
65
|
-
|
66
|
-
format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}")) if object.respond_to? :hour
|
67
|
-
object.strftime(format)
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
# Picks a pluralization rule specified in translation tables for a language or
|
72
|
-
# uses default pluralization rules.
|
73
|
-
#
|
74
|
-
# This is how pluralization rules are defined in translation tables, English
|
75
|
-
# language for example:
|
76
|
-
#
|
77
|
-
# store_translations :'en', {
|
78
|
-
# :pluralize => lambda { |n| n == 1 ? :one : :other }
|
79
|
-
# }
|
80
|
-
#
|
81
|
-
# Rule must return a symbol to use with pluralization, it must be one of:
|
82
|
-
# :zero, :one, :two, :few, :many, :other
|
83
|
-
def pluralize(locale, entry, count)
|
84
|
-
return entry unless entry.is_a?(Hash) and count
|
85
|
-
|
86
|
-
key = :zero if count == 0 && entry.has_key?(:zero)
|
87
|
-
locale_pluralize = lookup(locale, :pluralize)
|
88
|
-
if locale_pluralize && locale_pluralize.respond_to?(:call)
|
89
|
-
key ||= locale_pluralize.call(count)
|
90
|
-
else
|
91
|
-
key ||= default_pluralizer(count)
|
92
|
-
end
|
93
|
-
raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
|
94
|
-
|
95
|
-
entry[key]
|
96
|
-
end
|
97
|
-
|
98
|
-
# Default pluralizer, used if pluralization rule is not defined in translations.
|
99
|
-
#
|
100
|
-
# Uses English pluralization rules -- it will pick the first translation if count is not equal to 1
|
101
|
-
# and the second translation if it is equal to 1.
|
102
|
-
def default_pluralizer(count)
|
103
|
-
count == 1 ? :one : :other
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
h1. Changelog
|
2
|
-
|
3
|
-
h2. master
|
4
|
-
|
5
|
-
* (no changes)
|
6
|
-
|
7
|
-
h2. 0.2.0 (2009-07-12)
|
8
|
-
|
9
|
-
* "Allow using Ruby 1.9 syntax for string interpolation (API addition)":http://github.com/svenfuchs/i18n/commit/c6e0b06d512f2af57199a843a1d8a40241b32861
|
10
|
-
* "Allow configuring the default scope separator, allow to pass a custom scope separator(API addition)":http://github.com/svenfuchs/i18n/commit/5b75bfbc348061adc11e3790187a187275bfd471 (e.g. I18n.t(:'foo|bar', :separator => '|')
|
11
|
-
* "Pass :format option to #translate for #localize more useful lambda support":http://github.com/svenfuchs/i18n/commit/e277711b3c844fe7589b8d3f9af0f7d1b969a273
|
12
|
-
* "Refactor Simple backend #resolve to #default and #resolve for more consistency. Now allows to pass lambdas as defaults and re-resolve Symbols":http://github.com/svenfuchs/i18n/commit/8c4ce3d923ce5fa73e973fe28217e18165549aba
|
13
|
-
* "Add lambda support to #translate (API addition)":http://github.com/svenfuchs/i18n/commit/c90e62d8f7d3d5b78f34cfe328d871b58884f115
|
14
|
-
* "Add lambda support to #localize (API addition)":http://github.com/svenfuchs/i18n/commit/9d390afcf33f3f469bb95e6888147152f6cc7442
|
15
|
-
|
16
|
-
h2. 0.1.3 (2009-02-27)
|
17
|
-
|
18
|
-
* "Remove unnecessary string encoding handling in the i18n simple backend which made the backend break on Ruby 1.9":http://github.com/svenfuchs/i18n/commit/4c3a970783861a94f2e89f46714fb3434e4f4f8d
|
19
|
-
|
20
|
-
h2. 0.1.2 (2009-01-09)
|
21
|
-
|
22
|
-
* "added #available_locales (returns an array of locales for which translations are available)":http://github.com/svenfuchs/i18n/commit/411f8fe7c8f3f89e9b6b921fa62ed66cb92f3af4
|
23
|
-
* "flatten load_path before using it so that a nested array of paths won't throw up":http://github.com/svenfuchs/i18n/commit/d473a068a2b90aba98135deb225d6eb6d8104d70
|
24
|
-
|
25
|
-
h2. 0.1.1 (2008-11-20)
|
26
|
-
|
27
|
-
* "Use :'en' as a default locale (in favor of :'en-US')":http://github.com/svenfuchs/i18n/commit/c4b10b246aecf7da78cb2568dd0d2ab7e6b8a230
|
28
|
-
* "Add #reload! to Simple backend":http://github.com/svenfuchs/i18n/commit/36dd2bd9973b9e1559728749a9daafa44693e964
|
29
|
-
|
30
|
-
h2. 0.1.0 (2008-10-25)
|
31
|
-
|
32
|
-
* "Fix Simple backend to distinguish false from nil values":http://github.com/svenfuchs/i18n/commit/39d9a47da14b5f3ba126af48923af8c30e135166
|
33
|
-
* "Add #load_path to public api, add initialize to simple backend and remove #load_translations from public api":http://github.com/svenfuchs/i18n/commit/c4c5649e6bc8f020f1aaf5a5470bde048e22c82d
|
34
|
-
* "Speed up Backend::Simple#interpolate":http://github.com/svenfuchs/i18n/commit/9e1ac6bf8833304e036323ec9932b9f33c468a35
|
35
|
-
* "Remove #populate and #store_translations from public API":http://github.com/svenfuchs/i18n/commit/f4e514a80be7feb509f66824ee311905e2940900
|
36
|
-
* "Use :other instead of :many as a plural key":http://github.com/svenfuchs/i18n/commit/0f8f20a2552bf6a2aa758d8fdd62a7154e4a1bf6
|
37
|
-
* "Use a class instead of a module for Simple backend":http://github.com/svenfuchs/i18n/commit/08f051aa61320c17debde24a83268bc74e33b995
|
38
|
-
* "Make Simple backend #interpolate deal with non-ASCII string encodings":http://github.com/svenfuchs/i18n/commit/d84a3f3f55543c084d5dc5d1fed613b8df148789
|
39
|
-
* "Fix default arrays of non-existant keys returning the default array":http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a4023644e5ba8b839
|
40
|
-
|
41
|
-
h2. Initial implementation (June/July 2008)
|
42
|
-
|
43
|
-
Initial implementation by "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs based on previous discussion/consensus of the rails-i18n team (alphabetical order) and many others:
|
44
|
-
|
45
|
-
* "Matt Aimonetti":http://railsontherun.com
|
46
|
-
* "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs
|
47
|
-
* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
|
48
|
-
* "Saimon Moore":http://saimonmoore.net
|
49
|
-
* "Stephan Soller":http://www.arkanis-development.de
|
50
|
-
|
51
|
-
h2. More information
|
52
|
-
|
53
|
-
* "Homepage":http://rails-i18n.org
|
54
|
-
* "Wiki":http://rails-i18n.org/wiki
|
55
|
-
* "Mailinglist":http://groups.google.com/group/rails-i18n
|
56
|
-
* "About the project/history":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
|
57
|
-
* "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api
|
data/lib/vendor/i18n/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 The Ruby I18n team
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,42 +0,0 @@
|
|
1
|
-
h1. Ruby I18n
|
2
|
-
|
3
|
-
Ruby Internationalization and localization solution.
|
4
|
-
|
5
|
-
Features:
|
6
|
-
|
7
|
-
* translation and localization
|
8
|
-
* interpolation of values to translations (Ruby 1.9 compatible syntax)
|
9
|
-
* pluralization (CLDR compatible)
|
10
|
-
* flexible defaults
|
11
|
-
* bulk lookup
|
12
|
-
* lambdas as translation data
|
13
|
-
* custom key/scope separator
|
14
|
-
* custom exception handlers
|
15
|
-
* extensible architecture with a swappable backend
|
16
|
-
|
17
|
-
Experimental, pluggable features:
|
18
|
-
|
19
|
-
* lambda pluralizers stored as translation data
|
20
|
-
* RFC4647 compliant locale fallbacks (with optional RFC4646 locale validation)
|
21
|
-
* backend cache
|
22
|
-
|
23
|
-
For more information and lots of resources see: "http://rails-i18n.org/wiki":http://rails-i18n.org/wiki
|
24
|
-
|
25
|
-
h2. Install
|
26
|
-
|
27
|
-
gem install i18n
|
28
|
-
|
29
|
-
h2. Authors
|
30
|
-
|
31
|
-
* "Sven Fuchs":http://www.artweb-design.de
|
32
|
-
* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
|
33
|
-
* "Stephan Soller":http://www.arkanis-development.de
|
34
|
-
* "Saimon Moore":http://saimonmoore.net
|
35
|
-
* "Matt Aimonetti":http://railsontherun.com
|
36
|
-
|
37
|
-
h2. License
|
38
|
-
|
39
|
-
MIT License. See the included MIT-LICENCE file.
|
40
|
-
|
41
|
-
|
42
|
-
|
data/lib/vendor/i18n/Rakefile
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
task :default => [:test]
|
2
|
-
|
3
|
-
task :test do
|
4
|
-
ruby "test/all.rb"
|
5
|
-
end
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'jeweler'
|
9
|
-
Jeweler::Tasks.new do |s|
|
10
|
-
s.name = "i18n"
|
11
|
-
s.rubyforge_project = "i18n"
|
12
|
-
s.summary = "New wave Internationalization support for Ruby"
|
13
|
-
s.email = "rails-i18n@googlegroups.com"
|
14
|
-
s.homepage = "http://rails-i18n.org"
|
15
|
-
s.description = "Add Internationalization support to your Ruby application."
|
16
|
-
s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
|
17
|
-
s.files = FileList["[A-Z]*", "{lib,test}/**/*"]
|
18
|
-
end
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
21
|
-
end
|
data/lib/vendor/i18n/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|
@@ -1,141 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{i18n}
|
5
|
-
s.version = "0.2.0"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Sven Fuchs", "Joshua Harvey", "Matt Aimonetti", "Stephan Soller", "Saimon Moore"]
|
9
|
-
s.date = %q{2009-08-19}
|
10
|
-
s.description = %q{Add Internationalization support to your Ruby application.}
|
11
|
-
s.email = %q{rails-i18n@googlegroups.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
"README.textile"
|
14
|
-
]
|
15
|
-
s.files = [
|
16
|
-
"CHANGELOG.textile",
|
17
|
-
"MIT-LICENSE",
|
18
|
-
"README.textile",
|
19
|
-
"Rakefile",
|
20
|
-
"VERSION",
|
21
|
-
"lib/i18n.rb",
|
22
|
-
"lib/i18n/backend/base.rb",
|
23
|
-
"lib/i18n/backend/cache.rb",
|
24
|
-
"lib/i18n/backend/chain.rb",
|
25
|
-
"lib/i18n/backend/fallbacks.rb",
|
26
|
-
"lib/i18n/backend/gettext.rb",
|
27
|
-
"lib/i18n/backend/helpers.rb",
|
28
|
-
"lib/i18n/backend/pluralization.rb",
|
29
|
-
"lib/i18n/backend/simple.rb",
|
30
|
-
"lib/i18n/core_ext/string/interpolate.rb",
|
31
|
-
"lib/i18n/exceptions.rb",
|
32
|
-
"lib/i18n/gettext.rb",
|
33
|
-
"lib/i18n/helpers/gettext.rb",
|
34
|
-
"lib/i18n/locale/fallbacks.rb",
|
35
|
-
"lib/i18n/locale/tag.rb",
|
36
|
-
"lib/i18n/locale/tag/parents.rb",
|
37
|
-
"lib/i18n/locale/tag/rfc4646.rb",
|
38
|
-
"lib/i18n/locale/tag/simple.rb",
|
39
|
-
"test/all.rb",
|
40
|
-
"test/api/basics.rb",
|
41
|
-
"test/api/interpolation.rb",
|
42
|
-
"test/api/lambda.rb",
|
43
|
-
"test/api/link.rb",
|
44
|
-
"test/api/localization/date.rb",
|
45
|
-
"test/api/localization/date_time.rb",
|
46
|
-
"test/api/localization/lambda.rb",
|
47
|
-
"test/api/localization/time.rb",
|
48
|
-
"test/api/pluralization.rb",
|
49
|
-
"test/api/translation.rb",
|
50
|
-
"test/backend/active_record/active_record_test.rb",
|
51
|
-
"test/backend/active_record/all.rb",
|
52
|
-
"test/backend/active_record/api_test.rb",
|
53
|
-
"test/backend/active_record/setup.rb",
|
54
|
-
"test/backend/cache/cache_test.rb",
|
55
|
-
"test/backend/chain/api_test.rb",
|
56
|
-
"test/backend/chain/chain_test.rb",
|
57
|
-
"test/backend/fallbacks/api_test.rb",
|
58
|
-
"test/backend/fallbacks/fallbacks_test.rb",
|
59
|
-
"test/backend/pluralization/api_test.rb",
|
60
|
-
"test/backend/pluralization/pluralization_test.rb",
|
61
|
-
"test/backend/simple/all.rb",
|
62
|
-
"test/backend/simple/api_test.rb",
|
63
|
-
"test/backend/simple/helpers_test.rb",
|
64
|
-
"test/backend/simple/lookup_test.rb",
|
65
|
-
"test/backend/simple/setup.rb",
|
66
|
-
"test/backend/simple/translations_test.rb",
|
67
|
-
"test/core_ext/string/interpolate_test.rb",
|
68
|
-
"test/fixtures/locales/de.po",
|
69
|
-
"test/fixtures/locales/en.rb",
|
70
|
-
"test/fixtures/locales/en.yml",
|
71
|
-
"test/fixtures/locales/plurals.rb",
|
72
|
-
"test/gettext/api_test.rb",
|
73
|
-
"test/gettext/backend_test.rb",
|
74
|
-
"test/i18n_exceptions_test.rb",
|
75
|
-
"test/i18n_load_path_test.rb",
|
76
|
-
"test/i18n_test.rb",
|
77
|
-
"test/locale/fallbacks_test.rb",
|
78
|
-
"test/locale/tag/rfc4646_test.rb",
|
79
|
-
"test/locale/tag/simple_test.rb",
|
80
|
-
"test/test_helper.rb",
|
81
|
-
"test/with_options.rb"
|
82
|
-
]
|
83
|
-
s.homepage = %q{http://rails-i18n.org}
|
84
|
-
s.require_paths = ["lib"]
|
85
|
-
s.rubyforge_project = %q{i18n}
|
86
|
-
s.rubygems_version = %q{1.3.5}
|
87
|
-
s.summary = %q{New wave Internationalization support for Ruby}
|
88
|
-
s.test_files = [
|
89
|
-
"test/all.rb",
|
90
|
-
"test/api/basics.rb",
|
91
|
-
"test/api/interpolation.rb",
|
92
|
-
"test/api/lambda.rb",
|
93
|
-
"test/api/link.rb",
|
94
|
-
"test/api/localization/date.rb",
|
95
|
-
"test/api/localization/date_time.rb",
|
96
|
-
"test/api/localization/lambda.rb",
|
97
|
-
"test/api/localization/time.rb",
|
98
|
-
"test/api/pluralization.rb",
|
99
|
-
"test/api/translation.rb",
|
100
|
-
"test/backend/active_record/active_record_test.rb",
|
101
|
-
"test/backend/active_record/all.rb",
|
102
|
-
"test/backend/active_record/api_test.rb",
|
103
|
-
"test/backend/active_record/setup.rb",
|
104
|
-
"test/backend/cache/cache_test.rb",
|
105
|
-
"test/backend/chain/api_test.rb",
|
106
|
-
"test/backend/chain/chain_test.rb",
|
107
|
-
"test/backend/fallbacks/api_test.rb",
|
108
|
-
"test/backend/fallbacks/fallbacks_test.rb",
|
109
|
-
"test/backend/pluralization/api_test.rb",
|
110
|
-
"test/backend/pluralization/pluralization_test.rb",
|
111
|
-
"test/backend/simple/all.rb",
|
112
|
-
"test/backend/simple/api_test.rb",
|
113
|
-
"test/backend/simple/helpers_test.rb",
|
114
|
-
"test/backend/simple/lookup_test.rb",
|
115
|
-
"test/backend/simple/setup.rb",
|
116
|
-
"test/backend/simple/translations_test.rb",
|
117
|
-
"test/core_ext/string/interpolate_test.rb",
|
118
|
-
"test/fixtures/locales/en.rb",
|
119
|
-
"test/fixtures/locales/plurals.rb",
|
120
|
-
"test/gettext/api_test.rb",
|
121
|
-
"test/gettext/backend_test.rb",
|
122
|
-
"test/i18n_exceptions_test.rb",
|
123
|
-
"test/i18n_load_path_test.rb",
|
124
|
-
"test/i18n_test.rb",
|
125
|
-
"test/locale/fallbacks_test.rb",
|
126
|
-
"test/locale/tag/rfc4646_test.rb",
|
127
|
-
"test/locale/tag/simple_test.rb",
|
128
|
-
"test/test_helper.rb",
|
129
|
-
"test/with_options.rb"
|
130
|
-
]
|
131
|
-
|
132
|
-
if s.respond_to? :specification_version then
|
133
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
134
|
-
s.specification_version = 3
|
135
|
-
|
136
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
137
|
-
else
|
138
|
-
end
|
139
|
-
else
|
140
|
-
end
|
141
|
-
end
|
data/lib/vendor/i18n/lib/i18n.rb
DELETED
@@ -1,270 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
# Authors:: Matt Aimonetti (http://railsontherun.com/),
|
4
|
-
# Sven Fuchs (http://www.artweb-design.de),
|
5
|
-
# Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
|
6
|
-
# Saimon Moore (http://saimonmoore.net),
|
7
|
-
# Stephan Soller (http://www.arkanis-development.de/)
|
8
|
-
# Copyright:: Copyright (c) 2008 The Ruby i18n Team
|
9
|
-
# License:: MIT
|
10
|
-
require 'i18n/backend/simple'
|
11
|
-
require 'i18n/exceptions'
|
12
|
-
require 'i18n/string'
|
13
|
-
|
14
|
-
module I18n
|
15
|
-
@@backend = nil
|
16
|
-
@@load_path = nil
|
17
|
-
@@default_locale = :en
|
18
|
-
@@default_separator = '.'
|
19
|
-
@@exception_handler = :default_exception_handler
|
20
|
-
|
21
|
-
class << self
|
22
|
-
# Returns the current backend. Defaults to +Backend::Simple+.
|
23
|
-
def backend
|
24
|
-
@@backend ||= Backend::Simple.new
|
25
|
-
end
|
26
|
-
|
27
|
-
# Sets the current backend. Used to set a custom backend.
|
28
|
-
def backend=(backend)
|
29
|
-
@@backend = backend
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns the current default locale. Defaults to :'en'
|
33
|
-
def default_locale
|
34
|
-
@@default_locale
|
35
|
-
end
|
36
|
-
|
37
|
-
# Sets the current default locale. Used to set a custom default locale.
|
38
|
-
def default_locale=(locale)
|
39
|
-
@@default_locale = locale.to_sym rescue nil
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns the current locale. Defaults to I18n.default_locale.
|
43
|
-
def locale
|
44
|
-
Thread.current[:locale] ||= default_locale
|
45
|
-
end
|
46
|
-
|
47
|
-
# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
|
48
|
-
def locale=(locale)
|
49
|
-
Thread.current[:locale] = locale.to_sym rescue nil
|
50
|
-
end
|
51
|
-
|
52
|
-
# Returns an array of locales for which translations are available.
|
53
|
-
# Unless you explicitely set the these through I18n.available_locales=
|
54
|
-
# the call will be delegated to the backend and memoized on the I18n module.
|
55
|
-
def available_locales
|
56
|
-
@@available_locales ||= backend.available_locales
|
57
|
-
end
|
58
|
-
|
59
|
-
# Sets the available locales.
|
60
|
-
def available_locales=(locales)
|
61
|
-
@@available_locales = locales
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns the current default scope separator. Defaults to '.'
|
65
|
-
def default_separator
|
66
|
-
@@default_separator
|
67
|
-
end
|
68
|
-
|
69
|
-
# Sets the current default scope separator.
|
70
|
-
def default_separator=(separator)
|
71
|
-
@@default_separator = separator
|
72
|
-
end
|
73
|
-
|
74
|
-
# Sets the exception handler.
|
75
|
-
def exception_handler=(exception_handler)
|
76
|
-
@@exception_handler = exception_handler
|
77
|
-
end
|
78
|
-
|
79
|
-
# Allow clients to register paths providing translation data sources. The
|
80
|
-
# backend defines acceptable sources.
|
81
|
-
#
|
82
|
-
# E.g. the provided SimpleBackend accepts a list of paths to translation
|
83
|
-
# files which are either named *.rb and contain plain Ruby Hashes or are
|
84
|
-
# named *.yml and contain YAML data. So for the SimpleBackend clients may
|
85
|
-
# register translation files like this:
|
86
|
-
# I18n.load_path << 'path/to/locale/en.yml'
|
87
|
-
def load_path
|
88
|
-
@@load_path ||= []
|
89
|
-
end
|
90
|
-
|
91
|
-
# Sets the load path instance. Custom implementations are expected to
|
92
|
-
# behave like a Ruby Array.
|
93
|
-
def load_path=(load_path)
|
94
|
-
@@load_path = load_path
|
95
|
-
end
|
96
|
-
|
97
|
-
# Tells the backend to reload translations. Used in situations like the
|
98
|
-
# Rails development environment. Backends can implement whatever strategy
|
99
|
-
# is useful.
|
100
|
-
def reload!
|
101
|
-
backend.reload!
|
102
|
-
end
|
103
|
-
|
104
|
-
# Translates, pluralizes and interpolates a given key using a given locale,
|
105
|
-
# scope, and default, as well as interpolation values.
|
106
|
-
#
|
107
|
-
# *LOOKUP*
|
108
|
-
#
|
109
|
-
# Translation data is organized as a nested hash using the upper-level keys
|
110
|
-
# as namespaces. <em>E.g.</em>, ActionView ships with the translation:
|
111
|
-
# <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
|
112
|
-
#
|
113
|
-
# Translations can be looked up at any level of this hash using the key argument
|
114
|
-
# and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
|
115
|
-
# returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
|
116
|
-
#
|
117
|
-
# Key can be either a single key or a dot-separated key (both Strings and Symbols
|
118
|
-
# work). <em>E.g.</em>, the short format can be looked up using both:
|
119
|
-
# I18n.t 'date.formats.short'
|
120
|
-
# I18n.t :'date.formats.short'
|
121
|
-
#
|
122
|
-
# Scope can be either a single key, a dot-separated key or an array of keys
|
123
|
-
# or dot-separated keys. Keys and scopes can be combined freely. So these
|
124
|
-
# examples will all look up the same short date format:
|
125
|
-
# I18n.t 'date.formats.short'
|
126
|
-
# I18n.t 'formats.short', :scope => 'date'
|
127
|
-
# I18n.t 'short', :scope => 'date.formats'
|
128
|
-
# I18n.t 'short', :scope => %w(date formats)
|
129
|
-
#
|
130
|
-
# *INTERPOLATION*
|
131
|
-
#
|
132
|
-
# Translations can contain interpolation variables which will be replaced by
|
133
|
-
# values passed to #translate as part of the options hash, with the keys matching
|
134
|
-
# the interpolation variable names.
|
135
|
-
#
|
136
|
-
# <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
|
137
|
-
# value for the key +bar+ will be interpolated into the translation:
|
138
|
-
# I18n.t :foo, :bar => 'baz' # => 'foo baz'
|
139
|
-
#
|
140
|
-
# *PLURALIZATION*
|
141
|
-
#
|
142
|
-
# Translation data can contain pluralized translations. Pluralized translations
|
143
|
-
# are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
|
144
|
-
#
|
145
|
-
# Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
|
146
|
-
# pluralization rules. Other algorithms can be supported by custom backends.
|
147
|
-
#
|
148
|
-
# This returns the singular version of a pluralized translation:
|
149
|
-
# I18n.t :foo, :count => 1 # => 'Foo'
|
150
|
-
#
|
151
|
-
# These both return the plural version of a pluralized translation:
|
152
|
-
# I18n.t :foo, :count => 0 # => 'Foos'
|
153
|
-
# I18n.t :foo, :count => 2 # => 'Foos'
|
154
|
-
#
|
155
|
-
# The <tt>:count</tt> option can be used both for pluralization and interpolation.
|
156
|
-
# <em>E.g.</em>, with the translation
|
157
|
-
# <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
|
158
|
-
# be interpolated to the pluralized translation:
|
159
|
-
# I18n.t :foo, :count => 1 # => '1 foo'
|
160
|
-
#
|
161
|
-
# *DEFAULTS*
|
162
|
-
#
|
163
|
-
# This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
|
164
|
-
# I18n.t :foo, :default => 'default'
|
165
|
-
#
|
166
|
-
# This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
|
167
|
-
# translation for <tt>:foo</tt> was found:
|
168
|
-
# I18n.t :foo, :default => :bar
|
169
|
-
#
|
170
|
-
# Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
|
171
|
-
# or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
|
172
|
-
# I18n.t :foo, :default => [:bar, 'default']
|
173
|
-
#
|
174
|
-
# *BULK LOOKUP*
|
175
|
-
#
|
176
|
-
# This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
|
177
|
-
# I18n.t [:foo, :bar]
|
178
|
-
#
|
179
|
-
# Can be used with dot-separated nested keys:
|
180
|
-
# I18n.t [:'baz.foo', :'baz.bar']
|
181
|
-
#
|
182
|
-
# Which is the same as using a scope option:
|
183
|
-
# I18n.t [:foo, :bar], :scope => :baz
|
184
|
-
#
|
185
|
-
# *LAMBDAS*
|
186
|
-
#
|
187
|
-
# Both translations and defaults can be given as Ruby lambdas. Lambdas will be
|
188
|
-
# called and passed the key and options.
|
189
|
-
#
|
190
|
-
# E.g. assuming the key <tt>:salutation</tt> resolves to:
|
191
|
-
# lambda { |key, options| options[:gender] == 'm' ? "Mr. {{options[:name]}}" : "Mrs. {{options[:name]}}" }
|
192
|
-
#
|
193
|
-
# Then <tt>I18n.t(:salutation, :gender => 'w', :name => 'Smith') will result in "Mrs. Smith".
|
194
|
-
#
|
195
|
-
# It is recommended to use/implement lambdas in an "idempotent" way. E.g. when
|
196
|
-
# a cache layer is put in front of I18n.translate it will generate a cache key
|
197
|
-
# from the argument values passed to #translate. Therefor your lambdas should
|
198
|
-
# always return the same translations/values per unique combination of argument
|
199
|
-
# values.
|
200
|
-
def translate(*args)
|
201
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
202
|
-
key = args.shift
|
203
|
-
locale = options.delete(:locale) || I18n.locale
|
204
|
-
backend.translate(locale, key, options)
|
205
|
-
rescue I18n::ArgumentError => exception
|
206
|
-
raise exception if options[:raise]
|
207
|
-
handle_exception(exception, locale, key, options)
|
208
|
-
end
|
209
|
-
alias :t :translate
|
210
|
-
|
211
|
-
def translate!(key, options = {})
|
212
|
-
translate(key, options.merge( :raise => true ))
|
213
|
-
end
|
214
|
-
alias :t! :translate!
|
215
|
-
|
216
|
-
# Localizes certain objects, such as dates and numbers to local formatting.
|
217
|
-
def localize(object, options = {})
|
218
|
-
locale = options[:locale] || I18n.locale
|
219
|
-
format = options[:format] || :default
|
220
|
-
backend.localize(locale, object, format)
|
221
|
-
end
|
222
|
-
alias :l :localize
|
223
|
-
|
224
|
-
protected
|
225
|
-
|
226
|
-
# Handles exceptions raised in the backend. All exceptions except for
|
227
|
-
# MissingTranslationData exceptions are re-raised. When a MissingTranslationData
|
228
|
-
# was caught and the option :raise is not set the handler returns an error
|
229
|
-
# message string containing the key/scope.
|
230
|
-
def default_exception_handler(exception, locale, key, options)
|
231
|
-
return exception.message if MissingTranslationData === exception
|
232
|
-
raise exception
|
233
|
-
end
|
234
|
-
|
235
|
-
# Any exceptions thrown in translate will be sent to the @@exception_handler
|
236
|
-
# which can be a Symbol, a Proc or any other Object.
|
237
|
-
#
|
238
|
-
# If exception_handler is a Symbol then it will simply be sent to I18n as
|
239
|
-
# a method call. A Proc will simply be called. In any other case the
|
240
|
-
# method #call will be called on the exception_handler object.
|
241
|
-
#
|
242
|
-
# Examples:
|
243
|
-
#
|
244
|
-
# I18n.exception_handler = :default_exception_handler # this is the default
|
245
|
-
# I18n.default_exception_handler(exception, locale, key, options) # will be called like this
|
246
|
-
#
|
247
|
-
# I18n.exception_handler = lambda { |*args| ... } # a lambda
|
248
|
-
# I18n.exception_handler.call(exception, locale, key, options) # will be called like this
|
249
|
-
#
|
250
|
-
# I18n.exception_handler = I18nExceptionHandler.new # an object
|
251
|
-
# I18n.exception_handler.call(exception, locale, key, options) # will be called like this
|
252
|
-
def handle_exception(exception, locale, key, options)
|
253
|
-
case @@exception_handler
|
254
|
-
when Symbol
|
255
|
-
send(@@exception_handler, exception, locale, key, options)
|
256
|
-
else
|
257
|
-
@@exception_handler.call(exception, locale, key, options)
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
# Merges the given locale, key and scope into a single array of keys.
|
262
|
-
# Splits keys that contain dots into multiple keys. Makes sure all
|
263
|
-
# keys are Symbols.
|
264
|
-
def normalize_translation_keys(locale, key, scope, separator = nil)
|
265
|
-
keys = [locale] + Array(scope) + Array(key)
|
266
|
-
keys = keys.map { |k| k.to_s.split(separator || I18n.default_separator) }
|
267
|
-
keys.flatten.map { |k| k.to_sym }
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|