text utils for RTL

This commit is contained in:
Pete Matsyburka
2024-01-15 01:45:26 +02:00
parent 98f5bba832
commit f1ebd8f912
5 changed files with 26 additions and 29 deletions
+17
View File
@@ -0,0 +1,17 @@
# frozen_string_literal: true
module TextUtils
RTL_REGEXP = /[\p{Hebrew}\p{Arabic}]/
module_function
def maybe_rtl_reverse(text)
if text.match?(RTL_REGEXP)
TwitterCldr::Shared::Bidi
.from_string(ArabicLetterConnector.transform(text), direction: :RTL)
.reorder_visually!.to_s
else
text
end
end
end