From 71b026bc01199583f2dcbc748f8c3c474e571a1d Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Mon, 7 Mar 2016 17:07:36 -0300 Subject: [PATCH] FIX: Properly downcase unicode chars Fix to https://meta.discourse.org/t/title-prettify-does-not-correctly-lowercase-non-english-characters-when-removing-all-caps/16645 This adds a dependency on Active Support Multibyte to downcase on other languages. --- lib/text_cleaner.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/text_cleaner.rb b/lib/text_cleaner.rb index 6d621ec9fba..656fba28f05 100644 --- a/lib/text_cleaner.rb +++ b/lib/text_cleaner.rb @@ -1,6 +1,10 @@ # # Clean up a text # + +# Whe use ActiveSupport mb_chars from here to properly support non ascii downcase +require 'active_support/core_ext/string/multibyte' + class TextCleaner def self.title_options @@ -27,7 +31,7 @@ class TextCleaner # Replace ????? with a single ? text.gsub!(/\?+/, '?') if opts[:deduplicate_question_marks] # Replace all-caps text with regular case letters - text.tr!('A-Z', 'a-z') if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase) + text = text.mb_chars.downcase if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase) # Capitalize first letter, but only when entire first word is lowercase text.sub!(/\A([a-z]*)\b/) { |first| first.capitalize } if opts[:capitalize_first_letter] # Remove unnecessary periods at the end