class I18n in Bamboo Twig 8.2
Same name and namespace in other branches
- 8.5 bamboo_twig_i18n/src/TwigExtension/I18n.php \Drupal\bamboo_twig_i18n\TwigExtension\I18n
- 8.3 bamboo_twig_i18n/src/TwigExtension/I18n.php \Drupal\bamboo_twig_i18n\TwigExtension\I18n
- 8.4 bamboo_twig_i18n/src/TwigExtension/I18n.php \Drupal\bamboo_twig_i18n\TwigExtension\I18n
Provides some 'Internationalization' Twig Extensions.
Hierarchy
- class \Drupal\bamboo_twig\TwigExtension\TwigExtensionBase extends \Drupal\bamboo_twig\TwigExtension\Twig_Extension uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
- class \Drupal\bamboo_twig_i18n\TwigExtension\I18n
Expanded class hierarchy of I18n
1 string reference to 'I18n'
- bamboo_twig_i18n.services.yml in bamboo_twig_i18n/
bamboo_twig_i18n.services.yml - bamboo_twig_i18n/bamboo_twig_i18n.services.yml
1 service uses I18n
File
- bamboo_twig_i18n/
src/ TwigExtension/ I18n.php, line 11
Namespace
Drupal\bamboo_twig_i18n\TwigExtensionView source
class I18n extends TwigExtensionBase {
/**
* List of all Twig functions.
*/
public function getFilters() {
return [
new \Twig_SimpleFilter('bamboo_i18n_format_date', [
$this,
'formatDate',
], [
'needs_environment' => TRUE,
]),
];
}
/**
* List of all Twig functions.
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('bamboo_i18n_current_lang', [
$this,
'getCurrentLanguage',
]),
];
}
/**
* Unique identifier for this Twig extension.
*/
public function getName() {
return 'bamboo_twig_i18n.twig.i18n';
}
/**
* Retrieve the current language.
*/
public function getCurrentLanguage() {
return $this
->getLanguageManager()
->getCurrentLanguage()
->getId();
}
/**
* Render a custom date format with Twig.
*
* Use the internal helper "format_date" to render the date
* using the current language for texts.
*
* @param \Drupal\Core\Template\TwigEnvironment $env
* A Twig_Environment instance.
* @param int|string|DateTime $date
* A string, integer timestamp or DateTime object to convert.
* @param string $type
* (optional) The format to use, one of:
* - One of the built-in formats: 'short', 'medium',
* 'long', 'html_datetime', 'html_date', 'html_time',
* 'html_yearless_date', 'html_week', 'html_month', 'html_year'.
* - The name of a date type defined by a date format config entity.
* - The machine name of an administrator-defined date format.
* - 'custom', to use $format.
* Defaults to 'medium'.
* @param string $format
* (optional) If $type is 'custom', a PHP date format string suitable for
* input to date(). Use a backslash to escape ordinary text, so it does not
* get interpreted as date format characters.
* @param string|null $timezone
* (optional) Time zone identifier, as described at
* http://php.net/manual/timezones.php Defaults to the time zone used to
* display the page.
* @param string|null $langcode
* (optional) Language code to translate to. NULL (default) means to use
* the user interface language for the page.
*
* @return string|null
* A translated date string in the requested format. Since the format may
* contain user input, this value should be escaped when output.
*/
public function formatDate(TwigEnvironment $env, $date, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
$date = twig_date_converter($env, $date);
if ($date instanceof \DateTime) {
return $this
->getDateFormatter()
->format($date
->getTimestamp(), $type, $format, $timezone, $langcode);
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
I18n:: |
public | function | Render a custom date format with Twig. | |
I18n:: |
public | function | Retrieve the current language. | |
I18n:: |
public | function | List of all Twig functions. | |
I18n:: |
public | function | List of all Twig functions. | |
I18n:: |
public | function |
Unique identifier for this Twig extension. Overrides TwigExtensionBase:: |
|
TwigExtensionBase:: |
protected | function | Return the block storage. | |
TwigExtensionBase:: |
protected | function | Provides an interface for a configuration object factory. | |
TwigExtensionBase:: |
protected | function | Return the current route match. | |
TwigExtensionBase:: |
protected | function | Lazy loading for the Drupal current user account proxy. | |
TwigExtensionBase:: |
protected | function | Provides a service to handle various date related functionality. | |
TwigExtensionBase:: |
protected | function | Lazy loading for the Drupal entity type manager. | |
TwigExtensionBase:: |
protected | function | Return a singleton mime type to file extension guesser. | |
TwigExtensionBase:: |
protected | function | Return the factory for image objects. | |
TwigExtensionBase:: |
protected | function | Return the file storage. | |
TwigExtensionBase:: |
protected | function | Provides helpers to operate on files and stream wrappers. | |
TwigExtensionBase:: |
protected | function | Provides an interface for form building and processing. | |
TwigExtensionBase:: |
protected | function | Return the factory for image objects. | |
TwigExtensionBase:: |
protected | function | Provides an interface defining an image style. | |
TwigExtensionBase:: |
protected | function | Returns the language manager service. | |
TwigExtensionBase:: |
protected | function | Interface for loading, transforming and rendering menu link trees. | |
TwigExtensionBase:: |
protected | function | Manages discovery and instantiation of block plugins. | |
TwigExtensionBase:: |
protected | function | Read only settings singleton. | |
TwigExtensionBase:: |
protected | function | The state storage service. | |
TwigExtensionBase:: |
protected | function | Return the token service. | |
TwigExtensionBase:: |
protected | function | Return the user storage. |