Closed brgrz closed 10 years ago
Ok - I will investigate this.
Another example, possibly a more clear one:
[RoutePrefix("directory")]
public partial class DirectoryController : BaseController
[Route("{id:int}/{slug?}")]
public virtual ActionResult Display(int id, string slug = "")
with this localization
localization.ForCulture("sl-si")
.SetRoutePrefix("imenik")
.ForController<DirectoryController>()
.ForAction(x => x.Display())
.AddTranslation("{id}/{slug}");
and this config:
configuration.AttributeRouteProcessing = AttributeRouteProcessing.AddAsNeutralRoute;
results in two routes (Glimpse):
directory/{id}/{slug} (neutral)
sl-si/imenik/{id}/{slug} (sl-si)
Routes are ok but it picks up the first one for URLs. Which route processing option should I use in this case?
I added #34 for your first issue described. For a workaround you could set Configuration.UseUntranslatedAttributePrefixes to false for now.
What do you mean with "picks up the first one for URLS"?
By that I meant it picked up the first of the two routes generated (the neutral one). Later, I figured out that happened because there was no culture provided in the URL, so it defaulted to the neutral one. I added the "sl-si" identifier and it picked up the 2nd generated route for generating URLs (via Html.Action or ActionLink). I guess I should use one of the culture setting options - the thing is there's an overload of options (I know you are doing your best and I know most are necessary) so I'm a bit cautious to use them because we could run into a bit of collateral effects.
What does Configuration.UseUntranslatedAttributePrefixes
do?
When you don't specify a culture for link generation it trys to pick up the route for the current UI culture - if your are already on an localized route for sl-si, it should work. Guess you were on a neutral one. See Link Generation.
The only reason for adding culture I think of is for "Switch Culture" links.
If you don't specify an RoutePrefix normally the untranslated route prefix from the attribute is taken. This can be prevented by setting Configuration.UseUntranslatedAttributePrefixes:
...
else if (string.IsNullOrEmpty(RoutePrefix) && Configuration.UseUntranslatedAttributePrefixes)
{
// Use untranslated prefix from attribute
RoutePrefix = routePrefixAttribute.Prefix;
}
Please try to use
.AddTranslation("~/{id}/{slug}");
This should now not add any prefixes.
With 2.0.0-alpha-6 this worked:
[RoutePrefix("pages")] public partial class ContentPageController : BaseController { [Route("~/{id:int?}/{slug?}", Order=0)] public virtual ActionResult Display(int id = 0, string slug = "", string culture = "")... }
The routes for content pages resulted in
/en/1/welcome
/sl-si/2/...
Now it adds "pages" prefix for all localized routes, results in
/sl-si/pages/2/...
The thing is, pages are special case. They are not denoted by prefix (although it is set at controller level). The route above does not contain any text to localize because of this special (you can think of it as top level routes) case.
I tried adding
.SetRoutePrefix("")
but didn't help.Now I could remove the prefix at controller but I don't really want to do that.