TAPevents / tap-i18n-db

MIT License
51 stars 17 forks source link

Sort on i18n.fa field #29

Open hrhitesh opened 8 years ago

hrhitesh commented 8 years ago

Hello all,

I have an issue with sorting on i18n.fa field. here is my collection format name:"a" "i18n" : { "fa" : { "name" : "fs" } }, name:"c" "i18n" : { "fa" : { "name" : "fa" } }, name:"b" "i18n" : { "fa" : { "name" : "fc" } }

now in my code i used this publication code TAPi18n.publish("name", function () { return Names.i18nFind({}),{sort:{name:1}}); }); and in client side i use this subscriptions TAPi18n.subscribe('name', function() { return Names.i18nFind({}); });

now when i run application it gives alphabetical order "a,b,c" in english language. But when i switch language to "fa" it does not gives order "like fa,fa,fs" instead it gives "fs,fc,fa". Does anyone have solution for this why its not working? Thanks

timbrandin commented 8 years ago

Right now, this is a bug, the quick fix is to hack it and sort by language yourself.

    let lang = TAPi18n.getLanguage();
    // Adding language specific sorting.
    let sorting = lang == 'en' ? { name: 1 } : {
      [`i18n.${lang}.name`]: 1
    };
    return Names.find({
      category: instance.category.get()
    }, {
      sort: sorting
    });