diff options
| author | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
|---|---|---|
| committer | hukl <hukl@eight.local> | 2009-02-07 15:50:40 +0100 |
| commit | 36a2f1f3c085dd81171cf7d8220770d4ff921ab3 (patch) | |
| tree | 5ded15331b192bf428af4c94d46d1abb28ef0690 /vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb | |
| parent | ce9645d0092d42c7bf8781378181ffbd4ff3d088 (diff) | |
added globalize2 plugin as well as some modifications
which use the new translation facilities.
backend mostly.
Diffstat (limited to 'vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb')
| -rw-r--r-- | vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb b/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb new file mode 100644 index 00000000..80016f20 --- /dev/null +++ b/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | require 'i18n/backend/simple' | ||
| 2 | |||
| 3 | module Globalize | ||
| 4 | module Backend | ||
| 5 | class Pluralizing < I18n::Backend::Simple | ||
| 6 | def pluralize(locale, entry, count) | ||
| 7 | return entry unless entry.is_a?(Hash) and count | ||
| 8 | key = :zero if count == 0 && entry.has_key?(:zero) | ||
| 9 | key ||= pluralizer(locale).call(count) | ||
| 10 | raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key) | ||
| 11 | translation entry[key], :plural_key => key | ||
| 12 | end | ||
| 13 | |||
| 14 | def add_pluralizer(locale, pluralizer) | ||
| 15 | pluralizers[locale.to_sym] = pluralizer | ||
| 16 | end | ||
| 17 | |||
| 18 | def pluralizer(locale) | ||
| 19 | pluralizers[locale.to_sym] || default_pluralizer | ||
| 20 | end | ||
| 21 | |||
| 22 | protected | ||
| 23 | def default_pluralizer | ||
| 24 | pluralizers[:en] | ||
| 25 | end | ||
| 26 | |||
| 27 | def pluralizers | ||
| 28 | @pluralizers ||= { :en => lambda{|n| n == 1 ? :one : :other } } | ||
| 29 | end | ||
| 30 | |||
| 31 | # Overwrite this method to return something other than a String | ||
| 32 | def translation(string, attributes) | ||
| 33 | string | ||
| 34 | end | ||
| 35 | end | ||
| 36 | end | ||
| 37 | end \ No newline at end of file | ||
