Class: ExtractI18n::Adapters::VueAdapter

Inherits:
SlimAdapter show all
Defined in:
lib/extract_i18n/adapters/vue_adapter.rb

Instance Attribute Summary

Attributes inherited from Adapter

#file_key, #file_path, #on_ask, #options

Instance Method Summary collapse

Methods inherited from SlimAdapter

join_multiline, #run, supports_relative_keys?

Methods inherited from Adapter

for, #initialize, #run, supports_relative_keys?

Constructor Details

This class inherits a constructor from ExtractI18n::Adapters::Adapter

Instance Method Details

#process_line(old_line) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/extract_i18n/adapters/vue_adapter.rb', line 5

def process_line(old_line)
  @mode ||= :template
  if old_line[/^<template/]
    @mode = :template
  elsif old_line[/^<script/]
    @mode = :script
  elsif old_line[/^<style/]
    @mode = :style
  end
  if @mode != :template
    return old_line
  end
  word = ExtractI18n::Slimkeyfy::Word.for('.vue').new(old_line)
  ExtractI18n::Slimkeyfy::VueTransformer.new(word, @file_key).transform do |change|
    if change.nil? # nothing to do
      return old_line
    end

    if @on_ask.call(change)
      change.i18n_t
    else
      old_line
    end
  end
end