Class: Juli::Util::JuliI18n

Inherits:
Object
  • Object
show all
Defined in:
lib/juli/util/juli_i18n.rb

Overview

Locale is determined by ‘locale’ entry in .juli/config (default = en).

Translation file is used at the following priority:

  1. .juli/LC.yml

  2. LIB/juli/template/locale/LC.yml

Where, LC is the value of ‘locale’ config (default = en), and LIB is ruby library directory (e.g. /usr/lib/lib/ruby/site_ruby/1.9.1/).

Instance Method Summary collapse

Constructor Details

#initialize(conf, juli_repo) ⇒ JuliI18n

Returns a new instance of JuliI18n.

Raises:

  • (Errno::ENOENT)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/juli/util/juli_i18n.rb', line 15

def initialize(conf, juli_repo)
  I18n.locale = conf['locale'] || :en

  for candidate_dir in [
      File.join(juli_repo, Juli::REPO),
      File.join(Juli::TEMPLATE_PATH, 'locale')
      ] do
    locale_yml = File.join(candidate_dir, "#{I18n.locale}.yml")
    if File.exist?(locale_yml)
      I18n.load_path = [locale_yml]
      return
    end
  end
  raise Errno::ENOENT, "no #{I18n.locale}.yml found"
end