Module: Localeapp

Defined in:
lib/localeapp/rails/mimic_rails_missing_translation_display.rb,
lib/localeapp.rb,
lib/localeapp/rails.rb,
lib/localeapp/poller.rb,
lib/localeapp/routes.rb,
lib/localeapp/sender.rb,
lib/localeapp/cli/add.rb,
lib/localeapp/updater.rb,
lib/localeapp/version.rb,
lib/localeapp/api_call.rb,
lib/localeapp/cli/pull.rb,
lib/localeapp/cli/push.rb,
lib/localeapp/i18n_shim.rb,
lib/localeapp/sync_file.rb,
lib/localeapp/api_caller.rb,
lib/localeapp/cli/daemon.rb,
lib/localeapp/cli/remove.rb,
lib/localeapp/cli/rename.rb,
lib/localeapp/cli/update.rb,
lib/localeapp/cli/command.rb,
lib/localeapp/cli/install.rb,
lib/localeapp/key_checker.rb,
lib/localeapp/routes/base.rb,
lib/localeapp/configuration.rb,
lib/localeapp/routes/export.rb,
lib/localeapp/routes/import.rb,
lib/localeapp/routes/remove.rb,
lib/localeapp/routes/rename.rb,
lib/localeapp/routes/projects.rb,
lib/localeapp/rails/controller.rb,
lib/localeapp/exception_handler.rb,
lib/localeapp/routes/translations.rb,
lib/localeapp/missing_translations.rb,
lib/localeapp/routes/missing_translations.rb,
lib/localeapp/rails/force_exception_handler_in_translation_helper.rb

Overview

Rails 3.2.16 and 4.0.2 introduced a new way of displaying missing translation : they now wrap them in a <span> element with useful class and title

github.com/rails/rails/commit/78790e4bceedc632cb40f9597792d7e27234138a

Defined Under Namespace

Modules: ApiCall, CLI, ForceExceptionHandlerInTranslationHelper, MimicRailsMissingTranslationDisplay, Rails, Routes, TranslationHelperRails41MonkeyPatch Classes: APIResponseError, ApiCaller, Configuration, ExceptionHandler, KeyChecker, LocaleappError, MissingApiKey, MissingTranslationRecord, MissingTranslations, Poller, PotentiallyInsecureYaml, RuntimeError, Sender, SyncData, SyncFile, Updater

Constant Summary collapse

API_VERSION =
"1"
LOG_PREFIX =
"** [Localeapp] "
ENV_FILE_PATH =
".env".freeze
VERSION =
"2.2.0"
I18nMissingTranslationException =
I18n::MissingTranslationData

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

An Localeapp configuration object.



42
43
44
# File 'lib/localeapp.rb', line 42

def configuration
  @configuration
end

.missing_translationsObject (readonly)

The missing_translations object is responsible for keeping track of missing translations that will be sent to the backend



55
56
57
# File 'lib/localeapp.rb', line 55

def missing_translations
  @missing_translations
end

.pollerObject

The poller object is responsible for retrieving data for the Localeapp server



48
49
50
# File 'lib/localeapp.rb', line 48

def poller
  @poller
end

.senderObject

The sender object is responsible for delivering formatted data to the Localeapp server.



45
46
47
# File 'lib/localeapp.rb', line 45

def sender
  @sender
end

.updaterObject

The updater object is responsible for merging translations into the i18n backend



51
52
53
# File 'lib/localeapp.rb', line 51

def updater
  @updater
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Localeapp.configure do |config|

config.api_key = '1234567890abcdef'

end

Examples:

Configuration

Yields:



80
81
82
83
84
85
86
87
# File 'lib/localeapp.rb', line 80

def configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
  self.sender  = Sender.new
  self.poller  = Poller.new
  self.updater = Updater.new
  @missing_translations = MissingTranslations.new
end

.debug(message) ⇒ Object



67
68
69
# File 'lib/localeapp.rb', line 67

def debug(message)
  logger.debug(LOG_PREFIX + message) if logger
end

.default_config_file_pathsObject



93
94
95
96
97
98
# File 'lib/localeapp.rb', line 93

def default_config_file_paths
  [
    File.join(Dir.pwd, '.localeapp', 'config.rb'),
    File.join(Dir.pwd, 'config', 'initializers', 'localeapp.rb')
  ]
end

.env_file_pathObject



112
113
114
# File 'lib/localeapp.rb', line 112

def env_file_path
  ENV_FILE_PATH
end

.has_config_file?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/localeapp.rb', line 89

def has_config_file?
  default_config_file_paths.any? { |path| File.exist?(path) }
end

.load_yaml(contents) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/localeapp.rb', line 100

def load_yaml(contents)
  if Localeapp.configuration.raise_on_insecure_yaml
    raise Localeapp::PotentiallyInsecureYaml if contents =~ /!ruby\//
  end

  YAML.load(contents)
end

.load_yaml_file(filename) ⇒ Object



108
109
110
# File 'lib/localeapp.rb', line 108

def load_yaml_file(filename)
  load_yaml(File.read(filename))
end

.log(message) ⇒ Object

Writes out the given message to the #logger



59
60
61
# File 'lib/localeapp.rb', line 59

def log(message)
  logger.info LOG_PREFIX + message if logger
end

.log_with_time(message) ⇒ Object



63
64
65
# File 'lib/localeapp.rb', line 63

def log_with_time(message)
  log [Time.now.to_i, message].join(' - ')
end

.loggerObject

Look for the Rails logger currently defined



72
73
74
# File 'lib/localeapp.rb', line 72

def logger
  self.configuration && self.configuration.logger
end