Hi all,
In some code I have written, I have a form where I get a series of lists of values into various select boxes, where the select box text options need to be multilanguage-capable. A simple example of the source would be something like this:
<span class="multilang" lang="EN">Yes</span><span class="multilang" lang="FR">Oui</span> <span class="multilang" lang="EN">No</span><span class="multilang" lang="FR">Non</span> <span class="multilang" lang="EN">Prefer not to say</span><span class="multilang" lang="FR">Je préfère ne pas le dire</span>
However, the response value (which goes to an external web service) must only contain the English version. I'd desperately like to avoid having to special case the creation of the arrays for each of these select boxes and hard code all the array keys. Obviously the following would work fine if the external web service accepted the foreign translations:
$rawoptions = explode(PHP_EOL, $sourcedata); $optionsarray = array(); foreach($rawoptions as $value) { $optionsarray[format_string($value)] = format_string($value); }
That would produce this sort of thing in French, for example:
Array ( [Oui] => Oui [Non] => Non [Je préfère ne pas le dire] => Je préfère ne pas le dire )
However, I need an output that is something like this:
Array ( [Yes] => Oui [No] => Non [Prefer not to say] => Je préfère ne pas le dire )
Am I right in thinking that there's no option I can pass to format_string() in order to get a specific language back? I mean, format_string() just applies the filters, I'm assuming it can't manipulate how they are applied.
Does anyone have any suggestions on how to do this in a neat(ish) way, rather than hardcoding the options for every select box?