0

I want to dynamically modify the "xxx.strings" file by a shell script in iOS project.

They are key-value files.Is there some way to replace the value with the key?

1.The "InfoPlist.strings" file contents like this:

CFBundleDisplayName = "WinTraining";

some one wants to change "WinTraining" to "eDetailing", like this:

CFBundleDisplayName = "eDetailing";

2.And there same muti line files named "Localizable.strings" like this:

"Item" = "Item";
"ProductName" = "Product Name";
"Today" = "Today";
"NetworkError" = "Unable to connect to the network, please check the network";
"UploadComplete" = "Upload complete";
"Updating" = "Updating,Please wait...";

I want to modify the ".strings" file in my CI environment(jenkins),diffrient jenkins's jobs is built for diffrient customers) . In iOS project "CFBundleDisplayName" is used to set the app name, different customer requires different app name, so I need to change the "InfoPlist.string" file. "Localizable.strings",same situation.

4
  • Could you please supply sample input and output for the script? Commented Dec 17, 2014 at 3:23
  • what exactly do you want to modify? Commented Dec 17, 2014 at 3:26
  • Why do you want to do this? Why not just lookup your localized dynamically, if you have some strings which are dynamic anyway? Commented Dec 17, 2014 at 3:33
  • @ShellFish, thanks for reminding. I've edited my question. Commented Dec 17, 2014 at 6:00

3 Answers 3

2

If you have access to the sed command, you can try:

sed -i 's/\"WinTraining\"/\"eDetailing\"/' InfoPlist.strings

The sed command should also work on your Localizable.strings as well. To replace something else use:

sed -i 's/STRING_TO_SEARCH_FOR/STRING_TO_REPLACE_SEARCH_STRING_WITH/'

Be sure to escape quotes and such.

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

1 Comment

They are key-value files.Is there some way to replace the value with the key?
2

Great Thanks to Kazuki and MeetTitan, I found the better way by your prompts. I also used the sed command to replace the values with the keys,Like this:

InfoPlist.strings:

 key=CFBundleDisplayName
 newvalue=\"eDetailing\"
 sed -i -e "s/${key} *\=.*\;/${key} = ${newvalue}\;/" InfoPlist.strings

Localizable.strings:

 key=\"Item\"
 newvalue=\"The\ Item\"
 sed -i -e "s/${key} *\=.*\;/${key} = ${newvalue}\;/" Localizable.strings

Comments

0

Add a script like the following to your Jenkins job settings

mv $WORKSPACE/InfoPlist.strings $WORKSPACE/InfoPlist.strings.orig
sed -e 's/WinTraining/eDetailing/' $WORKSPACE/InfoPlist.strings.orig > $WORKSPACE/InfoPlist.strings

Comments

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.