0

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.

0

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

<string name="text_register">REGISTER</string> becomes "REGISTER" = "REGISTER";, it should be "text_register" = "REGISTER" So I have changed print "\""$3 "\" \= \"" $3 "\";" to print "\""$2 "\" \= \"" $3 "\";" then it becomes "name="text_register"" = "REGISTER" then I have replaced "name=" to "" and "" = to " =

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.