Module: LangTools
- Included in:
- Catalog, I18nService
- Defined in:
- lib/ri18n/langtools.rb
Constant Summary collapse
- PLURAL_FAMILIES =
{ :one => %w(hu ja ko tr), :two_germanic => %w(da nl en de no sv et fi el he it pt es eo), :two_romanic => %w(fr pt_BR), :three_celtic => %w(ga gd), :three_baltic_latvian => %w(lv), :three_baltic_lithuanian => %w(lt), :three_slavic_russian => %w(hr cs ru sk uk), :three_slavic_polish => %w(pl), :four => %w(sl)}
- NPLURAL =
{:one => 1, :two_germanic => 2, :two_romanic => 2, :three_celtic => 3, :three_baltic_latvian => 3, :three_baltic_lithuanian => 3, :three_slavic_russian => 3, :three_slavic_polish => 3, :four => 4 }
Instance Attribute Summary collapse
-
#lang ⇒ Object
example: ‘ja_JP.eucJP’.
Instance Method Summary collapse
-
#country_code ⇒ Object
(also: #cc)
the country code part from lang, eg ‘JP’ for @lang=‘ja_JP.eucJP’ returns nil if there is none.
- #find_family ⇒ Object
-
#lang_encoding ⇒ Object
(also: #le)
the charset encoding part from lang, eg ‘eucJP’ for @lang=‘ja_JP.eucJP’ returns nil if there is none.
-
#language_code ⇒ Object
(also: #lc)
the language code part from lang, eg ‘ja’ for @lang=‘ja_JP.eucJP’.
-
#language_country ⇒ Object
the language and country code parts from lang, eg ‘ja_JP’ for @lang=‘ja_JP.eucJP’ returns language_code is there is no country code part.
-
#nplural ⇒ Object
number of plural forms.
- #plural_family ⇒ Object
Instance Attribute Details
#lang ⇒ Object
example: ‘ja_JP.eucJP’
7 8 9 |
# File 'lib/ri18n/langtools.rb', line 7 def lang @lang end |
Instance Method Details
#country_code ⇒ Object Also known as: cc
the country code part from lang, eg ‘JP’ for @lang=‘ja_JP.eucJP’ returns nil if there is none
38 39 40 41 42 |
# File 'lib/ri18n/langtools.rb', line 38 def country_code if m = /\w\w_(\w\w)/.match(@lang) m[1] end end |
#find_family ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/ri18n/langtools.rb', line 64 def find_family # first seek for 'pt_BR' then for just 'pt' (for example) if found = PLURAL_FAMILIES.find{|fam, list| list.include?(language_country)} || PLURAL_FAMILIES.find{|fam, list| list.include?(language_code)} found.first else nil end end |
#lang_encoding ⇒ Object Also known as: le
the charset encoding part from lang, eg ‘eucJP’ for @lang=‘ja_JP.eucJP’ returns nil if there is none
57 58 59 60 61 |
# File 'lib/ri18n/langtools.rb', line 57 def lang_encoding if m = /\w\w(?:_\w\w)?\./.match(@lang) m.post_match end end |
#language_code ⇒ Object Also known as: lc
the language code part from lang, eg ‘ja’ for @lang=‘ja_JP.eucJP’
31 32 33 |
# File 'lib/ri18n/langtools.rb', line 31 def language_code @lang[0,2] end |
#language_country ⇒ Object
the language and country code parts from lang, eg ‘ja_JP’ for @lang=‘ja_JP.eucJP’ returns language_code is there is no country code part
47 48 49 50 51 52 53 |
# File 'lib/ri18n/langtools.rb', line 47 def language_country if m = /(\w\w_\w\w)/.match(@lang) m[1] else language_code end end |
#nplural ⇒ Object
number of plural forms
74 75 76 |
# File 'lib/ri18n/langtools.rb', line 74 def nplural NPLURAL[plural_family] end |
#plural_family ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/ri18n/langtools.rb', line 78 def plural_family if @lang find_family or :two_germanic else :two_germanic end end |