Class: InertiaI18n::Configuration
- Inherits:
-
Object
- Object
- InertiaI18n::Configuration
- Defined in:
- lib/inertia_i18n/configuration.rb
Instance Attribute Summary collapse
-
#dynamic_keys ⇒ Object
Dynamic keys exact mapping (prefix => array of possible values).
-
#dynamic_patterns ⇒ Object
Dynamic key patterns (prefix => regex).
-
#ignore_missing ⇒ Object
Keys to ignore during missing check.
-
#ignore_unused ⇒ Object
Keys to ignore during unused check.
-
#interpolation ⇒ Object
Interpolation conversion settings.
-
#key_properties ⇒ Object
Object properties that contain translation keys (e.g., titleKey: "some.key").
- #locales ⇒ Object
-
#missing_key_filters ⇒ Object
Filters for false-positive missing keys.
-
#scan_extensions ⇒ Object
File extensions to scan by framework.
-
#scan_paths ⇒ Object
Paths to scan for translation usage.
-
#sibling_detection ⇒ Object
Sibling detection settings for enum-like keys (status, types, etc.).
-
#source_paths ⇒ Object
Source paths for Rails YAML locale files.
-
#source_pattern ⇒ Object
YAML file pattern to match.
-
#target_path ⇒ Object
Target path for generated i18next JSON files.
-
#translation_functions ⇒ Object
Translation function names to detect.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_from_yaml(path) ⇒ Object
- #primary_locale ⇒ Object
- #secondary_locales ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/inertia_i18n/configuration.rb', line 56 def initialize @source_paths = ["config/locales/frontend"] @target_path = "app/frontend/locales" @locales = nil # Uses I18n.available_locales by default @source_pattern = "**/*.{yml,yaml}" @interpolation = {from: "%{", to: "{{"} @scan_paths = ["app/frontend/**/*.{js,ts,jsx,tsx,svelte,vue}"] @scan_extensions = { svelte: %w[.svelte], react: %w[.jsx .tsx], vue: %w[.vue], javascript: %w[.js .ts] } @translation_functions = %w[t $t i18n.t] @dynamic_patterns = {} @dynamic_keys = {} @ignore_unused = [] @ignore_missing = [] @key_properties = %w[titleKey labelKey messageKey descriptionKey placeholderKey key] @sibling_detection = { enabled: true, suffixes: %w[status statuses types type priorities priority] } @missing_key_filters = { min_length: 4, require_dot: true, exclude_patterns: [ /^\/[\w\/-]*$/, # URL paths (/hr/applications) /^[A-Z_]+$/, # Constants (HTTP, POST) /^\w+_id$/, # ID fields (user_id, parent_id) /^[a-z]{2}(-[A-Z]{2})?$/ # Locales (en, ru-RU) ] } end |
Instance Attribute Details
#dynamic_keys ⇒ Object
Dynamic keys exact mapping (prefix => array of possible values)
39 40 41 |
# File 'lib/inertia_i18n/configuration.rb', line 39 def dynamic_keys @dynamic_keys end |
#dynamic_patterns ⇒ Object
Dynamic key patterns (prefix => regex)
36 37 38 |
# File 'lib/inertia_i18n/configuration.rb', line 36 def dynamic_patterns @dynamic_patterns end |
#ignore_missing ⇒ Object
Keys to ignore during missing check
45 46 47 |
# File 'lib/inertia_i18n/configuration.rb', line 45 def ignore_missing @ignore_missing end |
#ignore_unused ⇒ Object
Keys to ignore during unused check
42 43 44 |
# File 'lib/inertia_i18n/configuration.rb', line 42 def ignore_unused @ignore_unused end |
#interpolation ⇒ Object
Interpolation conversion settings
24 25 26 |
# File 'lib/inertia_i18n/configuration.rb', line 24 def interpolation @interpolation end |
#key_properties ⇒ Object
Object properties that contain translation keys (e.g., titleKey: "some.key")
48 49 50 |
# File 'lib/inertia_i18n/configuration.rb', line 48 def key_properties @key_properties end |
#locales ⇒ Object
16 17 18 |
# File 'lib/inertia_i18n/configuration.rb', line 16 def locales @locales || I18n.available_locales end |
#missing_key_filters ⇒ Object
Filters for false-positive missing keys
54 55 56 |
# File 'lib/inertia_i18n/configuration.rb', line 54 def missing_key_filters @missing_key_filters end |
#scan_extensions ⇒ Object
File extensions to scan by framework
30 31 32 |
# File 'lib/inertia_i18n/configuration.rb', line 30 def scan_extensions @scan_extensions end |
#scan_paths ⇒ Object
Paths to scan for translation usage
27 28 29 |
# File 'lib/inertia_i18n/configuration.rb', line 27 def scan_paths @scan_paths end |
#sibling_detection ⇒ Object
Sibling detection settings for enum-like keys (status, types, etc.)
51 52 53 |
# File 'lib/inertia_i18n/configuration.rb', line 51 def sibling_detection @sibling_detection end |
#source_paths ⇒ Object
Source paths for Rails YAML locale files. Can be one or more directories.
8 9 10 |
# File 'lib/inertia_i18n/configuration.rb', line 8 def source_paths @source_paths end |
#source_pattern ⇒ Object
YAML file pattern to match
21 22 23 |
# File 'lib/inertia_i18n/configuration.rb', line 21 def source_pattern @source_pattern end |
#target_path ⇒ Object
Target path for generated i18next JSON files
11 12 13 |
# File 'lib/inertia_i18n/configuration.rb', line 11 def target_path @target_path end |
#translation_functions ⇒ Object
Translation function names to detect
33 34 35 |
# File 'lib/inertia_i18n/configuration.rb', line 33 def translation_functions @translation_functions end |
Instance Method Details
#load_from_yaml(path) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/inertia_i18n/configuration.rb', line 99 def load_from_yaml(path) data = YAML.safe_load_file(path, permitted_classes: [Regexp]) return unless data.is_a?(Hash) SIMPLE_ATTRIBUTES.each do |attr| public_send(:"#{attr}=", data[attr.to_s]) if data.key?(attr.to_s) end self.locales = data["locales"].map(&:to_sym) if data.key?("locales") load_hash_attribute(:interpolation, data) self.dynamic_patterns = data["dynamic_patterns"] || {} if data.key?("dynamic_patterns") self.dynamic_keys = data["dynamic_keys"] || {} if data.key?("dynamic_keys") load_sibling_detection(data) if data.key?("sibling_detection") load_missing_key_filters(data) if data.key?("missing_key_filters") end |
#primary_locale ⇒ Object
91 92 93 |
# File 'lib/inertia_i18n/configuration.rb', line 91 def primary_locale locales.first end |
#secondary_locales ⇒ Object
95 96 97 |
# File 'lib/inertia_i18n/configuration.rb', line 95 def secondary_locales locales[1..] end |