Class: SimpleI18n::Language
- Inherits:
-
Object
- Object
- SimpleI18n::Language
- Defined in:
- lib/simple_i18n/language.rb
Class Attribute Summary collapse
-
.current ⇒ Object
Returns the value of attribute current.
-
.default ⇒ Object
Returns the value of attribute default.
-
.table ⇒ Object
Returns the value of attribute table.
Instance Attribute Summary collapse
-
#abbreviation ⇒ Object
readonly
Returns the value of attribute abbreviation.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
- #[](token) ⇒ Object
- #[]=(token, translation) ⇒ Object
-
#initialize(abbr, full_name) ⇒ Language
constructor
A new instance of Language.
- #token_defined?(token_name) ⇒ Boolean
Constructor Details
#initialize(abbr, full_name) ⇒ Language
Returns a new instance of Language.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_i18n/language.rb', line 13 def initialize(abbr, full_name) @translations = {} @abbreviation = abbr @full_name = full_name self.class.table ||= {} self.class.default ||= self self.class.current ||= self if self.class.table.has_key?(abbr) warn 'Redefining %s language.' % abbr end self.class.table[abbr] = self end |
Class Attribute Details
.current ⇒ Object
Returns the value of attribute current.
6 7 8 |
# File 'lib/simple_i18n/language.rb', line 6 def current @current end |
.default ⇒ Object
Returns the value of attribute default.
6 7 8 |
# File 'lib/simple_i18n/language.rb', line 6 def default @default end |
.table ⇒ Object
Returns the value of attribute table.
7 8 9 |
# File 'lib/simple_i18n/language.rb', line 7 def table @table end |
Instance Attribute Details
#abbreviation ⇒ Object (readonly)
Returns the value of attribute abbreviation.
10 11 12 |
# File 'lib/simple_i18n/language.rb', line 10 def abbreviation @abbreviation end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
10 11 12 |
# File 'lib/simple_i18n/language.rb', line 10 def full_name @full_name end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
11 12 13 |
# File 'lib/simple_i18n/language.rb', line 11 def translations @translations end |
Instance Method Details
#[](token) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/simple_i18n/language.rb', line 33 def [](token) tran = @translations[token] return tran if tran default_lang = self.class.default if default_lang == self or (not default_lang.token_defined? token) warn 'No token [%s] defined.' % token return token end warn 'No token [%s] defined in %s, take from %s.' % \ [token, @abbreviation, default_lang.abbreviation] return default_lang[token] end |
#[]=(token, translation) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/simple_i18n/language.rb', line 49 def []=(token, translation) if translations.has_key?(token) warn 'Token [%s] redefined in language %s.' % [token, @abbreviation] end @translations[token] = translation end |
#token_defined?(token_name) ⇒ Boolean
29 30 31 |
# File 'lib/simple_i18n/language.rb', line 29 def token_defined?(token_name) return @translations.has_key?(token_name) end |