Class: WOR::Localization

Inherits:
Object
  • Object
show all
Defined in:
lib/wor/localization.rb

Class Method Summary collapse

Class Method Details

.get_localeObject



46
47
48
49
50
51
52
53
54
# File 'lib/wor/localization.rb', line 46

def get_locale
  locale = I18n.locale

  if (locale.nil?)
    locale = Wor::Configuration::DEFAULT_LOCALE
  end

  return locale
end

.read_locale_file(locale) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/wor/localization.rb', line 56

def read_locale_file locale
  require 'yaml'

  path = "#{Rails.root}/config/locales/wor.#{locale}.yml"

  locale_info = nil

  begin
    locale_info = YAML.load_file(path)
  rescue
    locale_info = nil
  end

  return locale_info
end

.translate_path_to_language(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wor/localization.rb', line 26

def translate_path_to_language params
  if (!WOR::Configuration::USE_LOCALIZATION)
    return params[:path]
  end

  locale_info = WOR::Localization.read_locale_file(params[:locale])

  if (locale_info.nil?)
    return params[:path]
  end

  locale_info['paths'].each do | key, value |
    if (key == params[:path].to_s)
      return value
    end
  end

  return params[:path]
end

.translate_path_to_original(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wor/localization.rb', line 6

def translate_path_to_original params
  if (!WOR::Configuration::USE_LOCALIZATION)
    return params[:path]
  end

  locale_info = WOR::Localization.read_locale_file(params[:locale])

  if (locale_info.nil?)
    return params[:path]
  end

  locale_info['paths'].each do | key, value |
    if (value == params[:path].to_s)
      return key
    end
  end

  return params[:path]
end