A variable $status is assigned the string values ‘stop’ or ‘go’ (in php action).
In the view, I would like to display the value of $status in such a way that “stop” is displayed in red and “go” in green.
So I wrote something like:
<span class="<?=$status?>"><?= $status?></span>
and defined classes “stop/go” in my css. Everything works fine until I start making it multi-language by wrapping strings in _() in the action. Now gettext not only translates the actually displayed string but also the class name (which I don’t want). Is there something like ungettext, so that I can write:
<span class="<?=ungettext($status)?>"><?= $status?></span>
and get the untranslated class name?
I realize that I could just send a bool from the action and use an if statement in the view to create what I want. Alternatively (more ugly) I could add translated class names in the css. But is there a more elegant way?
I think you’re over-thinking the problem. Why not simply create another variable in the action, say $status_stye, that you don’t apply the translation to? That way you have both the CSS class you want and the translated version of the text.