Comments (5)
Yes, I stumbled across that issue, too. I like the tag helper approach as it should allow me to just remove the tag helper if/when the official solution is released.
I think, by far, the RouteSegmentCultureProvider
is the best solution, so I'll stick with that. I like the ability to send someone a URL with the page already localized. I have a requirement for the localization to be based off the TLD, for example, mywebsite.wales (to be localized in English) or mywebsite.cymru (to be localized in Welsh). I haven't had the chance to look into that yet with XLocalizer, but I'm hoping I'll be able to follow your advice given here for this project. That can wait until next year though. :)
Cheers
Morgan
from xlocalizer.
Hi Morgan,
The culture fallback behaviour works for the main route that ends with {culture}
param even if there is no culture parameter detected in the request, basically the home page route.
But for all other routes like /en/Dashboard/
there must be a culture param in the request, otherwise the route will not match the pattern in the route table and it will break. There could be some work around for such cases like adding a second route pattern without {culture}
but this will over complicate the routing table.
So if you want to use route value based localization the best solution is to guarantee the presence of {culture}
param in the url to match the relevant route.
Notice:
If the application is using razor pages and controllers the route convention for both must be configured in startup:
.AddMvcOptions((ops) => {
...
ops.Conventions.Insert(0, new RouteTemplateModelConventionMvc());
})
.AddRazorPagesOptions((ops) => {
ops.Conventions.Insert(0, new RouteTemplateModelConventionRazorPages());
})
....
Best regards,
Ziya
from xlocalizer.
Hi Ziya,
Sorry for the delay getting back to you.
Ok that makes sense, thank you. So my understanding is that XLocalizer will only fallback to my default culture if /
is the route. It doesn't work for any other route. And because of this, all URLs must start with /{culture}/
in order for the localization to work as expected when using RouteTemplateModelConventionRazorPages
and/or RouteTemplateModelConventionMvc
. For example /en/Dashboard
will work, but /Dashboard
will not (as designed).
I think in previous projects I had a route of something like {culture=en}/{controller=Home}/{action=Index}/{id?}
, which was causing the behaviour I expected. I'm going to leave it out this time and see how I get on.
Thankfully, I found a nice AnchorTagHelper that, when modified slightly, automatically adds the current culture to the URL. The thought of adding asp-route-culture="@Context.Request.RouteValues["culture"]"
to all of my anchor tags was depressing!
Kind regards,
Morgan
from xlocalizer.
I know that taghelper, and I've used a similar approach for a while, but for now I prefer to manually add the asp-route-culture="@CultureInfo.CurrentCulture.Name
till dotnet team solves this open issue Hopefully we will see the official solution before retiring :)
Kind regards,
Ziya
from xlocalizer.
Meanwhile, if you don't use RouteSegmentCultureProvider
and QueryStringRequestCultureProvider
you will have urls free of {culture}
param, and the localization will work with CookieRequestCultureProvider
depending on culture cookie value.
The downside of this appoarch that it depends on cookies, so if the user has not allowed cookies it will not work properly, additionally you can't share localized URLs.
from xlocalizer.
Related Issues (20)
- Multi-tenancy provider HOT 3
- Adding option to refresh cache memory HOT 3
- AmbiguousActionException when using services.AddMvc().AddXDbLocalizer<TDbContext, TTranslator>() HOT 7
- FluentValidation placeholders with XLocalizer HOT 2
- localize-att- and localize-att-args- HOT 3
- InvalidOperationException: Cache entry must specify a value for Size when SizeLimit is set. HOT 1
- Is it possible to localize <select asp-items />? HOT 4
- XLocalizer.DB database concurrency problem HOT 11
- How to set default culture? HOT 2
- localize-att- in Hyperlinks has forced localize-content HOT 1
- Blazor AddXDbLocalizer HOT 7
- localize-att-* also localize tag's content HOT 4
- RESX file reload at startup HOT 7
- fail: XLocalizer.Resx.ResxResourceProvider[0] HOT 7
- XLocalizer.Resx.ResxResourceProvider HOT 15
- AmbiguousMatchException: The request matched multiple endpoints HOT 10
- Set Arabic as default request culture HOT 2
- FormatException: Input string was not in a correct format. HOT 9
- translating html tags HOT 1
- Configure XLocalizer to use XML files inside an RCL HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xlocalizer.