2010-06-28 4 views

답변

2

들어오는 브라우저 요청에서 사용자의 문화권을 읽고 그로부터 CultureInfo를 설정해야한다고 생각합니다.

This fellow describes how they do it : 현재 스레드의 표시 culture를 사용자의 들어오는 Http "요청"개체에서 가장 적합한 문화권으로 설정하십시오.

그는이 훌륭한 토론을 가지고 있지만, 이것은 기본적으로 그가 그것을 어떻게하는지 : UIUtilities.setCulture(Request);

이 호출되는 것입니다 : Page_Load에서

, 그들은이 전화를 걸

/// Set the display culture for the current thread to the most 
/// appropriate culture from the user's incoming Http "request" object. 
internal static void setCulture(HttpRequest request) 
{ 
    if (request != null) 
    { 
     if (request.UserLanguages != null) 
     { 
     if (request.UserLanguages.Length > -1) 
     { 
      string cultureName = request.UserLanguages[0]; 
      UIUtilities.setCulture(cultureName); 
     } 
     } 
     // TODO: Set to a (system-wide, or possibly user-specified) default 
     // culture if the browser didn't give us any clues. 
    } 
} 

/// Set the display culture for the current thread to a particular named culture. 
/// <param name="cultureName">The name of the culture to be set 
/// for the thread</param> 
private static void setCulture(string cultureName) 
{ 
    Thread.CurrentThread.CurrentCulture = 
     CultureInfo.CreateSpecificCulture(cultureName); 
    Thread.CurrentThread.CurrentUICulture = new 
     CultureInfo(cultureName); 
} 
+0

오른쪽 행에 있지만 브라우저가 전송 한 Accept-Language 헤더가 반드시 사용자가 선호하는 언어 일 필요는 없습니다. 저는 유럽에 있는데 미국 버전의 Windows를 가지고 있기 때문에 IE8이 en-US를 보냅니다. accept-language 헤더의 이름은 유효한 .NET culture 이름이 아니므로 CreateSpecificCulture에 대한 호출을 try/catch로 묶어야합니다. – Joe

+0

행운이 없습니다. 나는 여전히 테스트 중일 것입니다. – thchaver

+0

Request.UserLanguages에서 무엇을 얻으십니까? 즉, 브라우저가 요청한 언어가 무엇입니까? – DOK

18

web.config 파일에서 culture 속성을 auto으로 설정하면됩니다.

<system.web> 
    <globalization culture="auto" /> 
<system.web> 

그러면 자동으로 CurrentCulture이 클라이언트의 문화권으로 설정됩니다.

현지화 된 리소스를 사용하는 경우 uiCulture에서 auto으로 설정할 수도 있습니다.

+1

나는 이것을 한 번 이상 upvote 할 수 있으면 좋겠다. 이 일을하기 위해 3 시간을 보냈습니다 :) – Thousand

1

필자의 경우 내 컴퓨터에는 원래 영어 - 영국이 설치되어있었습니다. 영어 - 미국 언어를 추가하고 기본값으로 설정했습니다. 나는 또한 미국이 레지스트리에 올바르게 설치되었는지 확인했다. 슬프게도 System.Threading.Thread.CurrentThread.CurrentCulture은 여전히 ​​영국 문화를 틀리게 보여주었습니다. 언어 옵션을 설정해야한다는 사실을 발견했습니다. 언어 팩, 필기 및 음성을 다운로드하십시오.

심지어 문화가 잘못되었습니다. 영국이 컴퓨터 전체에 나타나고 미국 언어 팩을 설치 한 후 시작 메뉴가 완전히 열매를 맺었습니다. 영어 버전을 사용하여 OS를 포기하고 다시 설치했습니다.

관련 문제