turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

Base path for localized URLs #294

Closed hognevevle closed 7 years ago

hognevevle commented 7 years ago

Hi!

First of all, many thanks for creating such an awesome project!

We are working on a new web project in my organization, which will be located in a subdirectory. As the company web site (located on the root domain) is a different project, this causes some issues with the localized URLs, as the language tag is appended before the subdirectory of our new project.

Example: Our company website is at https://domain.tld. Our new project is at https://domain.tld/newapplication. Localized URLs are generated as https://domain.tld/en-US/newapplication/someresource.

In our production environment, we have a series of nginx servers that proxies requests to the appropriate backend server, based on the URL. Therefore, we would very much like to keep everything related to this new project under the subdomain alltogether.

Is there an easy way of overriding this default behaviour, i.e. specify some "base URL"? As you can understand, we would rather have the localized URLs generated as https://domain.tld/newapplication/en-US/someresource.

Please, let me know if I can provide any additional information.

turquoiseowl commented 7 years ago

Currently there's no support for what you ask I'm afraid.

However, it should be possible to achieve fairly simply. See the IUrlLocalizer interface. You can either extend the default implementation of that interface (UrlLocalizer) which would make a nice pull request, or derive your own and inject that (via LocalizedApplication.Current.RootServices).

hognevevle commented 7 years ago

Thanks Martin,

Actually, after some light digging, I found the following property which seems to do the trick:

i18n.LocalizedApplication.Current.ApplicationPath = "/newapplication";

After setting that value, URLs are indeed generated as https://domain.tld/newapplication/en-US/someresource - just what we needed. Unless this results in some other ramifications (which I'm not seeing) we should be all good :)

turquoiseowl commented 7 years ago

Whoops, I forgot about that. I've updated the readme accordingly. Thanks.