title: Switch gettext translated language with original language
body: <p>I started my PHP application with all text in German, then used gettext to extract all strings and translate them to English.<br>
  So, now I have a .po file with all <em>msgids</em> in German and <em>msgstrs</em> in English. I want to switch them, so that my source code contains the English as <em>msgids</em> for two main reasons:</p>
  
  <ol>
  <li>More translators will know English, so it is only appropriate to serve them up a file with <em>msgids</em> in English. I <em>could</em> always switch the file before I give it out and after I receive it, but naaah.</li>
  <li>It would help me to write English object &amp; function names and comments if the content text was also English. I'd like to do that, so the project is more open to other Open Source collaborators (more likely to know English than German).</li>
  </ol>
  
  <p>I could do this manually and this is the sort of task where I anticipate it will take me more time to write an automated routine for it (because I'm <strong>very</strong> bad with shell scripts) than do it by hand. But I also anticipate despising every minute of <em>manual computer labour</em> (feels like an oxymoron, right?) like I always do.</p>
  
  <p>Has someone done this before? I figured this would be a common problem, but couldn't find anything. Many thanks ahead.</p>
  
  <p>Sample Problem:</p>
  
  <pre><code>&lt;title&gt;&lt;?=_('Routinen')?&gt;&lt;/title&gt;
  
  #: /users/ruben/sites/v/routinen.php:43
  msgid "Routinen"
  msgstr "Routines"
  </code></pre>
  
  <hr>
  
  <p>I thought I'd narrow the problem down. The switch in the .po-file is no issue of course, it is as simple as</p>
  
  <pre><code>preg_replace('/msgid "(.+)"\nmsgstr "(.+)"/', '/msgid "$2"\nmsgstr "$1"/', $str);
  </code></pre>
  
  <p>The problem for me is the routine that searches my project folder files for <code>_('$msgid')</code> and substitutes <code>_('msgstr')</code> while parsing the .po-file (which is probably not even the most elegant way, after all the .po-file contains comments which contain all file paths where the msgid occurs).</p>
  
  <hr>
  
  <p>After <a href="http://pastebin.com/J7ipM1fy" rel="noreferrer">fooling around</a> with akirk's answer a little, I ran into some more problems. </p>
  
  <ol>
  <li>Because I have a mixture of <code>_('xxx')</code> and <code>_("xxx")</code> calls, I have to be careful about (un)escaping.
  
  <ul>
  <li>Double quotes " in msgids and msgstrs have to be unescaped, but the slashes can't be stripped, because it may be that the double quote was also escaped in PHP</li>
  <li>Single quotes have to be escaped when they're replaced into PHP, but then they also have to be changed in the .po-file. Luckily for me, single quotes only appear in English text.</li>
  </ul></li>
  <li>msgids and msgstrs can have multiple lines, then they look like this<br>
   <code>msgid = ""</code><br>
   <code>"line 1\n"</code><br>
   <code>"line 2\n"</code><br>
   <code>msgstr = ""</code><br>
   <code>"line 1\n"</code><br>
   <code>"line 2\n"</code>  </li>
  <li>plural forms are of course skipped at the moment, but in my case that's not an issue</li>
  <li>poedit wants to remove strings as obsolete that seem successfully switched and I have no idea why this happens in (many) cases.</li>
  </ol>
  
  <p>I'll have to stop working on this for tonight. Still it seems using the parser instead of RegExps wouldn't be overkill.</p>