Reputation: 2737
I want the strings in strings.xml to be converted to ios Localizable.strings format
Format:
"String"="String"
I have used few online tools in web which converts xml to localible.strings, but the format I have seen is :
"Key"="Value"
But I need in this format:
"value"="value"
example:
if this is the Strings.xml file,
<resources>
<String name="addtocart">Please add to cart</string>
</resources>
The localizable.strings format should be in :
"Please add to cart"="Please add to cart" (I need this)
and not
"addtocart"="Please add to cart" (Format resulted from conversion tools in web)
Is there any plugin or built in functionality in eclipse. I am new to android and this localization process.
Can one help me out in achieving this please...
Thanks in advance.
Upvotes: 0
Views: 1534
Reputation: 1362
A pretty simple awk
bash script can do your job.
awk '
BEGIN{
FS = "^ *<string *| *>|<\/string> *$|^ *<!-- *| *--> *$";
}
{
if (/<string.*name\=\".*\".*>.*<\/string> *$/){
print "\""$3 "\" \= \"" $3 "\";"
}
else if(/<!--.*-->/)
print "// "$2;
else if(/^ *$/)
print ""
}'
Save the above to android2ios.sh
. This script will read from the standard input stream.
For example your Android strings content like <string name="addtocart">Please add to cart</string>
is copied to your clipboard, and you're using OS X as your operating system.
pbpaste | sh android2ios.sh
This will print
"Please add to cart" = "Please add to cart";
You can do the redirect and pipe thing in your own way. The script only does the converting.
Comments like <!--comment-->
and multiline content are also handled well by this script.
BTW, I like the "addtocart"="Please add to cart"
way better, because "value" = "value"
may result in duplicated keys.
Upvotes: 3