lib/fast_gettext.rb in grosser-fast_gettext-0.2.4 vs lib/fast_gettext.rb in grosser-fast_gettext-0.2.5
- old
+ new
@@ -1,7 +1,8 @@
require 'fast_gettext/mo_file'
require 'fast_gettext/storage'
+require 'fast_gettext/translation'
require File.join(File.dirname(__FILE__),'..','vendor','string')
module FastGettext
include FastGettext::Storage
@@ -11,43 +12,22 @@
end
LOCALE_REX = /^[a-z]{2}$|^[a-z]{2}_[A-Z]{2}$/
NAMESPACE_SEPERATOR = '|'
- def _(translate)
- current_mo[translate] || translate
- end
-
- #translate pluralized
- def n_(singular,plural,count)
- if translation = current_mo.plural(singular,plural,count)
- translation
- else
- count > 1 ? plural : singular
+ # users should not include FastGettext, since this would conterminate their namespace
+ # rather use
+ # FastGettext.locale = ..
+ # FastGettext.text_domain = ..
+ # and
+ # include FastGettext::Translation
+ FastGettext::Translation.public_instance_methods.each do |method|
+ define_method method do |*args|
+ Translation.send(method,*args)
end
end
- #translate, but discard namespace if nothing was found
- # Car|Tire -> Tire if no translation could be found
- def s_(translate,seperator=nil)
- if translation = current_mo[translate]
- translation
- else
- translate.split(seperator||NAMESPACE_SEPERATOR).last
- end
- end
-
- #tell gettext: this string need translation (will be found during parsing)
- def N_(translate)
- translate
- end
-
- #tell gettext: this string need translation (will be found during parsing)
- def Nn_(singular,plural)
- [singular,plural]
- end
-
def add_text_domain(name,options)
self.text_domains ||= {}
domain = self.text_domains[name] = {:path=>options.delete(:path),:mo_files=>{}}
# parse all .mo files with the right name, that sit in locale/LC_MESSAGES folders
@@ -57,15 +37,7 @@
next unless File.exist? mo_file
locale = File.basename(locale_folder)
domain[:mo_files][locale] = MoFile.new(mo_file)
end
domain
- end
-
- private
-
- #TODO geht nicht <-> {}.plural
- def current_mo
- mo = text_domains[text_domain][:mo_files][locale] rescue nil
- mo || {}
end
end
\ No newline at end of file