I have a really complex situation when I need both static localization with dynamic localization in a project I'm working on.
What I need to localize:
- Static pages (like: "About", "Help", "Contact"...)
For example:
"domain.com/about" - For English localization.
"domain.com/es-es/about" - For Spanish localization.
This is where I'm now, and it's working.
Currently the culture is provided and specified in the routing mechanism (best for SEO), and not stored in a cookie or session.
RouteConfig.cs looks like this:
// Localized Default:
routes.MapRoute(
name: "LocalizedDefault",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { culture = new CultureRouteConstraint() }
);
// Default:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { culture = "en-us", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
- Dynamic pages - content users enter in their profile (like: "Full Name", "About"...)
Now here is what I have problem with...
Basically I need to allow users to enter many translations of their profile, and also pick the right translation for the user visiting the profile. In addition, if a user visiting a profile that the user didn't provide a translation for his language, I need to show him a "default" translation, but the site interface will remain in his language.
So, my approach for this:
For dynamic pages, I think I need a help from a cookie, that contains the user's culture, and eliminate the {culture} route parameter in the URL, the site interface localization will be determined from the cookie or browser (user-languages) when there's no cookie. And the content localization will be determined from a route parameter in the end of the URL "{content}".
For Example:
"domain.com/user/username" - For Default content localization (the language the user will set as default).
"domain.com/user/username/en-us" - For English content localization.
"domain.com/user/username/es-es" - For Spanish content localization.
I reached the following conclusions:
• For anonymous users = for static pages the localization is determined by the {culture} route parameter in the URL, but for dynamic pages the {culture} parameter is eliminated, the site interface is determined from a cookie and the {content} parameter in the end of the URL stands for the content localization.
• For authenticated users = for all pages (static & dynamic) the localization is determined only by the cookie, this makes a short & friendly URL and SEO is not affected.
Is this approach acceptable?
I can't figure what is the best practice solution in order to implement that, while preserving SEO, and friendly / easy URL?
BTW - I'm focusing on URL and SEO, database and other concerns are well performed.
Thank you!