lib/fast_gettext/translation.rb in grosser-fast_gettext-0.2.11 vs lib/fast_gettext/translation.rb in grosser-fast_gettext-0.3.0
- old
+ new
@@ -2,10 +2,11 @@
# this module should be included
# Responsibility:
# - direct translation queries to the current repository
# - handle untranslated values
# - understand / enforce namespaces
+ # - decide which plural form is used
module Translation
extend self
#make it usable in class definition, e.g.
# class Y
@@ -20,17 +21,19 @@
found = FastGettext.current_cache[translate] and return found
FastGettext.current_cache[translate] = FastGettext.current_repository[translate] || translate
end
#translate pluralized
- def n_(singular,plural,count)
- if translation = FastGettext.current_repository.plural(singular,plural,count)
- translation
- else
- #TODO remove this repeated logic, e.g. return :plural / :singular or raise an exception ?
- count == 1 ? singular : plural
- end
+ # some languages have up to 4 plural forms...
+ # n_(singular, plural, plural form 2, ..., count)
+ # n_('apple','apples',3)
+ def n_(*msgids)
+ count = msgids.pop
+
+ translations = FastGettext.current_repository.plural(*msgids)
+ selected = FastGettext.current_repository.pluralisation_rule.call(count)
+ translations[selected] || msgids[selected] || msgids.last
end
#translate, but discard namespace if nothing was found
# Car|Tire -> Tire if no translation could be found
def s_(translate,seperator=nil)
@@ -45,10 +48,10 @@
def N_(translate)
translate
end
#tell gettext: this string need translation (will be found during parsing)
- def Nn_(singular,plural)
- [singular,plural]
+ def Nn_(*msgids)
+ msgids
end
end
end
\ No newline at end of file