2

Xcode nowadays exports localization files in XLIFF format, which is great. Sometimes I would still like to work on old-school strings files, as they were common with earlier versions of Xcode. Is there a conversion tool to extract separate strings files from a single XLIFF document? All the information is contained in the XML-like XLIFF document, so there should be a routine for extraction?!

Thanks for your help!

Fabian Jäger
  • 447
  • 1
  • 5
  • 12

3 Answers3

1

As XLIFF is an XML format you could use XSLT to convert XLIFF to .strings format:

<xsl:output method="text"/>  
<xsl:template match="//trans-unit">  
  /* <xsl:value-of select="note"></xsl:value-of> */  
  "<xsl:value-of select="@id"></xsl:value-of>" = "<xsl:value-of select="source"></xsl:value-of>"  
</xsl:template>  

This may need a bit of additional fine-tuning, for example for trans-unit elements without notes and for multi-line strings, but perhaps it is enough for your XLIFF.

Jenszcz
  • 547
  • 3
  • 9
  • do you mind to extend a little bit your answer? how Can I apply an xslt template to an xliff? – MatterGoal Feb 25 '19 at 10:43
  • Using xmlstarlet and with $XL set to the *.xliff path... ``` $ xml sel -T -t -m "//_:trans-unit" -o "/* " -v "_:note" -o " */" -n -o "\"" -v "_:source" -o "\" = \"" -v "_:target" -o "\";" -n -n $XL ``` This will put everything in the *.xliff into stdout in .strings format (plist) without regard to what file it came from (Info.plist, Localizable.strings, etc). – James Stewart Apr 12 '19 at 13:38
  • This will do the same, but add a comment that indicates which file the original string came from: `$ xml sel -T -t -m "//_:trans-unit" -o "/* " -v "../../@original" -o " */" -n -o "/* " -v "_:note" -o " */" -n -o "\"" -v "_:source" -o "\" = \"" -v "_:target" -o "\";" -n -n $XL` – James Stewart Apr 12 '19 at 14:18
0

You can use ibtool to export localizable text in .strings format rather than XLIFF. I don't believe you can do a direct XLIFF -> .strings conversion, but you can have ibtool generate .strings files from your .xib or .storyboard files.

Michael Teper
  • 4,591
  • 2
  • 32
  • 49
  • I already knew about ibtool, but there should also be a way to export XLIFF (from Xcode resources) to strings files per resource. Anybody else? – Fabian Jäger May 27 '15 at 08:57
0

Once the XLIFF has been translated you can import those translations. At that point XCode should create the separate .strings files for you in the relevant .lproj directories.

Colin Downes
  • 446
  • 4
  • 4