Sha256: f63d8d7edd7f1e9e6803784924440db6010e1c1199d4061a898e413cb4099a0d

Contents?: true

Size: 1015 Bytes

Versions: 2

Compression:

Stored size: 1015 Bytes

Contents

require 'yaml'

module Vagrant
  module Util
    # This class is responsible for reading static messages from the strings.yml file.
    class Translator
      @@strings = nil

      class <<self
        # Resets the internal strings hash to nil, forcing a reload on the next
        # access of {strings}.
        def reset!
          @@strings = nil
        end

        # Returns the hash of strings from the error YML files. This only loads once,
        # then returns a cached value until {reset!} is called.
        #
        # @return [Hash]
        def strings
          @@strings ||= YAML.load_file(File.join(PROJECT_ROOT, "templates", "strings.yml"))
        end

        # Renders the string with the given key and data parameters and returns
        # the rendered result.
        #
        # @return [String]
        def t(key, data = {})
          template = strings[key] || "Unknown strings key: #{key}"
          TemplateRenderer.render_string(template, data)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
vagrantup-0.4.0 lib/vagrant/util/translator.rb
vagrant-0.4.0 lib/vagrant/util/translator.rb