text utils for RTL

This commit is contained in:
Pete Matsyburka committed 2024-01-15 02:22:53 +02:00
1 parent 98f5bba832
commit f1ebd8f912
5 files changed
+26 -29

No files matched your search

+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