|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-24 08:10 UTC] nico dot weinreich at gmail dot com
Description:
------------
I'm using sprintf() to realize multi language setup of my projects in a simple
way, e.g.:
$l['Stichworte'] = 'Uppslagsord';
$l['Alle %s mit %s'] = 'Alla %s på %s';
Base language is german, target language is swedish. On runtime I'm doing
something like:
echo sprintf(Lang::get("Alle %s mit %s"), Lang::get("Stichworte"), 'K');
So I get for german 'Alle Stichworte mit K' and for swedish 'Alla Uppslagsord på
K'. The problem is, in this context the word 'Uppslagsord' has to be in
lowercase for swedish.
So it would be great, if there are two more type specifiers for sprintf() to
allow text transformation, e.g.:
%s - the argument is treated as and presented as a string
%t - the argument is treated as and presented as a lowercase string
%T - the argument is treated as and presented as a uppercase string
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Easily done in user land. function foo($s) { $args = func_get_args(); return preg_replace_callback('/%(.)/', function($matches) use(&$args) { switch ($matches[1]) { case '%': return '%'; case 's': return next($args); case 't': return mb_convert_case(next($args), MB_CASE_LOWER); case 'T': return mb_convert_case(next($args), MB_CASE_UPPER); } }, $s); } echo foo('Alla %t på %s', 'Uppslagsord', 'K'); -> Alla uppslagsord på K