简体   繁体   中英

Zend_Translate: how to do a revserse translation

my site is built with Zend framework, and default in English. i have a csv file to translate from english to french : fr.csv

however, the datas in my db are in English. So I want to translate user frontend input from French to English so as to interact with my db. How can I use Zend_translate to do a reverse lookup, ie from french to english ? Or are there any other ways to achieve this?

Usually you don't translate from English to another language, but from IDs (including English) even if the IDs are in English. The reason is, that the IDs should not be full sentences or phrases, but short and meaningful statements, such as Forbidden (with the English translation "You don't have access to this resource", or something like that). With short keys typos are less likely.

If you want to show a formular for translations (as far as I can see that is what you are trying to do), I recommend to just the IDs internally and show the preferred/current translation as label

<?= $this->translate($id) ?><input type="text" name="<?= $id?>" />

You can get the currently defined IDs with Zend_Translate_Adapter::getMessageIds()

<?php foreach ($adapter->getMessageIds() as $id) : ?>
  <?= $this->translate($id) ?><input type="text" name="<?= $id ?>" />
<?php endforeach; ?>

You can use the method for access source data and after search in him what you need and doing a reverse translate, from message to id.

// returns all the complete translation data
$source = $this->translate->getMessages();

$trnslt_id = array_search($qc, $source);

The results:

 print_r($source);
 /* [VETERINARY] => Veterinaria
 [VIDEOGAMES] => Videogiochi
 [VISUALBASIC] => Visual Basic
 [VITICULTURE] => Viticoltura
 [WEBDESIGN] => Web design */

 echo $trnslt_id;
 // WEBDESIGN

Resource: http://framework.zend.com/manual/1.12/en/zend.translate.additional.html

Hope it's help some one, but i have one question, it's a good idea with a big translation file, or it's better create some arrays for this purpose? Thanks and sorry for bad English.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM