在我的项目中,我试图在我的一个模块中提供动态大小调整。我想在yii2国际化中弄清楚如何获得翻译文本的字符串长度。
例如:
<?php
//I am getting the name from the database. Assume name to be "Hello"
$name = $gettingNameFrom->db;
//Now $name is equal to string "Hello"
//The below function will dump the output to be int(5) as the length of hello is 5
var_dump(strlen($name));
//Now I want to apply translation to the above name in the db.
// I have all my translation configured and working fine.
echo Yii::t('app','{0}',[$name]);
//I have configured fo french language.
// the above output for "Hello" in french would be "Bonjour".
?>
现在我如何获得翻译文本的长度?我无法在线找到有关此主题的任何帮助。任何帮助赞赏。
谢谢!
答案 0 :(得分:2)
$translated = Yii::t('app', $name);
var_dump(strlen($translated));