2011-09-24 51 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 /单声道。感谢弗拉基米尔提出了很好的问题,并感谢乔纳森提供了很好的答案。

相关问题