Class: Translatomatic::CLI::Database

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/cli/database.rb

Overview

Database functions for the command line interface

Instance Method Summary collapse

Instance Method Details

#search(string, locale = nil) ⇒ void

This method returns an undefined value.

Search database for the given string

Parameters:

  • string (String)

    String to search for

  • locale (String) (defaults to: nil)

    Optional locale, by default search all locales



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/translatomatic/cli/database.rb', line 12

def search(string, locale = nil)
  Translatomatic::Database.new(options)
  texts = Translatomatic::Model::Text.where('value LIKE ?', "%#{string}%")
  if locale
    db_locale = Translatomatic::Model::Locale.from_tag(locale)
    texts = texts.where(locale: db_locale)
  end
  texts.find_each do |text|
    puts "(%s) %s" % [text.locale, text.value]
    text.translations.each do |translation|
      puts "  -> (%s) %s" % [translation.locale, translation.value]
    end
    puts
  end
end