Kurounin / Pagination

This package allows you to paginate the subscriptions over meteor's collections. It can be used in a Blaze template or in ReactJS.
MIT License
56 stars 22 forks source link

Using i18n-db #60

Closed boboci9 closed 6 years ago

boboci9 commented 6 years ago

Hi,

First of all let me tell you this is a fantastic package, I have used it in all of my projects.

I am now trying to implement translation using the tap:i18n-db package for translating the same collection that I am using with your pagination. For this I would need to change the publication and the subscriptions in the following way. if (Meteor.isServer) { TAPi18n.publish("inventors", function (born_after) { return Inventors.i18nFind({born: {$gt: born_after}}); }); }

if (Meteor.isClient) { TAPi18n.subscribe("inventors", 1800); } Do you have any ideas on how to do this?

Thank you for your help in advance.

Kurounin commented 6 years ago

By looking at the code of tap-i18n-db the publish and subscribe methods send an extra param containing the current client language. You could try doing something similar to this (replicating their functionality): on server side

const Fiber = require("fibers");

publishPagination(Inventors, {
    transform_filters: function (filters, options) {
        // called after filters & dynamic_filters
        this.language = filters.language_tag;
        Fiber.current.language_tag = language_tag;

        return _.omit(filters, 'language_tag') ;
    }
});

on client side

Template.InventorsList.onCreated(function() {
  this.pagination = new Meteor.Pagination(Inventors);
  const pagination = this.pagination;

  this.autorun(function () {
    const currentFilters = pagination.filters();

    pagination.filters(_.extend(
        currentFilters,
        {language_tag: TAPi18n.getLanguage()}
    ));
  });
});

I haven't tested it, so there might be some issues with the code. If you need further help please set-up a demo repository (maybe based on https://github.com/Kurounin/PaginationExample).

boboci9 commented 6 years ago

Thank you very much this works like a charm.