From 36a2f1f3c085dd81171cf7d8220770d4ff921ab3 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 7 Feb 2009 15:50:40 +0100 Subject: added globalize2 plugin as well as some modifications which use the new translation facilities. backend mostly. --- .../lib/globalize/backend/pluralizing.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb (limited to 'vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb') 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 @@ +require 'i18n/backend/simple' + +module Globalize + module Backend + class Pluralizing < I18n::Backend::Simple + def pluralize(locale, entry, count) + return entry unless entry.is_a?(Hash) and count + key = :zero if count == 0 && entry.has_key?(:zero) + key ||= pluralizer(locale).call(count) + raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key) + translation entry[key], :plural_key => key + end + + def add_pluralizer(locale, pluralizer) + pluralizers[locale.to_sym] = pluralizer + end + + def pluralizer(locale) + pluralizers[locale.to_sym] || default_pluralizer + end + + protected + def default_pluralizer + pluralizers[:en] + end + + def pluralizers + @pluralizers ||= { :en => lambda{|n| n == 1 ? :one : :other } } + end + + # Overwrite this method to return something other than a String + def translation(string, attributes) + string + end + end + end +end \ No newline at end of file -- cgit v1.3