lib/lazier/exceptions.rb in lazier-3.5.7 vs lib/lazier/exceptions.rb in lazier-4.0.0
- old
+ new
@@ -1,6 +1,5 @@
-# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#
@@ -9,17 +8,26 @@
module Exceptions
# This exception is raised to debug code.
class Debug < ::RuntimeError
end
- # This exception is raised from {I18n I18n} if no valid translation are found in the specified path.
+ # This is the handler for the core I18n gem.
+ class TranslationExceptionHandler < ::I18n::ExceptionHandler
+ # :nodoc:
+ def call(exception, locale, key, options)
+ exception.is_a?(::I18n::MissingTranslation) ? raise(exception.to_exception) : super
+ end
+ end
+
+ # This exception is raised from {I18n I18n} if a string is not translatable.
class MissingTranslation < RuntimeError
# Creates a new missing translation exception.
#
- # @param locales [Array] The locales that was requested to load.
- # @param path [String] The path where was request to search for translations.
- def initialize(locales, path)
- super("Unable to load any of the following translation in #{path}: #{locales.join(", ")}.")
+ # @param locale [Array] The locale that was requested to use.
+ # @param message [String] The message that was requested to translate.
+ def initialize(locale, message = nil)
+ locale, message = locale if message.nil?
+ super("Unable to load the translation \"#{message}\" for the locale \"#{locale}\".")
end
end
end
end