You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
354 B

  1. # frozen_string_literal: true
  2. class LanguageDetector
  3. attr_reader :text, :account
  4. def initialize(text, account = nil)
  5. @text = text
  6. @account = account
  7. end
  8. def to_iso_s
  9. WhatLanguage.new(:all).language_iso(text) || default_locale.to_sym
  10. end
  11. private
  12. def default_locale
  13. account&.user&.locale || I18n.default_locale
  14. end
  15. end