title: Character encoding of Localizable.strings, generated by genstrings
body: <p>In my "ViewController.swift", I have a localized string:</p>
  
  <pre><code>TheOutLabel.text = NSLocalizedString("hello", comment: "The \"hello\" word")
  </code></pre>
  
  <p>In the Terminal, to generate the "Localizable.strings" file, I typed:</p>
  
  <pre><code>cd Base.lproj/; genstrings ../*.swift; cat Localizable.strings
  </code></pre>
  
  <p>and got the following result:</p>
  
  <pre><code>??/* The \"hello\" word */
  "hello" = "hello";
  </code></pre>
  
  <p>When typing <code>od -c Localizable.strings</code>, I get:</p>
  
  <pre><code>0000000  377 376   /  \0   *  \0      \0   T  \0   h  \0   e  \0      \0
  0000020    \  \0   "  \0   h  \0   e  \0   l  \0   l  \0   o  \0   \  \0
  0000040    "  \0      \0   w  \0   o  \0   r  \0   d  \0      \0   *  \0
  0000060    /  \0  \n  \0   "  \0   h  \0   e  \0   l  \0   l  \0   o  \0
  0000100    "  \0      \0   =  \0      \0   "  \0   h  \0   e  \0   l  \0
  0000120    l  \0   o  \0   "  \0   ;  \0  \n  \0  \n  \0                
  </code></pre>
  
  <p>When I type <code>file Localizable.strings</code>, it says:</p>
  
  <pre><code>Localizable.strings: Little-endian UTF-16 Unicode c program text
  </code></pre>
  
  <p>When I open the file with "emacs", it does not display these characters, and when I type <code>M-x describe-current-coding-system RET</code>, it says:</p>
  
  <pre><code>Coding system for saving this buffer:
    U -- utf-16le-with-signature-unix (alias: utf-16-le-unix)
  </code></pre>
  
  <p>So, it seems that these octal characters \377 and \376 at the beginning of the file look like kind of a utf-16-le BOM, which explains why each character is followed by a \0 (UTF-16 is twice bigger than UTF-8 in this case).</p>
  
  <p>Is this normal/useful/harmful?</p>
  
  <p>Also, the standard *nix tools (<code>grep</code>, <code>sed</code>, <code>awk</code>) don't handle nicely utf-16 files:</p>
  
  <pre><code>grep '=' Localizable.strings 
  Binary file Localizable.strings matches
  
  grep -a '=' Localizable.strings | sed -e 's/ = //'
  "hello" = "hello";
  </code></pre>
  
  <p>Also, I edited Localizable.strings to replace <code>"hello";</code> by <code>"Hello";</code>. Then "SourceTree" (my "git" client) is unable to display the difference unless I do, as proposed in <a href="https://stackoverflow.com/a/21020607/3458802">Can I make git recognize a UTF-16 file as text?</a>:</p>
  
  <pre><code>echo '*.strings diff=localizablestrings' &gt; .../.git/../.gitattributes
  echo '[diff "localizablestrings"]' &gt;&gt; .../.git/config
  echo '  textconv = "iconv -f utf-16 -t utf-8"' &gt;&gt; .../.git/config
  </code></pre>
  
  <p>Apple's <a href="https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/MaintaingYourOwnStringsFiles/MaintaingYourOwnStringsFiles.html#//apple_ref/doc/uid/10000171i-CH19-SW1" rel="nofollow noreferrer">Internationalization and Localization Guide</a> says:</p>
  
  <blockquote>
    <p>Note: If Xcode warns you that the Localizable.strings file appears to
    be Unicode (UtF-16), you can convert it to Unicode (UTF-8) using the
    File inspector.</p>
  </blockquote>
  
  <p>So, should I remove / ignore the BOM?</p>
  
  <p>It seems there is no <code>genstrings</code> option to generate an UTF-8 file.</p>
  
  <p>Should I convert the file?</p>