Note that there are some explanatory texts on larger screens.

plurals
  1. POoverride gettext .mo files
    text
    copied!<p>For translations in our application, we're using <a href="http://framework.zend.com/manual/1.9/en/zend.translate.html">Zend Translate</a> with the gettext adapter. In each module is a folder <code>translations</code>, containing .mo files for all the languages;</p> <ul> <li>da.mo</li> <li>nl.mo</li> <li>en.mo</li> </ul> <p>Which are scanned and added through the <code>addTranslation()</code> method:</p> <pre><code>if ( is_dir( $translations_dir ) ) { foreach ( new DirectoryIterator( $translations_dir ) as $file ) { if ( substr( $file, -3 ) == '.mo' ) { $ZendTranslate-&gt;addTranslation( $file-&gt;getPathname(), $file-&gt;getBasename('.mo') ); } } } </code></pre> <p>The strings in my application are translated using the <code>_()</code> method, passing the current language as a parameter (it's stored in my framework's Language class):</p> <pre><code>$ZendTranslate-&gt;_( $string, $this-&gt;language ); </code></pre> <p>Now I need to customize the Dutch (nl) language strings for a specific customer. I don't want to modify the <code>nl.mo</code> file, as that would affect other customers. So I created a file called <code>nl_kpn.mo</code> (kpn is the customer name), and switched the <code>$this-&gt;language</code> to 'nl_kpn'. I was hoping Zend Transate would take <code>nl.mo</code> as the base file, overriding the customized strings found in <code>nl_kpn.mo</code>. But unfortunately I experienced, as the <a href="http://framework.zend.com/manual/1.9/en/zend.translate.additional.html">manual states</a>: </p> <blockquote> <p>fr_CH will be downgraded to fr</p> </blockquote> <p>So all the strings were still from the <code>nl.mo</code> file, even though <code>$this-&gt;language</code> was set to 'nl_kpn'. So how can I create a more specific version of a language, overriding strings from the general one? It must be possible, right? Because there's also en_UK and en_US, which are different 'dialects' of the same language.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload