本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::get方法的具体用法?PHP TranslatorInterface::get怎么用?PHP TranslatorInterface::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Translation\TranslatorInterface
的用法示例。
在下文中一共展示了TranslatorInterface::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translate
/**
* @param string $key
* @param mixed $default
*
* @return mixed
*/
protected function translate($key, $default = false)
{
$string = $this->translator->get($key);
if ($default !== false) {
if ($string == $key) {
return $default;
}
}
return $string;
}
示例2: getAttribute
/**
* Get the displayable name of the attribute.
*
* @param string $attribute
* @return string
*/
protected function getAttribute($attribute)
{
$primaryAttribute = $this->getPrimaryAttribute($attribute);
$expectedAttributes = $attribute != $primaryAttribute ? [$attribute, $primaryAttribute] : [$attribute];
foreach ($expectedAttributes as $expectedAttributeName) {
// The developer may dynamically specify the array of custom attributes
// on this Validator instance. If the attribute exists in this array
// it takes precedence over all other ways we can pull attributes.
if (isset($this->customAttributes[$expectedAttributeName])) {
return $this->customAttributes[$expectedAttributeName];
}
$line = Arr::get($this->translator->get('validation.attributes'), $expectedAttributeName);
// We allow for the developer to specify language lines for each of the
// attributes allowing for more displayable counterparts of each of
// the attributes. This provides the ability for simple formats.
if ($line) {
return $line;
}
}
// When no language line has been specified for the attribute and it is
// also an implicit attribute we will display the raw attribute name
// and not modify it with any replacements before we display this.
if (isset($this->implicitAttributes[$primaryAttribute])) {
return $attribute;
}
return str_replace('_', ' ', Str::snake($attribute));
}
示例3: getLanguageFileKey
/**
* Return the value of input key in the set locale input file (without extension).
*
* @param string $fileName
* @param string $key
* @throws InvalidFileNameException
*
* @return string
*/
public function getLanguageFileKey($fileName, $key)
{
// Check the input file name
if (!$this->checkFileName($fileName)) {
throw new InvalidFileNameException("Input file name is not valid.");
}
return $this->translator->get("{$fileName}.{$key}");
}