adbrosaci / vue-lang-router

Vue language routing with (optional) localized URLs.
MIT License
66 stars 8 forks source link

defaultLanguage not affecting localized URLs from root #12

Closed martlind closed 3 years ago

martlind commented 3 years ago

Hi! I have translations in nl, sv and en and localized URLs in sv. If I put 'sv' as default language the localized URLs isn't getting localized when I'm browsing from http://localhost:8080/, is this intended behavior or am I doing something wrong?

It's working from http://localhost:8080/sv/. The translations are working from both / and /sv.

Vue.use(LangRouter, {
    defaultLanguage: 'sv',
    translations,
    localizedURLs,
})

Thanks, Martin

radek-altof commented 3 years ago

Hi @martlind, this is intended behavior. It is sort of assumed that you configure your project in a way that paths in your router configuration are written in a default language.

When initiating Language Router, the localized URLs are added as aliases to your router configuration object. The original paths are not affected, and I believe it wouldn't be wise to do so. Unfortunately, that's exactly what would be needed in order to solve your problem.

defaultLanguage is what it is - it tells the app which language to use, in case it can't detect it from URL, last browsing session, or browser's preferences.

What comes to my mind as a possible Language Router's improvement is having an option to turn URL localization "always on". That would mean you wouldn't be able to access http://localhost:8080/ at all, but it would always redirect you to some language, in your case http://localhost:8080/sv/.

martlind commented 3 years ago

Hi and thanks! Okay I see. I'm probably doing something stupid here.

We are two developers, one in the Nederlands and me in Sweden, so we are doing everything in english but we don't want to release the site in english, at least not to start with, and the plan is to use localized domain names but we want to use the same code base and set the default language depending on the current domain name.

So for example the swedishdomain.se will have sv as default language. I guess your suggestion would work for us but I think I would prefer if the localized url:s could follow the defaultLanguage so we don't need to have swedishdomain.se/se/.

radek-altof commented 3 years ago

Well, in that case, I don't think this plugin can help you. It's designed to be used on one domain. I'd suggest loading different router configs based on a domain name and loading Vue i18n on your own.

martlind commented 3 years ago

Thanks a lot for your advice, sounds like a good idea!