2011-09-24 55 views
1

我想讓本地化在mac上使用monodevelop的asp.net mvc項目中工作。我添加了一個翻譯項目,並在丹麥語中翻譯了「歡迎」文本。在asp.net/monodevelop中運行時初始化gettext的正確方法

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     var culture = CultureInfo.CreateSpecificCulture("da");  
     System.Threading.Thread.CurrentThread.CurrentUICulture = culture; 
     System.Threading.Thread.CurrentThread.CurrentCulture = culture; 
     Mono.Unix.Catalog.Init("i8n1", "./locale"); 
     ViewData ["Message"] = Mono.Unix.Catalog.GetString("Welcome"); 
     return View(); 
    } 
} 

但是文本沒有被翻譯。 有什麼建議嗎?

+0

我在Ubuntu上遇到同樣的問題。 – ph7

回答

0

您需要完整路徑到您的區域設置文件夾。

MonoDevelop的做這樣的事情(編輯爲簡潔起見)

string location = System.Reflection.Assembly.GetExecutingAssembly().Location; 
location = Path.GetDirectoryName(location); 

string catalogPath = Path.Combine (location, "locale"); 

Catalog.Init ("monodevelop", catalogPath); 
-1

答案就在這裏:http://mono.1490590.n4.nabble.com/Mono-Unix-Catalog-Init-where-does-it-get-the-locale-from-td1532586.html

public static void Main (string[] args) 
    { 
     var culture = CultureInfo.CreateSpecificCulture ("de"); 
     Thread.CurrentThread.CurrentCulture = culture; 
     Environment.SetEnvironmentVariable ("LANGUAGE", "de_DE"); 
     Catalog.Init ("i8n1", "./locale"); 

     Console.WriteLine (Catalog.GetString("Hello World!")); 
    } 

而且它爲我工作在Ubuntu /單聲道。感謝弗拉基米爾提出了很好的問題,並感謝喬納森提供了很好的答案。

相關問題