Sha256: fb4a30ba5f61f6bc985bcd718930a2550f9947e0516be67a0d615261d2d82393

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

require 'erb'
require 'yaml'
require_relative 'text_actions'
require_relative '../logger'

class Lang
  include TextActions

  attr_reader :code, :mistakes

  def initialize(code = 'en')
    @code = code.to_s
    load_files
  end

  def lang
    @code
  end

  private

  def load_files
    dirbase = File.join(File.dirname(__FILE__), '..', 'files', 'language')
    filepath = File.join(dirbase, @code, 'templates.yaml')
    @templates = load_yaml_file(filepath)
    filepath = File.join(dirbase, @code, 'connectors.yaml')
    @connectors = load_yaml_file(filepath)
    filepath = File.join(dirbase, @code, 'mistakes.yaml')
    @mistakes = load_yaml_file(filepath)
  end

  def load_yaml_file(filepath)
    begin
      content = YAML.load(File.new(filepath))
    rescue StandardError => e
      Logger.verboseln '[ERROR] Lang.initialize():' \
                       " Reading YAML file <#{filepath}>"
      Logger.verboseln '[ADVISE] Revise apostrophe into string without \ symbol'
      raise e
    end
    content
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
asker-tool-2.6.0 lib/asker/lang/lang.rb
asker-tool-2.5.9 lib/asker/lang/lang.rb
asker-tool-2.5.8 lib/asker/lang/lang.rb
asker-tool-2.5.7 lib/asker/lang/lang.rb
asker-tool-2.5.6 lib/asker/lang/lang.rb
asker-tool-2.5.5 lib/asker/lang/lang.rb
asker-tool-2.5.4 lib/asker/lang/lang.rb
asker-tool-2.5.3 lib/asker/lang/lang.rb
asker-tool-2.5.2 lib/asker/lang/lang.rb
asker-tool-2.5.1 lib/asker/lang/lang.rb
asker-tool-2.5.0 lib/asker/lang/lang.rb
asker-tool-2.4.5 lib/asker/lang/lang.rb
asker-tool-2.4.4 lib/asker/lang/lang.rb
asker-tool-2.4.3 lib/asker/lang/lang.rb
asker-tool-2.4.2 lib/asker/lang/lang.rb
asker-tool-2.4.1 lib/asker/lang/lang.rb
asker-tool-2.4.0 lib/asker/lang/lang.rb