module ReactOnRails::Locales
def self.check_config_directory_exists(directory:, key_name:, remove_if:)
def self.check_config_directory_exists(directory:, key_name:, remove_if:) return if directory.nil? return if Dir.exist?(directory) msg = <<~MSG Error configuring /config/initializers/react_on_rails.rb: invalid value for `#{key_name}`. Directory does not exist: #{directory}. Set to value to nil or comment it out if #{remove_if}. MSG raise ReactOnRails::Error, msg end
def self.compile(force: false)
- Example: Force regeneration -
Example: Basic usage (skips if up-to-date) -
Raises:
-
(ReactOnRails::Error)- if configured directories do not exist
Returns:
-
(ReactOnRails::Locales::ToJs, ReactOnRails::Locales::ToJson)- the converter instance
Parameters:
-
force(Boolean) -- when true, regenerate even if output files are current
def self.compile(force: false) config = ReactOnRails.configuration check_config_directory_exists( directory: config.i18n_dir, key_name: "config.i18n_dir", remove_if: "not using the React on Rails i18n feature" ) check_config_directory_exists( directory: config.i18n_yml_dir, key_name: "config.i18n_yml_dir", remove_if: "not using this i18n with React on Rails, or if you want to use all translation files" ) if config.i18n_output_format&.downcase == "js" ReactOnRails::Locales::ToJs.new(force: force) else ReactOnRails::Locales::ToJson.new(force: force) end end