2012-10-04 44 views
1

我使用資源爲我的MVC應用程序存儲用於本地化目的不同的字符串。 我正在使用HttpHandler來處理JavaScript並將Translate(KEY)調用更改爲資源中實際的本地化字符串值。 這來自於這裏:Localize text in JavaScript files in ASP.NET使用getobject()拋出MissingManifestResourceException

問題是,當我從我的資源管理器調用GetObject方法我得到MissingManifestResourceException Could not find any resources appropriate for the specified culture or the neutral culture.

下面是相關的代碼部分(這個錯誤來自6號線在下面的代碼片段):

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; 
} 

我在做什麼錯?

回答

1

好的,我發現了這個問題,但我無法解釋爲什麼會發生這種情況。 (還)

我發現這個職位Problems with ResourceManager and neutral culture in Asp.Net MVC 並遵循他所做的步驟。 我恰克行:

ResourceManager manager = new ResourceManager(typeof(CamelotShiftManagement.Strings.SharedStrings)); 

要:

ResourceManager manager = CamelotShiftManagement.Strings.SharedStrings.ResourceManager; 

基本上它似乎你每一個資源文件中有一個靜態全球化志願服務青年來處理這個資源文件一個ResourceManager。

這解決了我的問題。 話雖如此,我仍然不確定爲什麼我以前使用的方法不起作用...

相關問題