나는 안드로이드 대신에 .net resource files을 사용하고 있습니다. 어디서나 코드의 문자열에 액세스 할 수 있습니다.
내가 자동으로 수행 할 수없는 유일한 작업은 레이아웃의 해당 문자열을 참조하는 것입니다. 이 문제를 해결하기 위해 resx 파일을 분석하고 동일한 값을 가진 Android 리소스 파일을 만드는 빠른 유틸리티를 작성했습니다. 안드로이드 프로젝트가 빌드되기 전에 실행되어 모든 문자열이 제자리에있을 때 실행됩니다.
면책 조항 : 실제로 여러 언어로 테스트하지는 않았습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace StringThing
{
class Program
{
static void Main(string[] args)
{
string sourceFile = args[0];
string targetFile = args[1];
Dictionary<string, string> strings = LoadDotNetStrings(sourceFile);
WriteToTarget(targetFile, strings);
}
static Dictionary<string, string> LoadDotNetStrings(string file)
{
var result = new Dictionary<string, string>();
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNodeList nodes = doc.SelectNodes("//data");
foreach (XmlNode node in nodes)
{
string name = node.Attributes["name"].Value;
string value = node.ChildNodes[1].InnerText;
result.Add(name, value);
}
return result;
}
static void WriteToTarget(string targetFile, Dictionary<string, string> strings)
{
StringBuilder bob = new StringBuilder();
bob.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
bob.AppendLine("<resources>");
foreach (string key in strings.Keys)
{
bob.Append(" ");
bob.AppendLine(string.Format("<string name=\"{0}\">{1}</string>", key, strings[key]));
}
bob.AppendLine("</resources>");
System.IO.File.WriteAllText(targetFile, bob.ToString());
}
}
}
이 답변을 바탕으로 많은 Android 리소스를 생성하고 iOS UIColor 리소스 (더 많은 iOS)를 생성하는 OSS 프로젝트를 만들었습니다. https://github.com/ChaseFlorell/ResourceMigrator –