• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 5171156489

pending completion
5171156489

push

github

web-flow
feat: add i18n support to taxonomy (#1711)

62 of 62 new or added lines in 4 files covered. (100.0%)

2803 of 3402 relevant lines covered (82.39%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/Generator/Taxonomy.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Generator;
15

16
use Cecil\Collection\Page\Page;
17
use Cecil\Collection\Page\Type;
18
use Cecil\Collection\Taxonomy\Vocabulary;
19

20
/**
21
 * Class Generator\Taxonomy.
22
 */
23
class Taxonomy extends AbstractGenerator implements GeneratorInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function generate(): void
29
    {
30
        foreach ($this->config->getLanguages() as $lang) {
1✔
31
            $language = $lang['code'];
1✔
32
            if ($this->config->get('taxonomies', $language, false) && $this->builder->getTaxonomies($language) !== null) {
1✔
33
                /** @var Vocabulary $vocabulary */
34
                foreach ($this->builder->getTaxonomies($language) as $vocabulary) {
1✔
35
                    $plural = $vocabulary->getId();
1✔
36
                    $singular = $this->config->get("taxonomies.$plural", $language, false);
1✔
37
                    if (\count($vocabulary) > 0) {
1✔
38
                        $date = date('Y-m-d');
1✔
39
                        /*
40
                        * Creates $plural/$term pages (list of pages)
41
                        * e.g.: /tags/tag-1/
42
                        */
43
                        foreach ($vocabulary as $term) {
1✔
44
                            $pageId = $path = Page::slugify($term->getId());
1✔
45
                            if ($language != $this->config->getLanguageDefault()) {
1✔
46
                                $pageId = "$language/$pageId";
1✔
47
                            }
48
                            $pages = $term->sortByDate();
1✔
49
                            $date = $pages->first()->getVariable('date');
1✔
50
                            $page = (new Page($pageId))
1✔
51
                                ->setPath($path)
1✔
52
                                ->setVariable('title', $term->getName())
1✔
53
                                ->setVariable('date', $date)
1✔
54
                                ->setVariable('language', $language);
1✔
55
                            if ($this->builder->getPages()->has($pageId)) {
1✔
56
                                $page = clone $this->builder->getPages()->get($pageId);
×
57
                            }
58
                            /** @var Page $page */
59
                            $page
1✔
60
                                ->setType(Type::TERM)
1✔
61
                                ->setPages($pages)
1✔
62
                                ->setVariable('term', $term->getId())
1✔
63
                                ->setVariable('plural', $plural)
1✔
64
                                ->setVariable('singular', $singular);
1✔
65
                            $this->generatedPages->add($page);
1✔
66
                        }
67
                        /*
68
                        * Creates $plural pages (list of terms)
69
                        * e.g.: /tags/
70
                        */
71
                        $pageId = $path = Page::slugify($plural);
1✔
72
                        if ($language != $this->config->getLanguageDefault()) {
1✔
73
                            $pageId = "$language/$pageId";
1✔
74
                        }
75
                        $page = (new Page($pageId))
1✔
76
                            ->setType(Type::VOCABULARY)
1✔
77
                            ->setPath($path)
1✔
78
                            ->setTerms($vocabulary)
1✔
79
                            ->setVariable('title', ucfirst($plural))
1✔
80
                            ->setVariable('date', $date)
1✔
81
                            ->setVariable('language', $language)
1✔
82
                            ->setVariable('plural', $plural)
1✔
83
                            ->setVariable('singular', $singular);
1✔
84
                        // adds page only if a template exist
85
                        try {
86
                            $this->generatedPages->add($page);
1✔
87
                        } catch (\Exception $e) {
×
88
                            printf("%s\n", $e->getMessage());
×
89
                            unset($page); // do not adds page
×
90
                        }
91
                    }
92
                }
93
            }
94
        }
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc