Class: RailsAiContext::Introspectors::I18nIntrospector

Inherits:
Object
  • Object
show all
Extended by:
StaticTier
Defined in:
lib/rails_ai_context/introspectors/i18n_introspector.rb

Overview

Discovers internationalization setup: locales, backends, key counts.

Constant Summary collapse

DEFAULT_LOCALE_ASSIGNMENT =

Both spellings apps use: config.i18n.default_locale = :es in application.rb or an environment file, and a bare I18n.default_locale = :es in an initializer.

/(?:config\.i18n|I18n)\.default_locale\s*=\s*[:"']([\w-]+)/

Constants included from StaticTier

StaticTier::ALTERNATE_SOURCE, StaticTier::FILES_ONLY, StaticTier::KINDS, StaticTier::RUNTIME_ONLY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StaticTier

answers_statically?, static_tier, static_tier_declared?, unavailable_reason, validate_static_tier!

Constructor Details

#initialize(app) ⇒ I18nIntrospector

Returns a new instance of I18nIntrospector.



19
20
21
# File 'lib/rails_ai_context/introspectors/i18n_introspector.rb', line 19

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/rails_ai_context/introspectors/i18n_introspector.rb', line 17

def app
  @app
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_ai_context/introspectors/i18n_introspector.rb', line 23

def call
  result = {
    default_locale: I18n.default_locale.to_s,
    available_locales: I18n.available_locales.map(&:to_s).sort,
    backend: I18n.backend.class.name,
    locale_files: extract_locale_files,
    total_locale_files: count_locale_files,
    locale_coverage: detect_locale_coverage
  }
  result.merge!(detect_fallback_config)
  result
rescue => e
  { error: e.message }
end

#static_callObject

The locale files are the same files either way; only the list of locales and the default came from a running I18n. Read both from disk rather than report the library's own defaults as the app's.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rails_ai_context/introspectors/i18n_introspector.rb', line 41

def static_call
  locales = locales_from_files
  default = default_locale_from_config

  {
    default_locale: default,
    available_locales: locales,
    backend: nil,
    locale_files: extract_locale_files,
    total_locale_files: count_locale_files,
    locale_coverage: detect_locale_coverage(locales: locales.map(&:to_sym), default: default.to_sym)
  }.merge(detect_fallback_config)
rescue => e
  { error: e.message }
end