- Added more filters and custom tags
[haanga.git] / lib / filters / pluralize.php
blob6cac93442edd92ebc4a7233f935778c08704efe2
1 <?php
3 class Pluralize_Filter
5 function generator($compiler, $args)
7 if (count($args) > 1) {
8 if (!isset($args[1]['string'])) {
9 throw new Haanga_CompilerException("pluralize: First parameter must be an string");
11 $parts = explode(",", $args[1]['string']);
12 $singular = "";
13 if (count($parts) == 1) {
14 $plural = $parts[0];
15 } else {
16 $singular = $parts[0];
17 $plural = $parts[1];
19 } else {
20 $singular = "";
21 $plural = "s";
24 return $compiler->expr_cond(
25 $compiler->expr("<=", $args[0], 1),
26 $compiler->expr_str($singular),
27 $compiler->expr_str($plural)