module Rodauth
def i18n_add(file)
point, so we prepend built-in translations to the load path to ensure we
User-defined translations have most likely already been loaded at this
def i18n_add(file) ::I18n.load_path.unshift(file) unless ::I18n.load_path.include?(file) end
def i18n_available_locales
def i18n_available_locales ::I18n.available_locales if ::I18n.available_locales_initialized? end
def i18n_default(name, fallback)
def i18n_default(name, fallback) default = [] default << name if i18n_namespace && i18n_cascade? default << fallback if i18n_fallback_to_untranslated? && !i18n_raise_on_missing_translations? default end
def i18n_files(directory)
Returns list of translation files in given directory based on
def i18n_files(directory) locales = i18n_available_locales pattern = locales ? "{#{locales.join(",")}}" : "*" Dir["#{directory}/#{pattern}.yml"] end
def i18n_locale
def i18n_locale ::I18n.locale end
def i18n_namespace
def i18n_namespace self.class.configuration_name end
def i18n_register(directory)
def i18n_register(directory) files = i18n_files(directory) files.each { |file| i18n_add(file) } i18n_reload Rodauth::I18n.directories << directory end
def i18n_reload
def i18n_reload ::I18n.reload! end
def i18n_scope
def i18n_scope "rodauth" end
def i18n_translate(name, default, **options)
def i18n_translate(name, default, **options) ::I18n.translate(i18n_translation_key(name), scope: i18n_scope, locale: i18n_locale, raise: i18n_raise_on_missing_translations?, default: i18n_default(name, default), **i18n_options, **options ) end
def i18n_translation_key(name)
def i18n_translation_key(name) [*i18n_namespace, name].join(".") end
def post_configure
def post_configure super i18n_register File.expand_path("#{__dir__}/../../../locales") end
def translate(name, default)
def translate(name, default) i18n_translate(name, default) end