Internationalization Yii2如何获取翻译消息的长度
在我的项目中,我试图在我的一个模块中提供动态大小调整。我试图在yii2国际化中找出如何获得翻译文本的字符串长度 例如:Internationalization Yii2如何获取翻译消息的长度,internationalization,yii2,strlen,Internationalization,Yii2,Strlen,在我的项目中,我试图在我的一个模块中提供动态大小调整。我试图在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 be
<?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".
?>
现在我怎样才能得到翻译文本的长度呢?我无法在网上找到有关此主题的任何帮助。谢谢你的帮助
谢谢 不,没用。它获取“string(37)”的长度@MISSING:app.Hello FOR LANGUAGE fr@。但我的翻译文件中提供了翻译。当我切换语言时,它会将文本从Hello更改为Bonjour代码>
$translated = Yii::t('app', $name);
var_dump(strlen($translated));