Class: Rosette::Core::Validators::LocaleValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/rosette/core/validators/locale_validator.rb

Overview

Validates a locale by making sure the given repo has been configured to support it.

Examples:

v = LocaleValidator.new
v.valid?('ko-KR', 'my_repo', config)   # => true
v.valid?('foo-BAR', 'my_repo', config) # => false
v.messages  # => ["Repo 'my_repo' doesn't support the 'foo-BAR' locale"]

Instance Attribute Summary

Attributes inherited from Validator

#options

Instance Method Summary collapse

Methods inherited from Validator

#initialize, #messages

Constructor Details

This class inherits a constructor from Rosette::Core::Validators::Validator

Instance Method Details

#valid?(locale_code, repo_name, configuration) ⇒ Boolean

Returns true if the locale is valid, false otherwise.

Parameters:

  • locale_code (String)

    The locale to validate.

  • repo_name (String)

    The repo to use. This method checks the entry in configuration for repo_name to see if it supports locale_code.

  • configuration (Configurator)

    The Rosette configuration to use.

Returns:

  • (Boolean)

24
25
26
27
28
29
30
31
32
# File 'lib/rosette/core/validators/locale_validator.rb', line 24

def valid?(locale_code, repo_name, configuration)
  repo = configuration.get_repo(repo_name)
  if locale_code && repo.get_locale(locale_code)
    true
  else
    messages << "Repo '#{repo_name}' doesn't support the '#{locale_code}' locale"
    false
  end
end