Module: Translating
- Included in:
- AboutDialog, CFPrawn, ConfCheck, ConfDialog, ConfOption, ConfValue, CremeFraiche, CremeFraicheGui, EmlFile, HowtoDialog
- Defined in:
- lib/translating.rb
Overview
A way to produce translated text in a ruby-program. Translations are read from a file “translations” in the program folder.
Constant Summary collapse
- @@lang =
There are better ways to extend a translated string, but I keep the ‘wild-card’ for historical reasons.
nil
- @@lang_file =
format("%s%s", RD, 'LANG')
- @@tr =
YAML::load_file("#{RD}translations")
Class Method Summary collapse
-
.language ⇒ Object
find the current language-setting and return it.
-
.trl(t, warn = true) ⇒ Object
Translate a string to the currently set langage.
Instance Method Summary collapse
-
#trl(t, warn = true) ⇒ Object
Translate a string to the currently set langage.
Class Method Details
.language ⇒ Object
find the current language-setting and return it.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/translating.rb', line 43 def self.language() if @@lang == nil r = ENV['LANG'] if(r) @@lang = r[0, 2] elsif( !File_Checking::file_check(@@lang_file, [:exist?, :readable?]) && File::size(@@lang_file) >= 2) File::open(@@lang_file, 'r') {|f| @@lang = f.readline} @@lang.chomp!.downcase! if @@lang end end @@lang = 'en' if !@@lang end |
.trl(t, warn = true) ⇒ Object
Translate a string to the currently set langage. If ‘warn’ is true (default), a missing translation provokes a message on STDOUT, indicating the string that needs translating.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/translating.rb', line 59 def self.trl(t, warn = true) Translating::language() lt = @@tr[t] if(lt) lt = lt[@@lang] elsif warn # File.open('/tmp/mtf', 'a+') {|f| f << t << "\n"} puts "\nTRANSLATION MISSING: \"" << t << "\"" end lt ||= t return lt end |
Instance Method Details
#trl(t, warn = true) ⇒ Object
Translate a string to the currently set langage. If ‘warn’ is true (default), a missing translation provokes a message on STDOUT, indicating the string that needs translating.
75 76 77 |
# File 'lib/translating.rb', line 75 def trl(t, warn = true ) Translating::trl(t, warn) end |