Class: Worldwide::RubyI18nConfig

Inherits:
I18n::Config
  • Object
show all
Defined in:
lib/worldwide/ruby_i18n_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backendObject



21
22
23
24
25
# File 'lib/worldwide/ruby_i18n_config.rb', line 21

def backend
  return @backend if defined?(@backend)

  super
end

#default_separatorObject



75
76
77
78
79
# File 'lib/worldwide/ruby_i18n_config.rb', line 75

def default_separator
  return @default_separator if defined?(@default_separator)

  super
end

#enforce_available_localesObject

Whether or not to verify if locales are in the list of available locales.



133
134
135
136
137
# File 'lib/worldwide/ruby_i18n_config.rb', line 133

def enforce_available_locales
  return @enforce_available_locales if defined?(@enforce_available_locales)

  super
end

#exception_handlerObject



82
83
84
85
86
# File 'lib/worldwide/ruby_i18n_config.rb', line 82

def exception_handler
  return @exception_handler if defined?(@exception_handler)

  super
end

#interpolation_patternsObject



141
142
143
144
145
# File 'lib/worldwide/ruby_i18n_config.rb', line 141

def interpolation_patterns
  return @interpolation_patterns if defined?(@interpolation_patterns)

  super
end

#missing_interpolation_argument_handlerObject

Returns the current handler for situations when interpolation argument is missing. MissingInterpolationArgument will be raised by default.



91
92
93
94
95
# File 'lib/worldwide/ruby_i18n_config.rb', line 91

def missing_interpolation_argument_handler
  return @missing_interpolation_argument_handler if defined?(@missing_interpolation_argument_handler)

  super
end

Instance Method Details

#available_localesObject



39
40
41
42
43
# File 'lib/worldwide/ruby_i18n_config.rb', line 39

def available_locales
  return @available_locales if defined?(@available_locales)

  super
end

#available_locales=(locales) ⇒ Object



57
58
59
60
61
# File 'lib/worldwide/ruby_i18n_config.rb', line 57

def available_locales=(locales)
  @available_locales = Array(locales).map(&:to_sym)
  @available_locales = nil if @available_locales.empty?
  @available_locales_set = nil
end

#available_locales_initialized?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/worldwide/ruby_i18n_config.rb', line 63

def available_locales_initialized?
  return !!@available_locales if defined?(@available_locales)

  super
end

#available_locales_setObject

Caches the available locales list as both strings and symbols in a Set, so that we can have faster lookups to do the available locales enforce check.



47
48
49
50
51
52
53
54
55
# File 'lib/worldwide/ruby_i18n_config.rb', line 47

def available_locales_set
  if defined?(@available_locales)
    return @available_locales_set ||= available_locales.inject(Set.new) do |set, locale|
      set << locale.to_s << locale.to_sym
    end
  end

  super
end

#clear_available_locales_setObject

Clears the available locales set so it can be recomputed again after I18n gets reloaded.



71
72
73
# File 'lib/worldwide/ruby_i18n_config.rb', line 71

def clear_available_locales_set
  @available_locales_set = nil
end

#default_localeObject



28
29
30
31
32
# File 'lib/worldwide/ruby_i18n_config.rb', line 28

def default_locale
  return @default_locale if defined?(@default_locale)

  super
end

#default_locale=(locale) ⇒ Object



34
35
36
37
# File 'lib/worldwide/ruby_i18n_config.rb', line 34

def default_locale=(locale)
  I18n.enforce_available_locales!(locale)
  @default_locale = locale&.to_sym
end

#load_pathObject

Allow clients to register paths providing translation data sources. The backend defines acceptable sources.

E.g. the provided SimpleBackend accepts a list of paths to translation files which are either named *.rb and contain plain Ruby Hashes or are named *.yml and contain YAML data. So for the SimpleBackend clients may register translation files like this:

I18n.load_path << 'path/to/locale/en.yml'


118
119
120
121
122
# File 'lib/worldwide/ruby_i18n_config.rb', line 118

def load_path
  return @load_path if defined?(@load_path)

  super
end

#load_path=(load_path) ⇒ Object

Sets the load path instance. Custom implementations are expected to behave like a Ruby Array.



126
127
128
129
130
# File 'lib/worldwide/ruby_i18n_config.rb', line 126

def load_path=(load_path)
  @load_path = load_path
  @available_locales_set = nil
  backend.reload!
end

#localeObject



12
13
14
# File 'lib/worldwide/ruby_i18n_config.rb', line 12

def locale
  defined?(@locale) && !@locale.nil? ? @locale : super
end

#locale=(locale) ⇒ Object



16
17
18
19
# File 'lib/worldwide/ruby_i18n_config.rb', line 16

def locale=(locale)
  I18n.enforce_available_locales!(locale)
  @locale = locale&.to_sym
end