ms-seo icon indicating copy to clipboard operation
ms-seo copied to clipboard

How to handle meta titles and descriptions for multilingual website?

Open calvinfu1128 opened this issue 10 years ago • 2 comments

Regarding the captioned, would adding more fields to SeoCollection and making use of i18n package work?

If not, how should it be handled?

Many thanks.

Calvin

calvinfu1128 avatar Jun 26 '15 07:06 calvinfu1128

I agree :+1:

Should we always use the dynamic SEO.set() for multilingual websites ?

onAfterAction: function() {
    var title = TAPi18n.__('template.contact.page.title');
    var description = TAPi18n.__('template.contact.page.description');

    SEO.set({
        title: title,
        meta: {
            'description': description
        }
    });
}

natalie-natsu avatar Oct 03 '15 19:10 natalie-natsu

Adding a 'lang' field to SeoCollection seems to work well. I just set up the collection and with the help of a little function it now does everything by itself.

Basically in the global onBeforeAction() I call a function called doSeo() which does a look up in SeoCollection, and everything looks like it works. A real test in the wild will be in a couple of weeks when I finally install my app, but at the moment the titles and metas are being set correctly and in the right language.

Router.onBeforeAction(function(){
    var router = this;
    doSEO(router.route.getName());
    this.next();
});

The function itself:

var doSEO = function(routeName){

     if (!Meteor.isClient) {
        return;
     }

    var currentLang = I18NConf.getLanguage();
    if(!currentLang)
        return;

    var seoRecord = SeoCollection.findOne({route_name: routeName, lang: currentLang});

    if(!seoRecord){
        return;
    }

    SEO.set({
        title: seoRecord.title,
        meta: {
            'description': seoRecord.meta.description
        },
        og: {
            'title': seoRecord.title,
            'description': seoRecord.meta.description
        }
    });

};

The only thing I can't work out is what has happened to the default look up which the package does in SeoCollection. There doesn't seem to be a way of turning off the database look up, it's just automatic. I'd like to see a field in seo.config() such as database:false to turn it off since I'm calling the database myself. I suppose I could just change the name of SeoCollection to something of my own choice, if necessary.

mwarren2 avatar Oct 13 '15 15:10 mwarren2