Module: RubyLsp::Ree::ReeLocaleUtils
- Included in:
- DefinitionHandler, HoverHandler, MissingErrorLocalesFormatter, ReeFormatter
- Defined in:
- lib/ruby_lsp/ruby_lsp_ree/utils/ree_locale_utils.rb
Instance Method Summary collapse
- #find_locale_key_location(file_path, key_path) ⇒ Object
- #find_locale_value(file_path, key_path) ⇒ Object
- #package_locales_folder_path(uri) ⇒ Object
Instance Method Details
#find_locale_key_location(file_path, key_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_lsp/ruby_lsp_ree/utils/ree_locale_utils.rb', line 25 def find_locale_key_location(file_path, key_path) loc_key = File.basename(file_path, '.yml') key_parts = [loc_key] + key_path.split('.') parsed_yaml = RubyLsp::Ree::YamlFileParser.parse(file_path) key_location = parsed_yaml.dig(*key_parts) if key_location OpenStruct.new(line: key_location.line, column: key_location.column) else OpenStruct.new(line: 0, column: 0) end end |
#find_locale_value(file_path, key_path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ruby_lsp/ruby_lsp_ree/utils/ree_locale_utils.rb', line 17 def find_locale_value(file_path, key_path) loc_yaml = YAML.load_file(file_path) loc_key = File.basename(file_path, '.yml') key_parts = [loc_key] + key_path.split('.') loc_yaml.dig(*key_parts) end |
#package_locales_folder_path(uri) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_lsp/ruby_lsp_ree/utils/ree_locale_utils.rb', line 7 def package_locales_folder_path(uri) uri_parts = uri.to_s.chomp(File.extname(uri.to_s)).split('/') package_folder_index = uri_parts.index('package') return unless package_folder_index path_parts = uri_parts.take(package_folder_index+2) + ['locales'] path_parts.join('/') end |