-
Notifications
You must be signed in to change notification settings - Fork 65
Localization no longer works after updating to rc1 #150
Comments
It works fine .. what's the issue you are facing? |
Does not localize the string anymore, console, or in VS Result is Name (key) instead of for example name it-CH Greetings Damien |
I'll check your source later |
Thanks |
Can you let me know which dnx version you are using? |
1.0.0-rc1-final clr x86 win Greetings Damien |
Why you didn't switch to rc2, because I faced another issue in previous versions have a look #147 |
Hi @hishamco I used rc1 because it was released yesterday. Are you saying rc1 has a problem? Greetings Damien |
@damienbod I run the localization sample, and it works fine, are you sure there's no missing piece in your app? |
@ryanbrandenburg Can you please take a look? |
@hishamco, not that I know of. The following URL is no longer localized since the update to rc1 http://localhost:5000/api/about?culture=it-CH DataAnnotations localization still works. All I did was update the project.json, changed the Startup.cs with the breaking changes. You can see this in the history. If I downgrade to beta8, it works. I also tried upgrading to rc2 with no success. Tested in the console. Thanks for your help Greetings Damien |
Now I will clone the repo and test it |
Seems it doesn't work as expected, can you let me know the latest dnx version where you got the right result? |
Hi @hishamco Version 1.0.0-beta8 works as expected. Got it from NuGet (released version) Greetings Damien |
I'm not sure if the issue is cause by #138, but seems @ryanbrandenburg will investigate into this |
Reproduce in rc1 with https://github.com/damienbod/AspNet5Localization, my own test and https://github.com/aspnet/Localization/tree/dev/samples/LocalizationSample. |
Even I it doesn't localize anything with me, but localization sample works fine, i'm not sure if this related to #138 as I mentioned before or there's a bug in mvc localization |
in beta8, culture and uiculture is correct
In rc1 no resx found when i use IStringLocalizer and HtmlLocalizer. |
There are a couple things happening here. One is that the convention you're using doesn’t work well with IHtmlLocalizer. Check out https://github.com/aspnet/Mvc/tree/dev/test/WebSites/LocalizationWebSite for an example of the new way. Basically now instead of having "IHtmlLocalizer" You want to do "IHtmlLocalizer" and have your resource as "AspNet5Localization.Controllers.AboutController..resx". It is POSSIBLE to do the "AmazingResource" method, but it's not recommended. Another part of this is that it's no longer recommended to have a "Default.resx". Instead the "key" of the resource should be the default value for it. So instead of having "Greeting" with a value in the default resx of "Hello" the key is "Hello", which will be returned if no matching language is found. Also for what @Thetyne is talking about, where VS will not localize properly because the resources aren't handled correctly, that's tracked here aspnet/dnx#3047 |
@ryanbrandenburg you are right that's the pattern that we should follow, but if the resource file resident with that same place of the controller issue #138 will happen |
Thanks for your answers. So you’re saying if you want to use the new localization, you have to/should name the resource like the controller with this magic string. Not very nice, or developer friendly. (Just my opinion) I then need to have one resx per controller. So for an application with a 100 controllers and 3 languages I would have 300 resource files. This would be a nightmare. Your recommendation that the key is the default value. This does not work for most of the applications which I am involved in. Most company’s program in English. Most of our applications are translated into de-CH, fr-CH and it-CH, we usually have no default English view. (Switzerland). The default key nearly never matches the default localization. We do not translate the application ourselves, we usually send the keys as a single file to a separate company which translates this for us. This is usually sent as a csv or excel file. This has to be imported and exported so if I have a lot of separate resource files, this costs too much. This issue should be a bug. At present in rc1, this does not work, in beta8, it was ok unlike the linked issue. Maybe you could consider rewriting the use cases for MVC 6 localization, because if it is released as it is, recommended, it will be unusable for most of our applications and for many other company’s which deal in localization regularly. It would mean that I have to re-implement localization, if I want to use ASP.NET 5 for my clients. Thanks and greetings Damien |
@damienbod wrote "I then need to have one resx per controller. So for an application with a 100 controllers and 3 languages I would have 300 resource files." I have found that I can create an empty class in my web app, say I name it LocalizationWebSite.Components.SharedResources.cs
in my controller and I can localize strings from a resx file named
This file lives in the /Resources folder of the web app which we point to from startup
I could use this in multiple controllers, so we are not forced to use a resx file per controller. The problem I have at the moment is I can't seem to get it to work if my controller classes or my resource class are in a class library instead of directly in the web app. If I have a classlibrary named SomeWebLib with a class named CommonResources and in HomeController of the web app I take a dependency on
in the constructor I'm using kestrel from the command line to avoid the known VS 2015 issues. I'm setting my browser language to French while testing. I don't know if these limitations are expected or whether to consider them bugs or whether there is some other approach I'm supposed to use if my controllers and/or resources are in a classlibrary instead of directly in the web app. |
@damienbod, @joeaudette 's suggestion should work for re-using the resource. As for using the default value as the key, you should be able to use the old style of key selection, just know that if it doesn't find a resource for the given key and culture it will default to using the key given. So if your key was "greeting" and you didn't have that set for fr-CH your page would show "greeting". @joeaudette your class library thing sounds like a separate thing, please feel free to file it as a new issue. I think that's everything @damienbod so I'm closing this issue, but let us know if we missed something or you have further questions. |
Thanks for your answer. It should be possible to use a Shared resource without having to create an empty class. Hopefully this is not the recommended way to use shared resources. This is not a good solution, but as least it works. So if I create ten shared resources, I need ten emtpy classes in the project to use the resx files. @joeaudette Thanks for the workaround. As a developer, it should be possible to define how resource files are named and also where the resources are saved. Greetings Damien |
It is also an option to implement your own IStringLocalizerFactory and/or IStringLocalizer with your expected behavior. |
@ryanbrandenburg thanks for reply. I have implement IStringLocalizerFactory and IStringLocalizer for read json file and it's work perfectly. |
@joeaudette @damienbod .. Ran into the same issue as you did and the work around of using an empty class doesn't seem to work when you are using Data annotation to drive model validation in the view |
@jmurkoth it looks like you're using the "Old" style of Resource selection with 'ErrorMessageResourceType'. You're perfectly welcome to do that, but it won't go through the new system which all the Empty class stuff above is intended to work with. If you want to use "ErrorMessageResourceType" you'll have to point it at an old-school "Designer" class. If that doesn't solve you or you run into something else feel free to open a new issue. |
@joeaudette @hishamco @danroth27 @Thetyne @jmurkoth I've just created a global issue for this, could you give your views here? Greetings Damien |
https://github.com/damienbod/AspNet5Localization
Greetings Damien
The text was updated successfully, but these errors were encountered: