Converting Android strings.xml to iPhone String File with xsltproc

I am embarking on converting an Android app to an iPhone app.  One thing I want to do is take advantage of all the localized strings I've got defined in strings.xml in the Android project.

Here's some very simple xsl to convert the strings.xml to something close to the proper format to be used in XCode.  You can  use the xsltproc command-line tool that comes with OsX to run it.

<?xml version="1.0" encoding="ISO-8859-15"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="ISO-8859-15"/>
<xsl:template match="string">
"<xsl:value-of select="@name"/>"= "<xsl:apply-templates/>"; </xsl:template>
<xsl:template match="resources">
<xsl:apply-templates select="string"/> </xsl:template>
</xsl:stylesheet>

Save this to a file, say transform.xsl. Then to run it to create the file you need for XCode, do this from a shell:

xsltproc transform.xsl your_android_strings.xml > string_file_for_iphone.out

There might still need to be some cleanup to do (dealing with format strings, for example), but this seems to get a lot of the grunt work done.

No comments:

Post a Comment

Popular Posts