크레아 (Creare) 아래에 언급 된 지원을 원하는 언어별로 파일을 다시 만듭니다. 사용자의 언어/currentculture을 바탕으로
는
alt text http://geekswithblogs.net/images/geekswithblogs_net/dotNETPlayground/resx.gif
, 라벨 또는 MessageBog에서 각각의 언어 리소스 파일 및 디스플레이의 값을 읽습니다. 다음은 몇 가지 샘플 코드입니다.
public static class Translate
{
public static string GetLanguage()
{
return HttpContext.Current.Request.UserLanguages[0];
}
public static string Message(string key)
{
ResourceManager resMan = null;
if (HttpContext.Current.Cache["resMan" + Global.GetLanguage()] == null)
{
resMan = Language.GetResourceManager(Global.GetLanguage());
if (resMan != null) HttpContext.Current.Cache["resMan" + Global.GetLanguage()] = resMan;
}
else
resMan = (ResourceManager)HttpContext.Current.Cache["resMan" + Global.GetLanguage()];
if (resMan == null) return key;
string originalKey = key;
key = Regex.Replace(key, "[ ./]", "_");
try
{
string value = resMan.GetString(key);
if (value != null) return value;
return originalKey;
}
catch (MissingManifestResourceException)
{
try
{
return HttpContext.GetGlobalResourceObject("en_au", key).ToString();
}
catch (MissingManifestResourceException mmre)
{
throw new System.IO.FileNotFoundException("Could not locate the en_au.resx resource file. This is the default language pack, and needs to exist within the Resources project.", mmre);
}
catch (NullReferenceException)
{
return originalKey;
}
}
catch (NullReferenceException)
{
return originalKey;
}
}
}
asn asp.net 응용 프로그램에서는 다음과 같이 사용합니다.
<span class="label">User:</span>
이제 둘 것 :
<span class="label"><%=Translate.Message("User") %>:</span>
좋은 스레드 : http://stackoverflow.com/questions/119568/best-practice-to-make-a-multi-language-application-in-c-winforms 또한 여기 – Inisheer
: HTTP : // msdn.microsoft.com/en-us/library/1021kkz0%28v=VS.100 % 29.aspx – Inisheer
WinForms 또는 WPF? –