Closed glen-84 closed 9 years ago
Thanks for taking the time to offer so much feedback! Let me say that for our initial version, we intend to keep the feature set small. We can always build it out from there. That said, let me try to address each suggestion:
StringLocalizer
IStringLocalizer
can be turned into a culture specific one easily, which is nice when the primary way people will get them is via DI on that interface, not from the concrete types.IViewLocalizer
has that behavior right now in the sample, but the /Shared/_Layout.cshtml
uses a an IStringLocalizer
directly. Any view can just create an IHtmlLocalizer
from IHtmlLocalizerFactory
for any source they like. We could look at making IViewLocalizer
a little more flexible by looking in multiple places for resources instead of just a file named after the view.ValidationAttribute
is in the .NET Framework and can't really be changed to do something else for validation messages, so this is the best approach we could come up with working within those boundaries.IStringLocalizer
which shows apps would be free to make composition choices like this.IStringLocalizer
is that domain. When you create one from the IStringLocalizerFactory
you can provide a location
which is just a string
that can be used to represent any source. In our default implementation which is based on .NET's ResourceManager
, it represents an AssemblyName
.RequestLocalizationMiddleware
Accept-Language
header). Then there'll be a delegate the app can set to have a chance to change it to whatever it likes, e.g. set from a user profile DB. This is the simplest thing we can do that enables the scenarios. The app is of course free to make its own middleware that does whatever it likes. It just needs to set the culture on the current thread and anywhere else it cares to.CurrentCulture
and/or CurrentUICulture
). Again, it won't be a very complex middleware and could be easily replaced by the app with whatever custom code it likes. We'll make sure things like the Accept-Language
header parsing logic can be easily reused.StringLocalizer
1) Maybe you're right. It's just that for a non-developer, it's very easy to forget a brace, or to add too few/too many placeholders. If it's going to be strict, then developers will need to create a tool to validate the messages before putting them into production.
2) Okay. To be honest, I'm not really familiar with this pattern (creating an instance of a type from an instance of the same/similar type), but it's not important. :smile:
6) "Note that ValidationAttribute is in the .NET Framework and can't really be changed ..." – how does the ErrorMessage get localized? Are you suggesting that you won't be able to use a different type of string formatting, for example?
7) Pretty much. For example, you could have an ILocalizedStringProvider that loads strings from resource files, and then the developer could switch between using regular string formatting, SmartFormat.NET, messageformat.net, etc. I should add caching somewhere as well.
8) It's for grouping messages into logical "domains". For example, you could have a text domain for each MVC area, and one for the application as a whole. If the same message is translated in more than one domain, you could prioritize the messages in the current area, or always favour the application-level translation (depending on your needs). However, I can't really say how important this is, since I haven't used it myself.
RequestLocalizationMiddleware
1) I may write a strategy-based culture selection middleware later, but it's not a very high priority right now. :smile:
2) "We'll make sure things like the Accept-Language header parsing logic can be easily reused." – that would be great.
The localization work is over at https://github.com/aspnet/Localization now
StringLocalizer
ResourceManagerLocalizer(ResourceManager resourceManager, CultureInfo culture = null)
(or two constructors)Dictionary<string, string>
, but this would usually load strings from a data source such as a database, resource files, JSON, CSV, web service, etc. Let me know what you think, and if something like this might be included.RequestLocalizationMiddleware
(some feedback copied from my comment here)