2011-12-01 11 views
5

내 응용 프로그램은 표준 .NET RESX 메서드 (예 : String.fr.resx, Strings.de.resx 등)를 사용하여 현지화되어 Windows Phone에서 잘 작동합니다.MonoDroid 현지화

MonoDroid를 사용하여 Android에 포팅 중이며 전화 로케일을 전환 할 때 현지화 된 UI가 표시되지 않습니다. APK 파일의 이름을 ZIP으로 변경하고 열면 빌드 도중 생성 된 로케일 DLL이 패키지화되지 않은 것을 볼 수 있습니다 (예 : 중간 \ .Resources.dll 파일은 bin 디렉토리에 있지만 APK에 패키지되어 있지 않음) .

무엇이 누락 되었습니까? RESX 파일의 빌드 동작을 "임베디드 리소스"에서 "Android 리소스"및 "Android 자산"으로 변경하려고했지만 아무 소용이 없었습니다.

미리 도움을 청하십시오!

건배 워렌

+1

현지화 폴더 제목을 통해 구현되었습니다. 이 작업을 수행하는 방법은이 기사를 읽으십시오. http://developer.android.com/guide/topics/resources/localization.html – mironych

답변

2

나는 monodroid IRC 채널에 대해 질문을하고 공식적인 답변은 "아직 지원되지하지만 우리는 그것을 할 계획이 있는가"했다. http://docs.xamarin.com/android/tutorials/Android_Resources/Part_5_-_Application_Localization_and_String_Resources

내 응용 프로그램 (게임) 나는 이름으로 지역화 된 문자열을 찾아 볼 필요에서 : 다음과 같이

당신은 (아래 참조) 프로젝트에 추가 안드로이드 XML 형식으로 RESX 파일을 변환 할 필요가 . 이렇게하는 코드는 간단하지만 즉시 명백하지는 않습니다. 대신 ResourceManager에를 사용하는 나는 안드로이드에 대한이의 교환 :

class AndroidResourcesProxy : Arands.Core.IResourcesProxy 
{ 
    Context _context; 

    public AndroidResourcesProxy(Context context) 
    { 
     _context = context; 
    } 

    public string GetString(string key) 
    { 
     int resId = _context.Resources.GetIdentifier(key, "string", _context.PackageName); 
     return _context.Resources.GetString(resId);    
    } 
} 

내가 안드로이드 문자열 XML 파일을 RESX을 변환하는 명령 줄 프로그램을 만든 XSLT 전문가가 아니에요 이후 : 안드로이드

/// <summary> 
/// Conerts localisation resx string files into the android xml format 
/// </summary> 
class Program 
{ 
    static void Main(string[] args) 
    { 
     string inFile = args[0]; 
     XmlDocument inDoc = new XmlDocument(); 
     using (XmlTextReader reader = new XmlTextReader(inFile)) 
     { 
      inDoc.Load(reader); 
     } 

     string outFile = Path.Combine(Path.GetDirectoryName(inFile), Path.GetFileNameWithoutExtension(inFile)) + ".xml"; 
     XmlDocument outDoc = new XmlDocument(); 
     outDoc.AppendChild(outDoc.CreateXmlDeclaration("1.0", "utf-8", null)); 

     XmlElement resElem = outDoc.CreateElement("resources"); 
     outDoc.AppendChild(resElem); 

     XmlNodeList stringNodes = inDoc.SelectNodes("root/data"); 
     foreach (XmlNode n in stringNodes) 
     { 
      string key = n.Attributes["name"].Value; 
      string val = n.SelectSingleNode("value").InnerText; 

      XmlElement stringElem = outDoc.CreateElement("string"); 
      XmlAttribute nameAttrib = outDoc.CreateAttribute("name"); 
      nameAttrib.Value = key; 
      stringElem.Attributes.Append(nameAttrib); 
      stringElem.InnerText = val; 

      resElem.AppendChild(stringElem); 
     } 

     XmlWriterSettings xws = new XmlWriterSettings(); 
     xws.Encoding = Encoding.UTF8; 
     xws.Indent = true; 
     xws.NewLineChars = "\n"; 

     using (StreamWriter sr = new StreamWriter(outFile)) 
     { 
      using (XmlWriter writer = XmlWriter.Create(sr, xws)) 
      { 
       outDoc.Save(writer); 
      } 
     } 
    } 
}