We're using Prawn to generate PDFs, and occasionally we get content in foreign languages like Hebrew that run right-to-left. I can specify text direction in Prawn, but I don't have any way of knowing when the language in question requires it. Is it possible to detect which language text is written in using Ruby, in order to make the appropriate decision about which direction to use?
Using the technique in this answer, I was able to test easily for Hebrew and Arabic at least (requires Ruby 1.9+):
if unknown_text.match(/\p{Hebrew}|\p{Arabic}/)
text_direction = :rtl
end
Another way would be to inspect the Unicode char ranges of the text in question, as described here.