I would like to create a page that contains just a textarea and placeholder for the output text. The user would enter text into the textarea and while they type (or when the enter button is pressed) the text is translated (or more to the point - swapped out). For example, I might write something like "In my honest opinion", or "to be honest" and that would convert the text to its abbreviated form IMHO and TBH, I thought about doing this with arrays. The text could be searched for the longer strings first, i.e. I thought about have an array of four word phrases, three word phrases, two word ones and a single array of words that can be abbreviated, they could be in "key" => "value" form. Would this work, or would mysql work better?
preguntado el 28 de agosto de 11 a las 00:08
It sounds like you're looking to map full text into abbreviated text. This should work just like actual i18n translation, so any translation implementation would suit.
Even if you don't use Zend Framework, you could look at
Zend_Translate adaptadores to see their supported mapping solutions for a suitable candidate.
Really though, beyond telling you that mapping that
key => value is definitely the way to go; how you store the map is entirely up to you.
$map = array( 'in my honest opinion' => 'IMHO', 'to be honest' => 'TBH' ); // Really simple search/replace $translated = str_replace(array_keys($map), $map, $string_to_translate);
This shows a really simple search/replace, but the complexity of your replacing will depend on the type of input and the type of replacement you expect