Making a variable length list translatable
I want to display a list of values from an array, and have it be
translatable. My translation method of choice is gettext. An example of
what I am trying to do is to turn a variable-length array like:
$array = ('apple', 'plum', 'watermelon', [...]);
into a string like apple, plum and watermelon.
Doing it only in English would not be a problem, but making it
translatable is, because other languages may not necessarily use a comma
to separate values and/or may not have the word "and" without a comma
between the second last and last values. If I knew that the array always
had 3 values, I could easily just do:
sprintf(gettext("%s, %s and %s"), $array[0], $array[1], $array[2]);
The problem is that the array can vary in length. How can I make a
translatable list from a variable-length array?
No comments:
Post a Comment