Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faker::Internet::fix_umlauts(String) does not clear all special characters #39

Closed
jensb opened this issue Oct 3, 2011 · 3 comments
Closed

Comments

@jensb
Copy link

jensb commented Oct 3, 2011

Hello,

fix_umlauts is currently implemented this way:

  def fix_umlauts(string)
    string.gsub(/[äöüß]/i) do |match|
        case match.downcase
            when "ä" 'ae'
            when "ö" 'oe'
            when "ü" 'ue'
            when "ß" 'ss'
        end
    end
  end

This should be extended so that characters like é, â, ç etc. are also replaced with their respective non-accented variants. E.g.

  def fix_umlauts(string)
    string.gsub(/[äöüß]/i) do |match|
        case match.downcase
            when "ä" 'ae'
            when "ö" 'oe'
            when "ü" 'ue'
            when "ß" 'ss'
        end
    end
    string.parameterize     # requires Rails ActiveSupport, however
  end
@jensb
Copy link
Author

jensb commented Oct 3, 2011

PS: related discussion: http://stackoverflow.com/questions/225471/how-do-i-replace-accented-latin-characters-in-ruby

This is not about pronounciation or meaning, however - the problem is that currently Faker::Internet.domain_name and .email create strings which are not valid, because in email addresses at least, non-ASCII strings are forbidden (and domain names would need to be punycoded).

@ryanhageman
Copy link

I tried to recreate this issue with Faker::Internet.email and the characters like é å ∑ ø were stripped out of the string.

Though this isn't a substitution, it does remove the offending forbidden characters.

Is this resolved, or would it be better to implement something like:

[1] pry(main)> I18n.transliterate("skägget i brevlådan")
=> "skagget i brevladan"

[2] pry(main)> I18n.transliterate("Esta cañón.")
=> "Esta canon."

@bpleslie
Copy link
Member

I think this can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants