나는 ustache를 i18n (php, Wordpress 내)과 함께 사용하려고합니다. 나는 그런 다음 출력에 국제화 문자열 템플릿, 나는 단순히이매개 변수가있는 콧수염 i18n
$context = new mytache;
$template = "<div>{{#__}}String to translate{{/__}}</div>";
$m = new Mustache;
echo $m->render($template, $context);
지금까지 모든 것이 괜찮 할 수있는이
class my_i18n {
public function __trans($string) {
return __($string, 'theme-name');
}
}
class mytache {
public function __()
{
return array('my_i18n', '__trans');
}
}
같은 기본적인 __ 잘 작동 기능, 뭔가있어. 그러나, 나는 매개 변수로 문자열을 번역 할 수 있기를 원한다. 즉 sprint_f(__('Account Balance: %s'), $balance);
에 해당합니다.
내가 {{#__}}Account Balance: {{balance}}{{/__}}
과 같은 것을하면 작동하지 않는 것 같습니다. 내면 태그가 먼저 변환되어 번역문을 찾을 수 없기 때문에 추측하고 있습니다.
콧수염으로 이것을 어떻게 완성 할 수 있습니까?
UPDATE :
class I18nMapper {
public static function translate($str) {
$matches = array();
// searching for all {{tags}} in the string
if (preg_match_all('/{{\s*.*?\s*}}/',$str, &$matches)) {
// first we remove ALL tags and replace with %s and retrieve the translated version
$result = __(preg_replace('/{{\s*.*?\s*}}/','%s', $str), 'theme-name');
// then replace %s back to {{tag}} with the matches
return vsprintf($result, $matches[0]);
}
else
return __($str, 'theme-name');
}
}
class mytache {
public function __()
{
return array('I18nMapper', 'trans');
}
}
"작동하지 않습니다">. < –
콧수염 템플리트에서 문자열을 추출하는 데 사용한 키워드는 무엇입니까? –