getgrav / grav-plugin-pagination

Grav Pagination Plugin
https://getgrav.org
MIT License
27 stars 20 forks source link

Feature request: Ability to localize page's param in URL #16

Open tranduyhung opened 8 years ago

tranduyhung commented 8 years ago

It is great if the plugin gives an option to change "page" param in URL to something else, like for localization.

For example, I would like to have

myblog.com/bai-viet/trang:10

instead of

myblog.com/bai-viet/page:10

"trang" means "page" in my language.

I looked into the code and I was able to change "page" to a different word, but the page's result was only from page 1 and the pagination only activated page 1, I couldn't browse pages 2+.

marcocevoli commented 4 years ago

Hi, I'm also interested in this. I've tried to replace $this->items[$x] = new PaginationPage($x, '/page' . $config->get('system.param_sep') . $x); with $this->items[$x] = new PaginationPage($x, '/'. $grav['language']->translate('PLUGIN_PAGINATION.PAGE') . $config->get('system.param_sep') . $x); in classes/plugin/PaginationHelper.php but I got the same error as @tranduyhung Looking forward to seeing someone taking it from here and suggest a pull request.

ricardo118 commented 4 years ago

Ive looked into this and the problem is here:

    public function currentPage()
    {
        $page = (int)($this->params['page'] ?? 1);

        return max(1, $page);
    }

This function from Grav/Common/Uri is hardchecking the 'page' param. changing it to something like this:

    public function currentPage()
    {
        $page = (int)($this->params[Grav::instance()['language']->translate('PLUGIN_PAGINATION.PAGE')]] ?? 1);

        return max(1, $page);
    }

does work for returning the appropriate page but may have some effects on other things

ricardo118 commented 4 years ago

what is your opinion @mahagr @rhukster ?

mahagr commented 4 years ago

Above does not work as it doesn't change the parameter name in the templates and I don't think that it's used so much either.

I'm not sure if it's best to use translation like that, especially as it gets translated to Chinese etc.. Might be better to use something like PAGE_URL_ATTRIBUTE and add a comment to it what it is used for.

ricardo118 commented 4 years ago

oh yeah theres a couple more modifications that are needed for it to work, we got it working this is the only function thats directly from core. But yeah a diff translation name than just page is better i agree

Sogl commented 2 years ago

Ran into this issue today. Any plans to change this behavior?

WordPress uses only the number of pages.