Module: R18n

Defined in:
lib/r18n-core.rb,
lib/r18n-core/i18n.rb,
lib/r18n-core/utils.rb,
lib/r18n-core/locale.rb,
lib/r18n-core/filters.rb,
lib/r18n-core/helpers.rb,
lib/r18n-core/version.rb,
lib/r18n-core/locales/af.rb,
lib/r18n-core/locales/az.rb,
lib/r18n-core/locales/bg.rb,
lib/r18n-core/locales/ca.rb,
lib/r18n-core/locales/cs.rb,
lib/r18n-core/locales/cy.rb,
lib/r18n-core/locales/da.rb,
lib/r18n-core/locales/de.rb,
lib/r18n-core/locales/en.rb,
lib/r18n-core/locales/eo.rb,
lib/r18n-core/locales/es.rb,
lib/r18n-core/locales/fa.rb,
lib/r18n-core/locales/fi.rb,
lib/r18n-core/locales/fr.rb,
lib/r18n-core/locales/gl.rb,
lib/r18n-core/locales/hr.rb,
lib/r18n-core/locales/hu.rb,
lib/r18n-core/locales/id.rb,
lib/r18n-core/locales/it.rb,
lib/r18n-core/locales/ja.rb,
lib/r18n-core/locales/kk.rb,
lib/r18n-core/locales/ko.rb,
lib/r18n-core/locales/lv.rb,
lib/r18n-core/locales/mn.rb,
lib/r18n-core/locales/nb.rb,
lib/r18n-core/locales/nl.rb,
lib/r18n-core/locales/no.rb,
lib/r18n-core/locales/pl.rb,
lib/r18n-core/locales/pt.rb,
lib/r18n-core/locales/ru.rb,
lib/r18n-core/locales/sk.rb,
lib/r18n-core/locales/th.rb,
lib/r18n-core/locales/tr.rb,
lib/r18n-core/locales/uk.rb,
lib/r18n-core/locales/vi.rb,
lib/r18n-core/locales/zh.rb,
lib/r18n-core/translated.rb,
lib/r18n-core/filter_list.rb,
lib/r18n-core/translation.rb,
lib/r18n-core/yaml_loader.rb,
lib/r18n-core/untranslated.rb,
lib/r18n-core/yaml_methods.rb,
lib/r18n-core/locales/en-au.rb,
lib/r18n-core/locales/en-gb.rb,
lib/r18n-core/locales/en-us.rb,
lib/r18n-core/locales/es-cl.rb,
lib/r18n-core/locales/es-us.rb,
lib/r18n-core/locales/pt-br.rb,
lib/r18n-core/locales/sv-se.rb,
lib/r18n-core/locales/zh-cn.rb,
lib/r18n-core/locales/zh-tw.rb,
lib/r18n-core/locales/sr-latn.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, YamlMethods Classes: CustomFilterList, FilterList, GlobalFilterList, I18n, Locale, TranslatedString, Translation, Typed, UnpluralizedTranslation, UnsupportedLocale, Untranslated

Constant Summary collapse

VERSION =
'5.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject

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



151
152
153
# File 'lib/r18n-core.rb', line 151

def cache
  @cache
end

.default_loaderObject

Default loader class, which will be used if you did not send loader to ‘I18n.new` (object with `available` and `load` methods).



144
145
146
# File 'lib/r18n-core.rb', line 144

def default_loader
  @default_loader
end

.default_places(&block) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/r18n-core.rb', line 132

def default_places(&block)
  if block
    @default_places = block
  elsif @default_places.is_a? Proc
    @default_places.call
  else
    @default_places
  end
end

.extension_placesObject

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



148
149
150
# File 'lib/r18n-core.rb', line 148

def extension_places
  @extension_places
end

Class Method Details

.available_locales(places = R18n.default_places) ⇒ Object

Return ‘Array` of locales with available translations. You can miss translation `places`, it will be taken from `R18n.default_places`.



122
123
124
# File 'lib/r18n-core.rb', line 122

def available_locales(places = R18n.default_places)
  R18n::I18n.convert_places(places).map(&:available).flatten.uniq
end

.change(locale) ⇒ Object

Return I18n object for ‘locale`. Useful to temporary change locale, for example, to show text in locales list:

- R18n.available_locales.each do |locale|
  - R18n.change(locale).t.language_title

It also can be used with block:

- R18n.change(locale) { t.language_title }


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/r18n-core.rb', line 97

def change(locale)
  locale = locale.code if locale.is_a? Locale
  exists = get ? get.locales.map(&:code) : []
  places = get ? get.translation_places : R18n.default_places

  i18n = R18n::I18n.new([locale] + exists, places)

  if block_given?
    old_thread_i18n = thread[:r18n_i18n]
    thread_set i18n
    yield
    thread[:r18n_i18n] = old_thread_i18n
  end

  i18n
end

.clear_cache!Object

Clean translations cache.



60
61
62
# File 'lib/r18n-core.rb', line 60

def clear_cache!
  self.cache = {}
end

.getObject

Get I18n object for current thread.



55
56
57
# File 'lib/r18n-core.rb', line 55

def get
  thread[:r18n_i18n] || @i18n
end

.l(*params) ⇒ Object

Localize object. Alias for ‘R18n.get.l`.



84
85
86
# File 'lib/r18n-core.rb', line 84

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

.locale(code) ⇒ Object

Return Locale object by locale code. It’s shortcut for ‘R18n::Locale.load(code)`.



116
117
118
# File 'lib/r18n-core.rb', line 116

def locale(code)
  R18n::Locale.load(code)
end

.reset!Object Also known as: reset

Delete I18n object from current thread and global variable.



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

def reset!
  thread[:r18n_i18n] = thread[:r18n_setter] = @i18n = @setter = nil
  clear_cache!
end

.set(i18n, places = R18n.default_places) ⇒ Object

Set I18n object globally. You can miss translation ‘places`, it will be taken from `R18n.default_places`.



45
46
47
# File 'lib/r18n-core.rb', line 45

def set(i18n, places = R18n.default_places)
  @i18n = i18n.is_a?(I18n) ? i18n : I18n.new(i18n, places)
end

.t(*params) ⇒ Object

Translate message. Alias for ‘R18n.get.t`.



79
80
81
# File 'lib/r18n-core.rb', line 79

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

.threadObject

Get the current thread.



74
75
76
# File 'lib/r18n-core.rb', line 74

def thread
  Thread.current
end

.thread_set(i18n) ⇒ Object

Set I18n object to current thread.



50
51
52
# File 'lib/r18n-core.rb', line 50

def thread_set(i18n)
  thread[:r18n_i18n] = i18n
end