Class: TranslateClient::ProjectConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/translate_client/project_config.rb

Constant Summary collapse

SUPPORTED_FORMATS =
["rails", "i18n_js"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ ProjectConfig

Returns a new instance of ProjectConfig.



13
14
15
16
17
18
19
20
# File 'lib/translate_client/project_config.rb', line 13

def initialize(**options)
  @options = options

  project_id
  locales
  format
  locales.each { |locale| file(locale:) }
end

Class Method Details

.supported_formatsObject



8
9
10
# File 'lib/translate_client/project_config.rb', line 8

def supported_formats
  SUPPORTED_FORMATS.map(&:dasherize).join(", ")
end

Instance Method Details

#file(locale:) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/translate_client/project_config.rb', line 40

def file(locale:)
  if locales.exclude?(locale)
    raise PresentableError.new("Locale \"#{locale}\" not found in #{locales.join(", ")}")
  end

  @options[:file] || default_file(locale)
end

#formatObject



30
31
32
33
34
35
36
37
38
# File 'lib/translate_client/project_config.rb', line 30

def format
  format = @options[:format]&.underscore

  if format && SUPPORTED_FORMATS.exclude?(format)
    raise PresentableError.new("Format \"#{@options[:format]}\" is not supported")
  end

  format || default_format
end

#localesObject



26
27
28
# File 'lib/translate_client/project_config.rb', line 26

def locales
  Array(@options[:locale] || default_locales)
end

#project_idObject



22
23
24
# File 'lib/translate_client/project_config.rb', line 22

def project_id
  @options[:project_id] || default_project_id
end