2011-12-01 12 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チャンネルにこの件について尋ねたと公式の答えは「まだサポートされていませんが、我々はそれを行うための計画を持っています」ました。

あなたがRESXファイルがAndroidのXML形式に変換する(下記参照)、ここで示したように、プロジェクトに追加する必要があります:私のアプリ(ゲーム)ではhttp://docs.xamarin.com/android/tutorials/Android_Resources/Part_5_-_Application_Localization_and_String_Resources

私は名前でローカライズされた文字列を検索するために必要な。これを行うコードは簡単でしたが、すぐには分かりませんでした。代わりの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);    
    } 
} 

私はAndroidの文字列の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); 
      } 
     } 
    } 
} 
関連する問題