Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Gettext is good for its ease of translation, but the default PHP implementation is not thread safe. Yii therefore uses its own unpacker, dramatically increasing processing time compared to php arrays.</p> <p>Since I was setting up a high volume, high transaction site, the performance hit was not acceptable. Also, by using APC, we could cache the PHP translation further increasing performance.</p> <p>My approach was therefore to use PHP arrays but to keep the translations in a DB for ease of translation, generating the needed files when translations are changed.</p> <p>The DB is similar to this :</p> <pre><code>TABLE Message // stores source language, updated by script id INT UNSIGNED category VARCHAR(20) // first argument to Yii::t() key TEXT // second argument to Yii::t() occurences TINYINT UNSIGNED // number of times found in sources TABLE MessageTranslation // stores target language, translated by human id INT UNSIGNED language VARCHAR(3) // ISO 639-1 or 639-3, as used by Yii messageId INT UNSIGNED // foreign key on Message table value TEXT version VARCHAR(15) creationTime TIMESTAMP DEFAULT NOW() lastModifiedTime TIMESTAMP DEFAULT NULL lastModifiedUserId INT UNSIGNED </code></pre> <p>I then modified the CLI tool yiic 'message' command to dump the collected strings into the DB.</p> <p><a href="http://www.yiiframework.com/wiki/41/how-to-extend-yiic-shell-commands/" rel="noreferrer">http://www.yiiframework.com/wiki/41/how-to-extend-yiic-shell-commands/</a></p> <p>Once in the DB, a simple CMS can be setup to provide translators an easy way to translate and at the same time providing versioning information, reverting to older versions, checking quality of translators, etc ...</p> <p>Another script, also modified from yiic, then takes the DB info and compiles it into PHP arrays. Basically a JOIN of the two tables for each language, then build an array using 'Message'.'key' and 'MessageTranslation'.'value' as (what else?) key => value ... saving to file named from 'Message'.'category' in folder specified by language.</p> <p>The generated files are loaded as normal by Yii CPhpMessageSource.</p> <p>For images, this was as simple as placing them in folders with the proper language and getting the app language when linking.</p> <pre><code>&lt;img src="/images/&lt;?php echo Yii::app()-&gt;language; ?&gt;/help_button.png"&gt; </code></pre> <p>Note that in real life, I wrote a little helper method to strip off the country from the language string, 'en_us' should be 'en'.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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