module TranslationIO

Constants

GETTEXT_METHODS

Attributes

client[R]
config[R]

Public Class Methods

add_parser_for_erb_source_formats(new_erb_formats) click to toggle source
# File lib/translation.rb, line 73
def add_parser_for_erb_source_formats(new_erb_formats)
  existing_extensions = GetText::ErbParser.instance_variable_get("@config")[:extnames]
  new_extensions = new_erb_formats.collect { |ext| ".#{ext}" }

  GetText::ErbParser.instance_variable_get("@config")[:extnames] = (existing_extensions + new_extensions).uniq
end
configure() { |config| ... } click to toggle source
# File lib/translation.rb, line 27
def configure(&block)
  ENV['LANG'] = 'en_US.UTF-8' if ENV['LANG'].blank?

  @config ||= Config.new

  yield @config

  if !@config.disable_gettext
    require_gettext_dependencies
    add_parser_for_erb_source_formats(@config.erb_source_formats)

    if Rails.env.development?
      GetText::TextDomainManager.cached = false
    end

    # include is private until Ruby 2.1
    Proxy.send(:include, GetText)

    @config.bound_text_domains.each do |bound_text_domain|
      Proxy.bindtextdomain(bound_text_domain, {
        :path           => @config.locales_path,
        :output_charset => @config.charset
      })
    end

    Proxy.textdomain(@config.text_domain)

    if @config.gettext_object_delegate
      Object.delegate *GETTEXT_METHODS, :to => Proxy
    end
  end

  @client = Client.new(@config.api_key, @config.endpoint)

  return true
end
info(message, level = 0, verbose_level = 0) click to toggle source
# File lib/translation.rb, line 80
def info(message, level = 0, verbose_level = 0)
  verbose = @config.try(:verbose) || 0
  if verbose >= verbose_level
    indent = (1..level).to_a.collect { "   " }.join('')
    puts "#{indent}* #{message}"
  end
end
normalize_path(relative_or_absolute_path) click to toggle source
# File lib/translation.rb, line 88
def normalize_path(relative_or_absolute_path)
  File.expand_path(relative_or_absolute_path).gsub("#{Dir.pwd}/", '')
end
require_gettext_dependencies() click to toggle source
# File lib/translation.rb, line 64
def require_gettext_dependencies
  require 'gettext'
  require 'gettext/po'
  require 'gettext/po_parser'
  require 'gettext/tools'
  require 'gettext/text_domain_manager'
  require 'gettext/tools/xgettext'
end
version() click to toggle source
# File lib/translation.rb, line 92
def version
  Gem::Specification::find_by_name('translation').version.to_s
end