Menu

Using in ASP.NET with specific culture

Aaron Haas
2014-10-03
2014-10-06
  • Aaron Haas

    Aaron Haas - 2014-10-03

    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

     
  • Aaron Haas

    Aaron Haas - 2014-10-06

    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

    Any invalid tokens are replaced with the underscore (_) character

    (Notice that dash (-) is in the list of invalid characters that will be replaced with an underscore (_))

    Thanks,
    -Aaron

     
  • arbinada

    arbinada - 2014-10-06

    Aaron, I changed the code in repository (intl.cs only) but didn't publish the release.
    Tell me please if it works for you.

     
  • Aaron Haas

    Aaron Haas - 2014-10-06

    That works perfectly. Thank you! :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.