Question

I have ios string file that i want to convert into the Android xml file:

This is the ios string file which i have want to convert into the Android xml file:

 /*
 Localizable.strings
 SaiÌda da Escola

 Created by farhan shah on 11/12/2013.
 Copyright (c) 2013 whizpool. All rights reserved.
 */

"settings_button" = "Settings";

"location" = "Destiny";

"Register_button" = "Register";

"logout" = "Log Out";

"login_button" = "Login";

"ok" = "Ok";

"yes" = "Yes";

"no" = "No";

the result should be like this like Android xml file:

<?xml version="1.0" encoding="utf-8"?>
 <resources>
<!--
 Localizable.strings
 SaiÌda da Escola

 Created by farhan shah on 11/12/2013.
 Copyright (c) 2013 whizpool. All rights reserved.
 -->

<string name="settings_button">Settings</string>

<string name="location">Destiny</string>

<string name="register_button">Register</string>

<string name="logout">Log Out</string>

<string name="login_button">Login</string>

<string name="ok">Ok</string>

<string name="yes">Yes</string>

<string name="no">No</string>


</resources>

any help,idea and sample code will be highly appreciated,Thanks alot in advance.

Was it helpful?

Solution

You can take a look at the JavaScript code in the page below, and you could do something similar in Java. It uses regular expressions to parse the input files.

http://members.home.nl/bas.de.reuver/files/stringsconvert.html

OTHER TIPS

You cannot convert this "programatically" using Android code, because those strings need to be available in your project's resources before compilation, of course.

You could use a simple bash script, like:

echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<resources>'
while read line ; do
    tag=$(echo $line | cut -d'"' -f2)
    trad=$(echo $line | cut -d'"' -f4)
    echo "  <string name=\"$tag\">$trad</string>"
done < <(cat Localizable.strings | egrep '^".+"\s?=\s?.+$')
echo '</resources>'

That outputs:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="settings_button">Settings</string>
  <string name="location">Destiny</string>
  <string name="Register_button">Register</string>
  <string name="logout">Log Out</string>
  <string name="login_button">Login</string>
  <string name="ok">Ok</string>
  <string name="yes">Yes</string>
  <string name="no">No</string>
</resources>

Use it like:

$ bash strings.bash > strings.xml

Note: Everything there is just an example I coded in a minute, adapt as you wish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top