I'm having an issue where I cannot get GetTextNet to find any of my resource files that are for a specific culture (for example, fr-CA) in ASP.NET.
The problem seems to be coming from GettextResourceManager.GetSatelliteAssembly(), around like 152 of intl.cs. It attempts to get a satellite assembly first, which always fails in ASP.NET (to my knowledge), because of the fact that the files are copied into some random temporary folder for IIS and the file locations are not preserved. So, it runs the second part, which tries to load the embedded resource. I added the resource dll files as embedded resources, in the proper folder (for example, "{Assembly}/fr-CA/{AssemblyName}.Messages.resources.dll"), so that the name of the embedded resource would match what is specified in that GetSatelliteAssembly class, but I can never get it to match completely for specific cultures without changing the code. Resource names cannot have a dash character in them -- .NET converts it to a _ automatically. However, the culture.Name always has a -, fr-CA, so the resource (which always changes the name to fr_CA) never matches id we are looking for (with a dash).
I was able to fix the issue by changing the code to generate the embeddedResourceId to use culture.Name.Replace('-','_') instead of just culture.Name, which works perfectly.
Does that make sense? Do you know of a different way to get embedded resources with specific culture+region names to work in ASP.NET, without changing the GetTextNet code?
Thank you!
-Aaron
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yup, I do have the dlls Build action set to embedded, "Copy if newer", and the folder structure is correct. But, it still won't ever pick up the resource, because the name will never match. The code is expecting a dash (-) in the name (because culture.Name produces something like en-US or fr-CA), which .NET will never allow:
Hi,
I'm having an issue where I cannot get GetTextNet to find any of my resource files that are for a specific culture (for example, fr-CA) in ASP.NET.
The problem seems to be coming from GettextResourceManager.GetSatelliteAssembly(), around like 152 of intl.cs. It attempts to get a satellite assembly first, which always fails in ASP.NET (to my knowledge), because of the fact that the files are copied into some random temporary folder for IIS and the file locations are not preserved. So, it runs the second part, which tries to load the embedded resource. I added the resource dll files as embedded resources, in the proper folder (for example, "{Assembly}/fr-CA/{AssemblyName}.Messages.resources.dll"), so that the name of the embedded resource would match what is specified in that GetSatelliteAssembly class, but I can never get it to match completely for specific cultures without changing the code. Resource names cannot have a dash character in them -- .NET converts it to a _ automatically. However, the culture.Name always has a -, fr-CA, so the resource (which always changes the name to fr_CA) never matches id we are looking for (with a dash).
I was able to fix the issue by changing the code to generate the embeddedResourceId to use culture.Name.Replace('-','_') instead of just culture.Name, which works perfectly.
Does that make sense? Do you know of a different way to get embedded resources with specific culture+region names to work in ASP.NET, without changing the GetTextNet code?
Thank you!
-Aaron
Hi Aaron,
Do you embed the resources as described in this thread :
http://sourceforge.net/p/gettextnet/discussion/general/thread/38fbd778/
Yup, I do have the dlls Build action set to embedded, "Copy if newer", and the folder structure is correct. But, it still won't ever pick up the resource, because the name will never match. The code is expecting a dash (-) in the name (because culture.Name produces something like en-US or fr-CA), which .NET will never allow:
http://stackoverflow.com/questions/14705211/how-is-net-renaming-my-embedded-resources
(Notice that dash (-) is in the list of invalid characters that will be replaced with an underscore (_))
Thanks,
-Aaron
Aaron, I changed the code in repository (intl.cs only) but didn't publish the release.
Tell me please if it works for you.
That works perfectly. Thank you! :)