本文整理匯總了PHP中Symfony\Component\Translation\MessageCatalogue::replace方法的典型用法代碼示例。如果您正苦於以下問題:PHP MessageCatalogue::replace方法的具體用法?PHP MessageCatalogue::replace怎麽用?PHP MessageCatalogue::replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Translation\MessageCatalogue
的用法示例。
在下文中一共展示了MessageCatalogue::replace方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testReplace
public function testReplace()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1');
$this->assertEquals($messages, $catalogue->all('domain1'));
}
示例2: validateAndFilter
/**
* @param MessageCatalogue $messageCatalogue
*
* @return bool
*/
protected function validateAndFilter(MessageCatalogue $messageCatalogue)
{
$allMessages = $messageCatalogue->all();
$notTranslatedKeys = [];
$isEmpty = true;
foreach ($allMessages as $domain => $messages) {
foreach ($messages as $key => $value) {
try {
$result = $this->validateMessage($key, $value);
} catch (\Exception $e) {
$result = false;
$notTranslatedKeys[$domain][] = $key;
}
if ($result === false) {
$messages[$key] = false;
continue;
}
}
$cleanMessages = array_filter($messages);
$messageCatalogue->replace($cleanMessages, $domain);
$isEmpty = $isEmpty && empty($cleanMessages);
}
foreach ($notTranslatedKeys as $domain => $messages) {
$this->logger->error(sprintf(' skipped not translated keys in "%s" domain', $domain));
foreach ($messages as $message) {
$this->logger->info(' - ' . $message);
}
}
return $isEmpty;
}