Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive plugin and multilanguage support #1

Open
marsien opened this issue Oct 25, 2015 · 5 comments
Open

archive plugin and multilanguage support #1

marsien opened this issue Oct 25, 2015 · 5 comments

Comments

@marsien
Copy link

marsien commented Oct 25, 2015

Hi rhukster

As seen on the forum, I have a problem with the archive plugin since I use multilanguage support. My website is in French, so I declared in admin plugin this language (fr), and only this language. Since this change, when I use the archive plugin, there is no results returned for a year or a month. However, the number of articles showed near the links is correct.

With the archive plus plugin, the problem is the same, except that all articles are returned as results whatever the link for years or months.

Thx
Ludo

@rhukster
Copy link
Member

I'm not able to replicate this on my test setup. Question if you rename your item.md (or whatever your blog posts are called) to item.fr.md does it make a difference?

@rhukster
Copy link
Member

Maybe you can zip up a copy of your user/ folder and make it available for me to download? I just tested without the fr in the filename and it made no difference. Just works for me.

@marsien
Copy link
Author

marsien commented Oct 26, 2015

Hi Andy,

You can find the user folder following this link :
http://test.scribavita.fr/user.7z

I tried with item.md or item.fr.md, it is the
same for me. Don't work.

Thx

Le 26/10/2015 01:32, Andy Miller a
  écrit :


  Maybe you can zip up a copy of your user/ folder
    and make it available for me to download? I just tested without
    the fr in the filename and it made no difference.
    Just works for me.
  —
    Reply to this email directly or view
      it on GitHub.

@Sommerregen
Copy link

Haven't seen that this issue is also connected with Archive Plus plugin... that's why I join in and see how I can help you @marsien

@marsien
Copy link
Author

marsien commented Oct 31, 2015

Sorry my late answer.
I try to undestand this problem. And I found the orgin for the archive plugin. I added 2 lines in the function onTwigSiteVariables in àrchives.php` :

$strftime_format = $this->config->get('plugins.archives.strftime_display_format');

$archives[date($date_format, $page->date())]['local_date'] = utf8_encode(strftime($strftime_format, $page->date()));

The final code was:

 public function onTwigSiteVariables()
    {
        /** @var Taxonomy $taxonomy_map */
        $taxonomy_map = $this->grav['taxonomy'];
        $pages = $this->grav['pages'];

        // Get current datetime
        $start_date = time();

        $archives = array();

        // get the plugin filters setting
        $filters = (array) $this->config->get('plugins.archives.filters');
        $operator = $this->config->get('plugins.archives.filter_combinator');

        if (count($filters) > 0) {
            $collection = new Collection();
            $collection->append($taxonomy_map->findTaxonomy($filters, $operator)->toArray());

            // reorder the collection based on settings
            $collection = $collection->order($this->config->get('plugins.archives.order.by'), $this->config->get('plugins.archives.order.dir'));
            $date_format = $this->config->get('plugins.archives.date_display_format');
            $strftime_format = $this->config->get('plugins.archives.strftime_display_format'); // ADDED

            // loop over new collection of pages that match filters
            foreach ($collection as $page) {
                // update the start date if the page date is older
                $start_date = $page->date() < $start_date ? $page->date() : $start_date;

                $archives[date($date_format, $page->date())][] = $page;
                $archives[date($date_format, $page->date())]['local_date'] = utf8_encode(strftime($strftime_format, $page->date())); // ADDED
            }
        }

        // slice the array to the limit you want
        $archives = array_slice($archives, 0, intval($this->config->get('plugins.archives.limit')));

        // add the archives_start date to the twig variables
        $this->grav['twig']->twig_vars['archives_show_count'] = $this->config->get('plugins.archives.show_count');
        $this->grav['twig']->twig_vars['archives_data'] = $archives;
    }

With these 2 lines, I can have months in french language for the archives list. Without, it is in english. Except if there is another way to get months in french...

If I remove these additional lines, the arhcive plugin is OK.

But I have always the same issue with the archive plus plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants