forked from leftypol/leftypol
Started on internationalization (i18n)
This commit is contained in:
parent
e8183e7899
commit
ff730c861b
30 changed files with 2584 additions and 103 deletions
45
inc/contrib/Twig/Extensions/Extension/I18n.php
Normal file
45
inc/contrib/Twig/Extensions/Extension/I18n.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
class Twig_Extensions_Extension_I18n extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Returns the token parser instances to add to the existing list.
|
||||
*
|
||||
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(new Twig_Extensions_TokenParser_Trans());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
'trans' => new Twig_Filter_Function('gettext'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'i18n';
|
||||
}
|
||||
}
|
||||
|
72
inc/contrib/Twig/Extensions/Extension/Tinyboard.php
Normal file
72
inc/contrib/Twig/Extensions/Extension/Tinyboard.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Returns a list of filters to add to the existing list.
|
||||
*
|
||||
* @return array An array of filters
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return Array(
|
||||
'filesize' => new Twig_Filter_Function('format_bytes', Array('needs_environment' => false)),
|
||||
'truncate' => new Twig_Filter_Function('twig_truncate_filter', array('needs_environment' => false)),
|
||||
'truncate_body' => new Twig_Filter_Function('truncate', array('needs_environment' => false)),
|
||||
'extension' => new Twig_Filter_Function('twig_extension_filter', array('needs_environment' => false)),
|
||||
'sprintf' => new Twig_Filter_Function('sprintf', array('needs_environment' => false)),
|
||||
'capcode' => new Twig_Filter_Function('capcode', array('needs_environment' => false)),
|
||||
'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter', array('needs_environment' => false)),
|
||||
'date' => new Twig_Filter_Function('twig_date_filter', array('needs_environment' => false)),
|
||||
'poster_id' => new Twig_Filter_Function('poster_id', array('needs_environment' => false)),
|
||||
'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter', array('needs_environment' => false))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'tinyboard';
|
||||
}
|
||||
}
|
||||
|
||||
function twig_remove_whitespace_filter($data) {
|
||||
return preg_replace('/[\t\r\n]/', '', $data);
|
||||
}
|
||||
|
||||
function twig_date_filter($date, $format) {
|
||||
return date($format, $date);
|
||||
}
|
||||
|
||||
function twig_hasPermission_filter($mod, $permission, $board) {
|
||||
return hasPermission($permission, $board, $mod);
|
||||
}
|
||||
|
||||
function twig_extension_filter($value, $case_insensitive = true) {
|
||||
return 'test';
|
||||
$ext = substr($value, strrpos($value, '.') + 1);
|
||||
if($case_insensitive)
|
||||
$ext = strtolower($ext);
|
||||
return $ext;
|
||||
}
|
||||
|
||||
function twig_sprintf_filter( $value, $var) {
|
||||
return sprintf($value, $var);
|
||||
}
|
||||
|
||||
function twig_truncate_filter($value, $length = 30, $preserve = false, $separator = '…') {
|
||||
if (strlen($value) > $length) {
|
||||
if ($preserve) {
|
||||
if (false !== ($breakpoint = strpos($value, ' ', $length))) {
|
||||
$length = $breakpoint;
|
||||
}
|
||||
}
|
||||
return substr($value, 0, $length) . $separator;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue