-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Github Actions Workflow
committed
Aug 19, 2020
1 parent
4109986
commit 863e5ac
Showing
1 changed file
with
46 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
<?php | ||
|
||
namespace Drupal\acdh_repo_gui\TwigExtension; | ||
|
||
class ArcheTwigDateExtension extends \Twig_Extension { | ||
|
||
public function getFilters() { | ||
return [ new \Twig_SimpleFilter('archeTranslateDateFilter', function($value, $dateformat){ | ||
(isset($_SESSION['language'])) ? $lang = strtolower($_SESSION['language']) : $lang = "en"; | ||
|
||
$dateformat = $this->extendDateFormat($dateformat); | ||
|
||
if($lang == 'de') { | ||
setlocale( LC_TIME , 'de_DE.utf8'); | ||
return strftime($dateformat, strtotime($value)); | ||
} else { | ||
setlocale( LC_TIME , 'en_US.utf8'); | ||
return strftime($dateformat, strtotime($value)); | ||
} | ||
}) | ||
]; | ||
|
||
} | ||
|
||
/** | ||
* Gets a unique identifier for this Twig extension. | ||
*/ | ||
public function getName() { | ||
return 'acdh_repo_gui.twig_extension'; | ||
} | ||
|
||
/** | ||
* change the datefomat to work with strftime | ||
* | ||
* @param string $dateformat | ||
* @return string | ||
*/ | ||
private function extendDateFormat(string $dateFormat): string { | ||
$search = array('Y', 'y', 'M', 'm', 'D', 'd'); | ||
$replace = array('%Y', '%y', '%b', '%m', '%d', '%d'); | ||
|
||
return str_replace($search, $replace, $dateFormat); | ||
} | ||
|
||
} | ||
<?php | ||
|
||
namespace Drupal\acdh_repo_gui\TwigExtension; | ||
|
||
class ArcheTwigDateExtension extends \Twig_Extension | ||
{ | ||
public function getFilters() | ||
{ | ||
return [ new \Twig_SimpleFilter('archeTranslateDateFilter', function ($value, $dateformat) { | ||
(isset($_SESSION['language'])) ? $lang = strtolower($_SESSION['language']) : $lang = "en"; | ||
|
||
$dateformat = $this->extendDateFormat($dateformat); | ||
|
||
if ($lang == 'de') { | ||
setlocale(LC_TIME, 'de_DE.utf8'); | ||
return strftime($dateformat, strtotime($value)); | ||
} else { | ||
setlocale(LC_TIME, 'en_US.utf8'); | ||
return strftime($dateformat, strtotime($value)); | ||
} | ||
}) | ||
]; | ||
} | ||
|
||
/** | ||
* Gets a unique identifier for this Twig extension. | ||
*/ | ||
public function getName() | ||
{ | ||
return 'acdh_repo_gui.twig_extension'; | ||
} | ||
|
||
/** | ||
* change the datefomat to work with strftime | ||
* | ||
* @param string $dateformat | ||
* @return string | ||
*/ | ||
private function extendDateFormat(string $dateFormat): string | ||
{ | ||
$search = array('Y', 'y', 'M', 'm', 'D', 'd'); | ||
$replace = array('%Y', '%y', '%b', '%m', '%d', '%d'); | ||
|
||
return str_replace($search, $replace, $dateFormat); | ||
} | ||
} |