gilsdav / ngx-translate-router

Translate routes using ngx-translate
131 stars 43 forks source link

Can it be used with ssr + subdomain? #100

Closed ozergul closed 3 years ago

ozergul commented 3 years ago

Hello. Thanks for the great package! I wonder that this package can be used at SSR and subdomain strategy?

gilsdav commented 3 years ago

Hello, When you mean "subdomain strategy", do you mean fr.mydomain.com ?

You can play with:

The result will be:

What does it mean ?

Why is it cool to have this feature and not only switch to other domain ? It allows you to switch langs at runtime. Change lang while filling out a form? No problem, no page refresh is needed.

ozergul commented 3 years ago

Looks fantastic. Lets give it a try!

ozergul commented 3 years ago

I tried your saids and worked like a charm. But what if I wamt to not show default language. For example: mydomain.com -> EN fr.mydomin.com -> FR pt.mydomain.com -> PT

gilsdav commented 3 years ago

It's simple as "no language found is EN". I don't know what you did into the part "// do stuff with hostname and languages" but if you used a regexp like /^(\w+).mydomain.com$/, you just have to set a default lang when none are found.

const langMatch = hostname.match(/^(\w+).mydomain.com$/);
const langFound = langMatch ? langMatch[1].toUpperCase() : 'EN';