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
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Grzegorz Kolodziejczyk
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Polish
|
2
|
+
======
|
3
|
+
Polish language support for Ruby on Rails.
|
4
|
+
|
5
|
+
Based on [Russian](http://github.com/yaroslav/russian/) by [yaroslav](http://github.com/yaroslav/).
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
Install as a gem
|
10
|
+
`
|
11
|
+
Rails::Initializer.run do |config|
|
12
|
+
config.gem 'polish', :source => 'http://gemcutter.org'
|
13
|
+
end
|
14
|
+
`
|
15
|
+
or a plugin
|
16
|
+
`
|
17
|
+
script/plugin install git://github.com/grk/polish.git
|
18
|
+
`
|
19
|
+
|
20
|
+
Then, magic happens. No need to set default locale.
|
21
|
+
|
22
|
+
|
23
|
+
Overrides
|
24
|
+
---------
|
25
|
+
Translations and date formats can be overridden in `config/locales/pl.yml`
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
require 'rubygems/specification'
|
5
|
+
require 'date'
|
6
|
+
require 'I18n'
|
7
|
+
|
8
|
+
GEM = "polish"
|
9
|
+
GEM_VERSION = "0.0.1"
|
10
|
+
AUTHOR = "Grzesiek Kolodziejczyk"
|
11
|
+
EMAIL = "gkolodziejczyk@gmail.com"
|
12
|
+
HOMEPAGE = "http://github.com/grk/polish/"
|
13
|
+
SUMMARY = "Polish language support for Ruby and Rails"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = GEM
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README.md", "LICENSE", "TODO"]
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
|
27
|
+
# Uncomment this to add a dependency
|
28
|
+
# s.add_dependency "foo"
|
29
|
+
|
30
|
+
s.require_path = 'lib'
|
31
|
+
s.autorequire = GEM
|
32
|
+
s.files = %w(LICENSE README.md Rakefile TODO init.rb) + Dir.glob("{lib,spec}/**/*")
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
36
|
+
pkg.gem_spec = spec
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
desc "Run specs"
|
41
|
+
Spec::Rake::SpecTask.new do |t|
|
42
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
43
|
+
t.spec_opts = %w(-fs --color)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "install the gem locally"
|
47
|
+
task :install => [:package] do
|
48
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "create a gemspec file"
|
52
|
+
task :make_spec do
|
53
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
54
|
+
file.puts spec.to_ruby
|
55
|
+
end
|
56
|
+
end
|
data/TODO
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'polish'
|
data/lib/polish.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
if RUBY_VERSION < "1.9"
|
4
|
+
$KCODE = 'u'
|
5
|
+
end
|
6
|
+
|
7
|
+
$:.push File.join(File.dirname(__FILE__), 'polish')
|
8
|
+
|
9
|
+
# I18n require
|
10
|
+
unless defined?(I18n)
|
11
|
+
$:.push File.join(File.dirname(__FILE__), 'vendor', 'i18n', 'lib')
|
12
|
+
require 'i18n'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Advanced backend
|
17
|
+
require 'backend/advanced'
|
18
|
+
|
19
|
+
# Rails hacks
|
20
|
+
if defined?(ActionView::Helpers)
|
21
|
+
require 'action_view_ext/helpers/date_helper'
|
22
|
+
end
|
23
|
+
|
24
|
+
module Polish
|
25
|
+
extend self
|
26
|
+
|
27
|
+
module VERSION
|
28
|
+
MAJOR = 0
|
29
|
+
MINOR = 0
|
30
|
+
TINY = 1
|
31
|
+
|
32
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
33
|
+
end
|
34
|
+
|
35
|
+
# Polish locale
|
36
|
+
LOCALE = :'pl'
|
37
|
+
|
38
|
+
# Polish locale
|
39
|
+
def locale
|
40
|
+
LOCALE
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns custom backend class for usage with Polish library
|
44
|
+
#
|
45
|
+
# See I18n::Backend
|
46
|
+
def i18n_backend_class
|
47
|
+
I18n::Backend::Advanced
|
48
|
+
end
|
49
|
+
|
50
|
+
# Init Polish i18n: set custom backend, set default locale to Polish locale,
|
51
|
+
# load all translations shipped with library.
|
52
|
+
def init_i18n
|
53
|
+
I18n.backend = Polish.i18n_backend_class.new
|
54
|
+
I18n.default_locale = LOCALE
|
55
|
+
I18n.load_path.unshift(*locale_files)
|
56
|
+
end
|
57
|
+
|
58
|
+
# See I18n::translate
|
59
|
+
def translate(key, options = {})
|
60
|
+
I18n.translate(key, options.merge({ :locale => LOCALE }))
|
61
|
+
end
|
62
|
+
alias :t :translate
|
63
|
+
|
64
|
+
# See I18n::localize
|
65
|
+
def localize(object, options = {})
|
66
|
+
I18n.localize(object, options.merge({ :locale => LOCALE }))
|
67
|
+
end
|
68
|
+
alias :l :localize
|
69
|
+
|
70
|
+
# strftime() proxy with Polish localization
|
71
|
+
def strftime(object, format = :default)
|
72
|
+
localize(object, { :format => format })
|
73
|
+
end
|
74
|
+
|
75
|
+
# Simple pluralization proxy
|
76
|
+
#
|
77
|
+
# Usage:
|
78
|
+
# Polish.pluralize(1, "dom", "domy", "domów")
|
79
|
+
def pluralize(n, *variants)
|
80
|
+
raise ArgumentError, "Must have a Numeric as a first parameter" unless n.is_a?(Numeric)
|
81
|
+
raise ArgumentError, "Must have 3 variants for pluralization" if variants.size < 3
|
82
|
+
variants_hash = pluralization_variants_to_hash(*variants)
|
83
|
+
I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
|
84
|
+
end
|
85
|
+
alias :p :pluralize
|
86
|
+
|
87
|
+
protected
|
88
|
+
# Returns all locale files shipped with library
|
89
|
+
def locale_files
|
90
|
+
Dir[File.join(File.dirname(__FILE__), "polish", "locale", "**/*")]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Converts an array of pluralization variants to a Hash that can be used
|
94
|
+
# with I18n pluralization.
|
95
|
+
def pluralization_variants_to_hash(*variants)
|
96
|
+
{
|
97
|
+
:one => variants[0],
|
98
|
+
:few => variants[1],
|
99
|
+
:other => variants[2]
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
Polish.init_i18n
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Replaces Rails <tt>select_month</tt> helper and <tt>translated_month_names</tt> private method to provide
|
4
|
+
# "standalone month names" feature.
|
5
|
+
#
|
6
|
+
# It is now possible to use both abbreviated and full month names in two variants (if current locale provides them).
|
7
|
+
# All date helpers support <tt>:use_standalone_month_names</tt> key now, <tt>select_month</tt> helper sets
|
8
|
+
# it to true by default.
|
9
|
+
# Standalone month names are also used when <tt>:discard_day</tt> key is provided.
|
10
|
+
if defined?(ActionView::Helpers::DateTimeSelector) && ActionView::Helpers::DateTimeSelector.private_instance_methods.include?("translated_month_names")
|
11
|
+
module ActionView
|
12
|
+
module Helpers
|
13
|
+
module DateHelper
|
14
|
+
# Returns a select tag with options for each of the months January through December with the current month
|
15
|
+
# selected. The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are
|
16
|
+
# used as values (what's submitted to the server). It's also possible to use month numbers for the presentation
|
17
|
+
# instead of names -- set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you
|
18
|
+
# want both numbers and names, set the <tt>:add_month_numbers</tt> key in +options+ to true. If you would prefer
|
19
|
+
# to show month names as abbreviations, set the <tt>:use_short_month</tt> key in +options+ to true. If you want
|
20
|
+
# to use your own month names, set the <tt>:use_month_names</tt> key in +options+ to an array of 12 month names.
|
21
|
+
# You can also choose if you want to use i18n standalone month names or default month names -- you can
|
22
|
+
# force standalone month names usage by using <tt>:use_standalone_month_names</tt> key.
|
23
|
+
# Override the field name using the <tt>:field_name</tt> option, 'month' by default.
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# ==== Examples
|
27
|
+
# # Generates a select field for months that defaults to the current month that
|
28
|
+
# # will use keys like "January", "March".
|
29
|
+
# select_month(Date.today)
|
30
|
+
#
|
31
|
+
# # Generates a select field for months that defaults to the current month that
|
32
|
+
# # is named "start" rather than "month"
|
33
|
+
# select_month(Date.today, :field_name => 'start')
|
34
|
+
#
|
35
|
+
# # Generates a select field for months that defaults to the current month that
|
36
|
+
# # will use keys like "1", "3".
|
37
|
+
# select_month(Date.today, :use_month_numbers => true)
|
38
|
+
#
|
39
|
+
# # Generates a select field for months that defaults to the current month that
|
40
|
+
# # will use keys like "1 - January", "3 - March".
|
41
|
+
# select_month(Date.today, :add_month_numbers => true)
|
42
|
+
#
|
43
|
+
# # Generates a select field for months that defaults to the current month that
|
44
|
+
# # will use keys like "Jan", "Mar".
|
45
|
+
# select_month(Date.today, :use_short_month => true)
|
46
|
+
#
|
47
|
+
# # Generates a select field for months that defaults to the current month that
|
48
|
+
# # will use keys like "Januar", "Marts."
|
49
|
+
# select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...))
|
50
|
+
#
|
51
|
+
def select_month(date, options = {}, html_options = {})
|
52
|
+
DateTimeSelector.new(date, options.merge(:use_standalone_month_names => true), html_options).select_month
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class DateTimeSelector #:nodoc:
|
57
|
+
private
|
58
|
+
# Returns translated month names
|
59
|
+
# => [nil, "January", "February", "March",
|
60
|
+
# "April", "May", "June", "July",
|
61
|
+
# "August", "September", "October",
|
62
|
+
# "November", "December"]
|
63
|
+
#
|
64
|
+
# If :use_short_month option is set
|
65
|
+
# => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
66
|
+
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
67
|
+
#
|
68
|
+
# Also looks up if <tt>:discard_day</tt> or <tt>:use_standalone_month_names</tt> option is set
|
69
|
+
# and uses i18n standalone month names if so.
|
70
|
+
#
|
71
|
+
def translated_month_names
|
72
|
+
begin
|
73
|
+
if @options[:use_short_month]
|
74
|
+
if (@options[:discard_day] || @options[:use_standalone_month_names]) && I18n.translate(:'date.standalone_abbr_month_names')
|
75
|
+
key = :'date.standalone_abbr_month_names'
|
76
|
+
else
|
77
|
+
key = :'date.abbr_month_names'
|
78
|
+
end
|
79
|
+
else
|
80
|
+
if (@options[:discard_day] || @options[:use_standalone_month_names]) && I18n.translate(:'date.standalone_month_names')
|
81
|
+
key = :'date.standalone_month_names'
|
82
|
+
else
|
83
|
+
key = :'date.month_names'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
I18n.translate(key, :locale => @options[:locale])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end # if defined?
|
@@ -0,0 +1,105 @@
|
|
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\.?)?(\s*)(%b)/
|
12
|
+
LOCALIZE_MONTH_NAMES_MATCH = /(%d\.?|%e\.?)?(\s*)(%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
|
+
def localize(locale, object, format = :default)
|
23
|
+
raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime)
|
24
|
+
type = object.respond_to?(:sec) ? 'time' : 'date'
|
25
|
+
# TODO only translate these if format is a String?
|
26
|
+
formats = translate(locale, :"#{type}.formats")
|
27
|
+
format = formats[format.to_sym] if formats && formats[format.to_sym]
|
28
|
+
# TODO raise exception unless format found?
|
29
|
+
format = format.to_s.dup
|
30
|
+
|
31
|
+
# TODO only translate these if the format string is actually present
|
32
|
+
# TODO check which format strings are present, then bulk translate then, then replace them
|
33
|
+
|
34
|
+
if lookup(locale, :"date.standalone_abbr_day_names")
|
35
|
+
format.gsub!(LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH,
|
36
|
+
translate(locale, :"date.standalone_abbr_day_names")[object.wday])
|
37
|
+
end
|
38
|
+
format.gsub!(/%a/, translate(locale, :"date.abbr_day_names")[object.wday])
|
39
|
+
|
40
|
+
if lookup(locale, :"date.standalone_day_names")
|
41
|
+
format.gsub!(LOCALIZE_STANDALONE_DAY_NAMES_MATCH,
|
42
|
+
translate(locale, :"date.standalone_day_names")[object.wday])
|
43
|
+
end
|
44
|
+
format.gsub!(/%A/, translate(locale, :"date.day_names")[object.wday])
|
45
|
+
|
46
|
+
if lookup(locale, :"date.standalone_abbr_month_names")
|
47
|
+
format.gsub!(LOCALIZE_ABBR_MONTH_NAMES_MATCH) do
|
48
|
+
$1 ? $1 + $2 + translate(locale, :"date.abbr_month_names")[object.mon] :
|
49
|
+
$2 + translate(locale, :"date.standalone_abbr_month_names")[object.mon]
|
50
|
+
end
|
51
|
+
else
|
52
|
+
format.gsub!(/%b/, translate(locale, :"date.abbr_month_names")[object.mon])
|
53
|
+
end
|
54
|
+
|
55
|
+
if lookup(locale, :"date.standalone_month_names")
|
56
|
+
format.gsub!(LOCALIZE_MONTH_NAMES_MATCH) do
|
57
|
+
$1 ? $1 + $2 + translate(locale, :"date.month_names")[object.mon] :
|
58
|
+
$2 + translate(locale, :"date.standalone_month_names")[object.mon]
|
59
|
+
end
|
60
|
+
else
|
61
|
+
format.gsub!(/%B/, translate(locale, :"date.month_names")[object.mon])
|
62
|
+
end
|
63
|
+
|
64
|
+
format.gsub!(/%p/, translate(locale, :"time.#{object.hour < 12 ? :am : :pm}")) if object.respond_to? :hour
|
65
|
+
object.strftime(format)
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
# Picks a pluralization rule specified in translation tables for a language or
|
70
|
+
# uses default pluralization rules.
|
71
|
+
#
|
72
|
+
# This is how pluralization rules are defined in translation tables, English
|
73
|
+
# language for example:
|
74
|
+
#
|
75
|
+
# store_translations :'en', {
|
76
|
+
# :pluralize => lambda { |n| n == 1 ? :one : :other }
|
77
|
+
# }
|
78
|
+
#
|
79
|
+
# Rule must return a symbol to use with pluralization, it must be one of:
|
80
|
+
# :zero, :one, :two, :few, :many, :other
|
81
|
+
def pluralize(locale, entry, count)
|
82
|
+
return entry unless entry.is_a?(Hash) and count
|
83
|
+
|
84
|
+
key = :zero if count == 0 && entry.has_key?(:zero)
|
85
|
+
locale_pluralize = lookup(locale, :pluralize)
|
86
|
+
if locale_pluralize && locale_pluralize.respond_to?(:call)
|
87
|
+
key ||= locale_pluralize.call(count)
|
88
|
+
else
|
89
|
+
key ||= default_pluralizer(count)
|
90
|
+
end
|
91
|
+
raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
|
92
|
+
|
93
|
+
entry[key]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Default pluralizer, used if pluralization rule is not defined in translations.
|
97
|
+
#
|
98
|
+
# Uses English pluralization rules -- it will pick the first translation if count is not equal to 1
|
99
|
+
# and the second translation if it is equal to 1.
|
100
|
+
def default_pluralizer(count)
|
101
|
+
count == 1 ? :one : :other
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Polish translations for Ruby on Rails
|
2
|
+
# by Jacek Becela (jacek.becela@gmail.com, http://github.com/ncr)
|
3
|
+
|
4
|
+
pl:
|
5
|
+
number:
|
6
|
+
format:
|
7
|
+
separator: ","
|
8
|
+
delimiter: " "
|
9
|
+
precision: 2
|
10
|
+
currency:
|
11
|
+
format:
|
12
|
+
format: "%n %u"
|
13
|
+
unit: "PLN"
|
14
|
+
percentage:
|
15
|
+
format:
|
16
|
+
delimiter: ""
|
17
|
+
precision:
|
18
|
+
format:
|
19
|
+
delimiter: ""
|
20
|
+
human:
|
21
|
+
format:
|
22
|
+
delimiter: ""
|
23
|
+
precision: 1
|
24
|
+
storage_units:
|
25
|
+
format: "%n %u"
|
26
|
+
units:
|
27
|
+
byte:
|
28
|
+
one: "bajt"
|
29
|
+
other: "bajty"
|
30
|
+
kb: "KB"
|
31
|
+
mb: "MB"
|
32
|
+
gb: "GB"
|
33
|
+
tb: "TB"
|
34
|
+
|
35
|
+
datetime:
|
36
|
+
distance_in_words:
|
37
|
+
half_a_minute: "pół minuty"
|
38
|
+
less_than_x_seconds:
|
39
|
+
one: "mniej niż sekundę"
|
40
|
+
few: "mniej niż {{count}} sekundy"
|
41
|
+
other: "mniej niż {{count}} sekund"
|
42
|
+
x_seconds:
|
43
|
+
one: "sekundę"
|
44
|
+
few: "{{count}} sekundy"
|
45
|
+
other: "{{count}} sekund"
|
46
|
+
less_than_x_minutes:
|
47
|
+
one: "mniej niż minutę"
|
48
|
+
few: "mniej niż {{count}} minuty"
|
49
|
+
other: "mniej niż {{count}} minut"
|
50
|
+
x_minutes:
|
51
|
+
one: "minutę"
|
52
|
+
few: "{{count}} minuty"
|
53
|
+
other: "{{count}} minut"
|
54
|
+
about_x_hours:
|
55
|
+
one: "około godziny"
|
56
|
+
other: "about {{count}} godzin"
|
57
|
+
x_days:
|
58
|
+
one: "1 dzień"
|
59
|
+
other: "{{count}} dni"
|
60
|
+
about_x_months:
|
61
|
+
one: "około miesiąca"
|
62
|
+
other: "około {{count}} miesięcy"
|
63
|
+
x_months:
|
64
|
+
one: "1 miesiąc"
|
65
|
+
few: "{{count}} miesiące"
|
66
|
+
other: "{{count}} miesięcy"
|
67
|
+
about_x_years:
|
68
|
+
one: "około roku"
|
69
|
+
other: "około {{count}} lat"
|
70
|
+
over_x_years:
|
71
|
+
one: "ponad rok"
|
72
|
+
few: "ponad {{count}} lata"
|
73
|
+
other: "ponad {{count}} lat"
|
74
|
+
|
75
|
+
activerecord:
|
76
|
+
errors:
|
77
|
+
template:
|
78
|
+
header:
|
79
|
+
one: "{{model}} nie został zachowany z powodu jednego błędu"
|
80
|
+
other: "{{model}} nie został zachowany z powodu {{count}} błędów"
|
81
|
+
body: "Błędy dotyczą następujących pól:"
|