Created
September 20, 2012 22:02
-
-
Save brentvatne/3758614 to your computer and use it in GitHub Desktop.
truncate by locale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TruncationHelper | |
# Not all character sizes are equal, 120 characters of English text | |
# could take up a lot more screen space than 120 characters of | |
# Chinese text. | |
def locale_aware_truncate(text, options) | |
length = case I18n.locale | |
when :ja, :zh | |
options[:length][I18n.locale] || options[:length][:en] / 2 | |
else | |
options[:length][:en] | |
end | |
truncate(text, length: length) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment