digitalascetic / iron-router-i18n

Meteor iron router support for i18n
MIT License
36 stars 5 forks source link

problem with iron-router-i18n and spiderable #61

Closed SierraGolf closed 9 years ago

SierraGolf commented 9 years ago

Hi,

I am having problems bringing together iron-router-i18n with spiderable. If I do not use iron-router-i18n spiderable works as expected. With iron-router-i18n all the language awesomeness works, but I lose the spiderable server-side rendering.

So this is what happens:

  1. I call http://localhost:3000/?_escaped_fragment_=foobar
  2. I see
 Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/foobar."

This is my configuration:

I18NConf.configure({
    defaultLanguage: 'de',
    languages: ['de', 'en'],
    autoConfLanguage: false,
    persistLanguage: false
});

I am using it together with tap:i18n.

Upon initialisation of my client I do this:

Meteor.startup(function () {
    Session.set("languageLoading", true);
});

... and my router.js looks like this:

Router.onBeforeAction(function () {
    TAPi18n.setLanguage(I18NConf.getLanguage()).done(function () {
        Session.set("languageLoading", false);
    });
    this.next();
}, {where: 'server'});

Router.map(function () {
    this.route('/', function () {
        this.render('index');
    });
    this.route('/share', function () {
        this.render('share');
    });
});

Am I missing some configuration? If the above information is not enough, I can provide an example project to demonstrate the problem.

martinopic commented 9 years ago

I'm not sure why you are using that "onBeforeAction" just on the server and why you put TAPi18n language configuration there. Also I guess there actually is a route named "foobar" :-)

It wouldn't be bad to have a sample project showing the problem!

SierraGolf commented 9 years ago

closed by accident

SierraGolf commented 9 years ago

I will create an example project. Btw. bare with me, because I am kinda new to this javascript frontend world.

About your questions:

I guess my question is why does the app think I want to access http://localhost:3000/foobar when I call http://localhost:3000?_escaped_fragment_=foobar, but only when I add the i18n support (router+conf)?

martinopic commented 9 years ago

as for TAPi18n you can configure a I18NConf listener:

I18NConf.onLanguageChange(function(oldLang, newLang) {
  TAPi18n.setLanguage(newLang);
});

This listener will be simply called everytime I18NConf.setLanguage is called manually or anytime is called automatically by Iron Router i18n (e.g. when accessing a route with lang code and/or recognized as a i18n route).

martinopic commented 9 years ago

As for the issue I'll have a look into it, if you can prepare a minimal sample app to show it it would be an helping hand.

martinopic commented 9 years ago

P.S. it's strange that if confirmed would be a strange behavior but why are you using http://localhost:3000/?_escaped_fragment_=foobar instead of http://localhost:3000/foobar?_escaped_fragment_=, a web crawler would use the second one.

SierraGolf commented 9 years ago

Yeah, you are right the example is artificial. To be honest I did not know at the time that there would not be a value for the parameter _escaped_fragment_ and I just put something random there to test the behaviour. Testing with an empty value works as it should and query parameters generally work also as expected. However I did not test with actual hash fragments, because I don't have any (yet).

About the tip with the language change listener. Where is the recommended place to put this? Client, server or both? Btw. I remember now why I did not use it in the first place. In my project the default language for I18nConf is set to "de" and in TAPi18n the default language is hard-coded to "en".

This means when I call my app with localhost:3000/de I18nConf does not detect a change and does not trigger the listener, but my TAPi18n still defaults to "en".

martinopic commented 9 years ago

I'd say both, client and server.

As for TAPi18n having the hardcoded language to "en" I'd just initially set the language to de in a Meteor.startup block and still use the I18NConf listener. There is a ticket I've opened to integrate tapi18n with i18n conf https://github.com/TAPevents/tap-i18n/issues/62

SierraGolf commented 9 years ago

About this issue, since we figured out that it is not really a real life problem, feel free to close this issue.

About the listener problem. When I set the language to "de" in the start block any page request will be using de as language independent from the url language.