I use Resources to store different string for localization purposes in my MVC application.
I am using an HttpHandler to process JavaScript and change the Translate(KEY)
calls to the actual localized string value from the resource.
This comes for here: Localize text in JavaScript files in ASP.NET
The problem is when i call the getObject Method from my Resource manager I get MissingManifestResourceException Could not find any resources appropriate for the specified culture or the neutral culture.
here Is the relevant code portion (The error comes from line 6 in the snippet below):
private string TranslateScript(string text)
{
MatchCollection matches = REGEX.Matches(text);
ResourceManager manager = new ResourceManager(typeof(CamelotShiftManagement.Strings.SharedStrings));
foreach (Match match in matches)
{
object obj = manager.GetObject(match.Groups[1].Value, CultureInfo.CurrentCulture); //This throws the MissingManifestResourceException for some reson!!!!
if (obj != null)
{
text = text.Replace(match.Value, CleanText(obj.ToString()));
}
}
return text;
}
What am I doing wrong ?
Okay, I found the problem but I can't explain why is that happening. (yet)
I found this post Problems with ResourceManager and neutral culture in Asp.Net MVC and followde the steps he did. I have chage the line:
ResourceManager manager = new ResourceManager(typeof(CamelotShiftManagement.Strings.SharedStrings));
To:
ResourceManager manager = CamelotShiftManagement.Strings.SharedStrings.ResourceManager;
Basically it seems as thou each resource file has a static referance to a ResourceManager that handles this resource file.
That solved my problem. Having said that, I am still unsure as to why the method I used before did not work...