Module: R18n

Defined in:
lib/r18n-core/utils.rb,
lib/r18n-core.rb,
lib/r18n-core/i18n.rb,
lib/r18n-core/locale.rb,
lib/r18n-core/filters.rb,
lib/r18n-core/helpers.rb,
lib/r18n-core/version.rb,
lib/r18n-core/translated.rb,
lib/r18n-core/translation.rb,
lib/r18n-core/yaml_loader.rb,
lib/r18n-core/untranslated.rb,
lib/r18n-core/translated_string.rb,
lib/r18n-core/unsupported_locale.rb

Overview

Locale withou information file to i18n support.

Copyright © 2008 Andrey “A.I.” Sitnik <[email protected]>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Defined Under Namespace

Modules: Filters, Helpers, Loader, Locales, Translated, Utils Classes: I18n, Locale, TranslatedString, Translation, Typed, UnsupportedLocale, Untranslated

Constant Summary collapse

VERSION =
'0.4.14'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject

Hash of hash-like (see Moneta) object to store loaded translations.



99
100
101
# File 'lib/r18n-core.rb', line 99

def cache
  @cache
end

.default_loaderObject

Default loader class, which will be used if you didn’t send loader to I18n.new (object with available and load methods).



92
93
94
# File 'lib/r18n-core.rb', line 92

def default_loader
  @default_loader
end

.extension_placesObject

Loaders with extension translations. If application translations with same locale isn’t exists, extension file willn’t be used.



96
97
98
# File 'lib/r18n-core.rb', line 96

def extension_places
  @extension_places
end

Class Method Details

.getObject

Get I18n object for current thread.



64
65
66
67
# File 'lib/r18n-core.rb', line 64

def get
  (thread[:r18n_i18n] ||= ((block = thread[:r18n_setter]) && block.call)) ||
  (@i18n ||= (@setter && @setter.call))
end

.l(*params) ⇒ Object

Localize object. Alias for R18n.get.l.



86
87
88
# File 'lib/r18n-core.rb', line 86

def l(*params)
  get.l(*params)
end

.resetObject

Delete I18n object from current thread and global variable.



70
71
72
73
# File 'lib/r18n-core.rb', line 70

def reset
  thread[:r18n_i18n] = thread[:r18n_setter] = @i18n = @setter = nil
  self.cache = {}
end

.set(i18n = nil, dir = nil, &block) ⇒ Object

Set I18n object globally.



42
43
44
45
46
47
48
49
50
51
# File 'lib/r18n-core.rb', line 42

def set(i18n = nil, dir = nil, &block)
  if block_given?
    @setter = block
    @i18n = nil
  elsif i18n.is_a? I18n
    @i18n = i18n
  else
    @i18n = I18n.new(i18n, dir)
  end
end

.t(*params) ⇒ Object

Translate message. Alias for R18n.get.t.



81
82
83
# File 'lib/r18n-core.rb', line 81

def t(*params)
  get.t(*params)
end

.threadObject

Get the current thread.



76
77
78
# File 'lib/r18n-core.rb', line 76

def thread
  Thread.current
end

.thread_set(i18n = nil, &block) ⇒ Object

Set I18n object to current thread.



54
55
56
57
58
59
60
61
# File 'lib/r18n-core.rb', line 54

def thread_set(i18n = nil, &block)
  if block_given?
    Thread.current[:r18n_setter] = block
    Thread.current[:r18n_i18n] = nil
  else
    Thread.current[:r18n_i18n] = i18n
  end
end