R18n

Mixin with common methods.

Copyright (C) 2010 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Filters for translations content.

Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Untranslation string for i18n support.

Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Loader for YAML translations.

Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Translation string for i18n support.

Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Add i18n support to any class.

Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Locale withou information file to i18n support.

Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.


Common methods for i18n support.

Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>

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/>.

# Common methods for another R18n code.

Constants

Typed

Struct to containt translation with some type for filter.

VERSION

Attributes

cache[RW]

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

default_loader[RW]

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

default_places[RW]

Default places for R18n.set and R18n.available_locales.

You can set block to calculate places dynamically:

R18n.default_places { settings.i18n_places }
extension_places[RW]

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

Public Class Methods

available_locales(places = R18n.default_places) click to toggle source

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

# File lib/r18n-core.rb, line 124
def available_locales(places = R18n.default_places)
  R18n::I18n.convert_places(places).map { |i| i.available }.flatten.uniq
end
change(locale) click to toggle source

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
# File lib/r18n-core.rb, line 109
def change(locale)
  locale = locale.code if locale.is_a? Locale
  exists = get ? get.locales.map { |i| i.code } : []
  places = get ? get.translation_places : R18n.default_places
  R18n::I18n.new([locale] + exists, places)
end
clear_cache!() click to toggle source

Clean translations cache.

# File lib/r18n-core.rb, line 76
def clear_cache!
  self.cache = { }
end
get() click to toggle source

Get I18n object for current thread.

# File lib/r18n-core.rb, line 68
def get
  thread[:r18n_i18n] ||
  (thread[:r18n_setter] && thread_set(thread[:r18n_setter].call)) ||
  @i18n ||
  (@setter && set(@setter.call))
end
l(*params) click to toggle source

Localize object. Alias for R18n.get.l.

# File lib/r18n-core.rb, line 100
def l(*params)
  get.l(*params)
end
locale(code) click to toggle source

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

# File lib/r18n-core.rb, line 118
def locale(code)
  R18n::Locale.load(code)
end
reset() click to toggle source

Deprecated.

Alias for: reset!
reset!() click to toggle source

Delete I18n object from current thread and global variable.

# File lib/r18n-core.rb, line 81
def reset!
  thread[:r18n_i18n] = thread[:r18n_setter] = @i18n = @setter = nil
  clear_cache!
end
Also aliased as: reset
set(i18n = nil, places = R18n.default_places, &block) click to toggle source

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

# File lib/r18n-core.rb, line 46
def set(i18n = nil, places = R18n.default_places, &block)
  if block_given?
    @setter = block
    @i18n   = nil
  elsif i18n.is_a? I18n
    @i18n = i18n
  else
    @i18n = I18n.new(i18n, places)
  end
end
t(*params) click to toggle source

Translate message. Alias for R18n.get.t.

# File lib/r18n-core.rb, line 95
def t(*params)
  get.t(*params)
end
thread() click to toggle source

Get the current thread.

# File lib/r18n-core.rb, line 90
def thread
  Thread.current
end
thread_set(i18n = nil, &block) click to toggle source

Set I18n object to current thread.

# File lib/r18n-core.rb, line 58
def thread_set(i18n = nil, &block)
  if block_given?
    thread[:r18n_setter] = block
    thread[:r18n_i18n]   = nil
  else
    thread[:r18n_i18n] = i18n
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.