about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/language_detector.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb
new file mode 100644
index 000000000..b6f81923b
--- /dev/null
+++ b/app/lib/language_detector.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class LanguageDetector
+  attr_reader :text, :account
+
+  def initialize(text, account = nil)
+    @text = text
+    @account = account
+  end
+
+  def to_iso_s
+    WhatLanguage.new(:all).language_iso(text) || default_locale.to_sym
+  end
+
+  private
+
+  def default_locale
+    account&.user&.locale || I18n.default_locale
+  end
+end