lib/knj/gettext_threadded.rb in knjrbfw-0.0.30 vs lib/knj/gettext_threadded.rb in knjrbfw-0.0.31
- old
+ new
@@ -1,18 +1,26 @@
+#This class reads .po-files generated by something like POEdit and can be used to run multi-language applications or websites.
class Knj::Gettext_threadded
- attr_reader :langs, :args
+ #Hash that contains all translations loaded.
+ attr_reader :langs
+ #Config-hash that contains encoding and more.
+ attr_reader :args
+
+ #Initializes various data.
def initialize(args = {})
@args = {
:encoding => "utf-8"
}.merge(args)
@langs = {}
@dirs = []
load_dir(@args["dir"]) if @args["dir"]
end
- #Loads a 'locales'-directory with .mo- and .po-files.
+ #Loads a 'locales'-directory with .mo- and .po-files and fills the '@langs'-hash.
+ #===Examples
+ # gtext.load_dir("#{File.dirname(__FILE__)}/../locales")
def load_dir(dir)
@dirs << dir
check_folders = ["LC_MESSAGES", "LC_ALL"]
Dir.new(dir).each do |file|
@@ -42,9 +50,13 @@
end
end
end
end
+ #Translates a given string to a given locale from the read .po-files.
+ #===Examples
+ # str = "Hello" #=> "Hello"
+ # gtext.trans("da_DK", str) #=> "Hej"
def trans(locale, str)
locale = locale.to_s
str = str.to_s
if !@langs.key?(locale)
\ No newline at end of file