polish 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +25 -0
- data/Rakefile +56 -0
- data/TODO +5 -0
- data/init.rb +1 -0
- data/lib/polish.rb +104 -0
- data/lib/polish/action_view_ext/helpers/date_helper.rb +94 -0
- data/lib/polish/backend/advanced.rb +105 -0
- data/lib/polish/locale/actionview.yml +81 -0
- data/lib/polish/locale/activerecord.yml +27 -0
- data/lib/polish/locale/activesupport.yml +11 -0
- data/lib/polish/locale/datetime.yml +25 -0
- data/lib/polish/locale/pluralize.rb +16 -0
- data/lib/vendor/i18n/CHANGELOG.textile +57 -0
- data/lib/vendor/i18n/MIT-LICENSE +20 -0
- data/lib/vendor/i18n/README.textile +42 -0
- data/lib/vendor/i18n/Rakefile +21 -0
- data/lib/vendor/i18n/VERSION +1 -0
- data/lib/vendor/i18n/i18n.gemspec +141 -0
- data/lib/vendor/i18n/lib/i18n.rb +270 -0
- data/lib/vendor/i18n/lib/i18n/backend/base.rb +251 -0
- data/lib/vendor/i18n/lib/i18n/backend/cache.rb +71 -0
- data/lib/vendor/i18n/lib/i18n/backend/chain.rb +64 -0
- data/lib/vendor/i18n/lib/i18n/backend/fallbacks.rb +53 -0
- data/lib/vendor/i18n/lib/i18n/backend/gettext.rb +65 -0
- data/lib/vendor/i18n/lib/i18n/backend/pluralization.rb +56 -0
- data/lib/vendor/i18n/lib/i18n/backend/simple.rb +23 -0
- data/lib/vendor/i18n/lib/i18n/exceptions.rb +61 -0
- data/lib/vendor/i18n/lib/i18n/gettext.rb +25 -0
- data/lib/vendor/i18n/lib/i18n/helpers/gettext.rb +35 -0
- data/lib/vendor/i18n/lib/i18n/locale/fallbacks.rb +100 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag.rb +27 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/rfc4646.rb +78 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/simple.rb +44 -0
- data/lib/vendor/i18n/lib/i18n/string.rb +95 -0
- data/lib/vendor/i18n/test/all.rb +5 -0
- data/lib/vendor/i18n/test/api/basics.rb +15 -0
- data/lib/vendor/i18n/test/api/interpolation.rb +85 -0
- data/lib/vendor/i18n/test/api/lambda.rb +52 -0
- data/lib/vendor/i18n/test/api/link.rb +47 -0
- data/lib/vendor/i18n/test/api/localization/date.rb +65 -0
- data/lib/vendor/i18n/test/api/localization/date_time.rb +63 -0
- data/lib/vendor/i18n/test/api/localization/lambda.rb +26 -0
- data/lib/vendor/i18n/test/api/localization/time.rb +63 -0
- data/lib/vendor/i18n/test/api/pluralization.rb +37 -0
- data/lib/vendor/i18n/test/api/translation.rb +51 -0
- data/lib/vendor/i18n/test/backend/cache/cache_test.rb +57 -0
- data/lib/vendor/i18n/test/backend/chain/api_test.rb +80 -0
- data/lib/vendor/i18n/test/backend/chain/chain_test.rb +64 -0
- data/lib/vendor/i18n/test/backend/fallbacks/api_test.rb +79 -0
- data/lib/vendor/i18n/test/backend/fallbacks/fallbacks_test.rb +29 -0
- data/lib/vendor/i18n/test/backend/pluralization/api_test.rb +81 -0
- data/lib/vendor/i18n/test/backend/pluralization/pluralization_test.rb +39 -0
- data/lib/vendor/i18n/test/backend/simple/all.rb +5 -0
- data/lib/vendor/i18n/test/backend/simple/api_test.rb +90 -0
- data/lib/vendor/i18n/test/backend/simple/lookup_test.rb +24 -0
- data/lib/vendor/i18n/test/backend/simple/setup.rb +147 -0
- data/lib/vendor/i18n/test/backend/simple/translations_test.rb +89 -0
- data/lib/vendor/i18n/test/fixtures/locales/de.po +61 -0
- data/lib/vendor/i18n/test/fixtures/locales/en.rb +3 -0
- data/lib/vendor/i18n/test/fixtures/locales/en.yml +3 -0
- data/lib/vendor/i18n/test/fixtures/locales/plurals.rb +112 -0
- data/lib/vendor/i18n/test/gettext/api_test.rb +78 -0
- data/lib/vendor/i18n/test/gettext/backend_test.rb +35 -0
- data/lib/vendor/i18n/test/i18n_exceptions_test.rb +97 -0
- data/lib/vendor/i18n/test/i18n_load_path_test.rb +23 -0
- data/lib/vendor/i18n/test/i18n_test.rb +163 -0
- data/lib/vendor/i18n/test/locale/fallbacks_test.rb +128 -0
- data/lib/vendor/i18n/test/locale/tag/rfc4646_test.rb +147 -0
- data/lib/vendor/i18n/test/locale/tag/simple_test.rb +35 -0
- data/lib/vendor/i18n/test/string_test.rb +94 -0
- data/lib/vendor/i18n/test/test_helper.rb +71 -0
- data/lib/vendor/i18n/test/with_options.rb +34 -0
- data/lib/vendor/i18n/vendor/po_parser.rb +329 -0
- data/spec/fixtures/en.yml +4 -0
- data/spec/fixtures/pl.yml +4 -0
- data/spec/i18n/locale/datetime_spec.rb +91 -0
- data/spec/i18n/locale/pluralization_spec.rb +41 -0
- data/spec/locale_spec.rb +124 -0
- data/spec/polish_spec.rb +141 -0
- data/spec/spec_helper.rb +4 -0
- metadata +138 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
pl:
|
2
|
+
messages:
|
3
|
+
inclusion: "nie znajduje się na liście dopuszczalnych wartości"
|
4
|
+
exclusion: "znajduje się na liście zabronionych wartości"
|
5
|
+
invalid: "jest nieprawidłowe"
|
6
|
+
confirmation: "nie zgadza się z potwierdzeniem"
|
7
|
+
accepted: "musi być zaakceptowane"
|
8
|
+
empty: "nie może być puste"
|
9
|
+
blank: "nie może być puste"
|
10
|
+
too_long:
|
11
|
+
one: "jest za długie (maksymalnie {{count}} znak)"
|
12
|
+
few: "jest za długie (maksymalnie {{count}} znaki)"
|
13
|
+
many: "jest za długie (maksymalnie {{count}} znaków)"
|
14
|
+
too_short:
|
15
|
+
one: "jest za krótkie (minimalnie {{count}} znak)"
|
16
|
+
few: "jest za krótkie (minimalnie {{count}} znaki)"
|
17
|
+
many: "jest za krótkie (minimalnie {{count}} znaków)"
|
18
|
+
wrong_length: "jest nieprawidłowej długości (powinna wynosić {{count}} znaków)"
|
19
|
+
taken: "zostało już zajęte"
|
20
|
+
not_a_number: "nie jest liczbą"
|
21
|
+
greater_than: "musi być większe niż {{count}}"
|
22
|
+
greater_than_or_equal_to: "musi być większe lub równe {{count}}"
|
23
|
+
equal_to: "musi być równe {{count}}"
|
24
|
+
less_than: "musie być mniejsze niż {{count}}"
|
25
|
+
less_than_or_equal_to: "musi być mniejsze lub równe {{count}}"
|
26
|
+
odd: "musi być nieparzyste"
|
27
|
+
even: "musi być parzyste"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
pl:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%d.%m.%Y"
|
5
|
+
short: "%d. %b"
|
6
|
+
long: "%d. %B %Y"
|
7
|
+
|
8
|
+
day_names: [niedziela, poniedziałek, wtorek, środa, czwartek, piątek, sobota]
|
9
|
+
standalone_day_names: [Niedziela, Poniedziałek, Wtorek, Środa, Czwartek, Piątek, Sobota]
|
10
|
+
abbr_day_names: [nie., pon., wto., śro., czw., pią., sob.]
|
11
|
+
standalone_abbr_day_names: [Nie., Pon., Wto., Śro., Czw., Pią., Sob.]
|
12
|
+
|
13
|
+
month_names: [~, stycznia, lutego, marca, kwietnia, maja, czerwca, lipca, sierpnia, września, października, listpoada, grudnia]
|
14
|
+
standalone_month_names: [~, Styczeń, Luty, Marzec, Kwiecień, Maj, Czerwiec, Lipiec, Sierpień, Wrzesień, Październik, Listopad, Grudzień]
|
15
|
+
abbr_month_names: [~, sty., lut., mar., kwi., maj., cze., lip., sie., wrz., paź., lis., gru.]
|
16
|
+
standalone_abbr_month_names: [~, Sty., Lut., Mar., Kwi., Maj., Cze., Lip., Sie., Wrz., Paź., Lis., Gru.]
|
17
|
+
order: [ :year, :month, :day ]
|
18
|
+
|
19
|
+
time:
|
20
|
+
formats:
|
21
|
+
default: "%a, %d. %B %Y, %H:%M:%S"
|
22
|
+
short: "%d. %b, %H:%M"
|
23
|
+
long: "%d. %B %Y, %H:%M"
|
24
|
+
am: "przed południem"
|
25
|
+
pm: "po południu"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
{
|
4
|
+
:'pl' => {
|
5
|
+
:pluralize => lambda { |n|
|
6
|
+
# taken from http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
|
7
|
+
# TODO: check if they're really wrong about 22..24
|
8
|
+
#
|
9
|
+
# one -> n is 1;
|
10
|
+
# few -> n mod 10 in 2..4 and n mod 100 not in 12..14;
|
11
|
+
# other -> everything else
|
12
|
+
#
|
13
|
+
n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,57 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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.
|
@@ -0,0 +1,42 @@
|
|
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
|
+
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,141 @@
|
|
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
|
@@ -0,0 +1,270 @@
|
|
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
|