Skip to content

Instantly share code, notes, and snippets.

@brentvatne
Created September 20, 2012 22:02
Show Gist options
  • Save brentvatne/3758614 to your computer and use it in GitHub Desktop.
Save brentvatne/3758614 to your computer and use it in GitHub Desktop.
truncate by locale
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