Open imajus opened 8 years ago
Did you solve this @imajus? What is the code you are using to subscribe to that publication?
Personally I've changed the logic so I don't need to search by translated field on the server anymore. Here's what I have:
// server
TAPi18n.publish('Entries.all', function() {
return Entries.i18nFind({});
});
// client
TAPi18n.subscribe('Entries.all');
function getEntities() {
const lang = TAPi18n.getLanguage();
const sort = lang == 'en' ? { name: 1 } : { [`i18n.${lang}.name`]: 1 };
return Entries.find({}, { sort });
}
As you can see I don't use translated field in search query anymore but for sorting option on client only. I bet if you find out how to get current language inside TAPi18n.publish
you'll be able to use the same for your search query.
// server
TAPi18n.publish('Entries.byTitle', function(title) {
const lang = 'en'; //FIXME: maybe this.lang? the latest function argument? something else? must be available somehow
const query = lang == 'en' ? { title } : { [`i18n.${lang}.title`]: title };
return Entries.i18nFind(query);
});
I'm trying to fetch some records using
i18nFind
using translated field in a query, like so:That doesn't work when I choose non-English language in a client. I know there's matched record in database and can fetch it using
News.find({ 'i18n.ru.title': title })
.Does
i18nFind
support this anyway? Maybe I'm just doing something wrong?