0

I have lots of files in us-ascii but they should be converted in utf-8

I've tried it with

recode UTF-8 [filename]

and with

iconv -f ascii -t utf8 [filename] > [newfilename]

but when I'm check the file after this with file -bs [filename] ...

What's going wrong? and how can I convert those files correctly? (They are .rb files)

I have to convert those files because my ruby on rails app broke while I have us-ascii files in the project.

UPDATE

Thanks for thos tips, but when I do:

iconv -f ISO-8859-1 -t UTF-8

Like mentioned in the other question ... dosn't have any effect .. same result

text/x-ruby; charset=us-ascii

UPDATE Here is an example whats going wrong:

incompatible character encodings: UTF-8 and ASCII-8BIT

Extracted source (around line #65):


62:   <div id="content">
63:     <%= render :partial => "shared/breadcrumb" %>
64: 
65:     <%= yield  %>
66:   </div>
67:   <div id="footer">
68:     <%= link_to t("navigation.home"), { :controller => :pages, :action    => :home } %>
Felix
  • 5,452
  • 12
  • 68
  • 163
  • Can you not add `# encoding: UTF-8` on the top of each file ? – Pramod Solanky Apr 12 '15 at 06:52
  • possible duplicate of [Force encode from US-ASCII to UTF-8 (iconv)](http://stackoverflow.com/questions/11303405/force-encode-from-us-ascii-to-utf-8-iconv) – Jordan Running Apr 12 '15 at 06:53
  • I've tried to add `# encoding: UTF-8` in all ascii files ... in controller / model it's okay but when I add it in view the application run into errrors.... – Felix Apr 12 '15 at 07:11
  • Please share an example view that led to problems. – Aleksei Matiushkin Apr 12 '15 at 08:17
  • I've added the code snipped into question – Felix Apr 12 '15 at 08:29
  • None of the files seem to have non-ASCII chars in them so your conversion commands won't do anything. If there's no non-ASCII in your document, `file` will always show as ASCII - only when a non-ASCII character is found can `file` work out if it's UTF-8 or an 8bit charset. – Alastair McCormack Apr 12 '15 at 09:37
  • Okay. But what could be the reason of the error? ... – Felix Apr 12 '15 at 09:39
  • If that's the case, I suspect there's an illegal character in the source code that your editor is not showing you. Most editors have a mode to show you "control characters" – Alastair McCormack Apr 12 '15 at 09:39
  • I've checked it ... but I haven't found illegal characters. – Felix Apr 12 '15 at 11:48
  • All ASCII is UTF-8 too, so if your files really are exclusively ascii characters, then converting them to UTF-8 will indeed result in the exact same bytes. And if your file has some bytes in it that are *not* pure ASCII, then you can't just 'convert from ASCII to UTF-8', because you didn't start out with ascii! If you have a non-ascii byte somewhere, you're going to have to figure out where, and what encoding it's really in -- is it really in a source file, or is it coming from the database, or is it coming from user input? Different responses accordingly. – jrochkind Apr 12 '15 at 14:33

0 Answers0