grav-plugin-pagination icon indicating copy to clipboard operation
grav-plugin-pagination copied to clipboard

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

Open tranduyhung opened this issue 8 years ago • 6 comments

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+.

tranduyhung avatar Apr 15 '16 04:04 tranduyhung

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.

marcocevoli avatar Aug 02 '20 16:08 marcocevoli

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 avatar Aug 02 '20 16:08 ricardo118

what is your opinion @mahagr @rhukster ?

ricardo118 avatar Aug 02 '20 16:08 ricardo118

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.

mahagr avatar Aug 04 '20 08:08 mahagr

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

ricardo118 avatar Aug 04 '20 09:08 ricardo118

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

WordPress uses only the number of pages.

Sogl avatar Jul 12 '22 16:07 Sogl