In every project, the same problem is bound to happen (if you care and do localization - tip: you should do it, even if you plan to release your app just in English, just set it up.): You add an element to storyboard and you want to translate it, but you have a .strings file in that language already and the changes aren’t propagated automatically. If you follow the various “guides” online that tell you to remove and re-add the file you’ll end up with a new file and you’d need to retranslate everything all over. Same with localizable.string: If you run
genstrings again you will lose your localization!
I found an even better way. Check the bottom of the post!
If you just have a few elements you can just add them manually (use the other entries to help you).
- Go to Main.storyboard
- Select the element to translate (a label for example)
- Go to the custom class bar (the third one) in the right sidebar
- Copy the Object-ID in the Document section
- Switch back to your Main.strings file
Paste the id like this:
“YjH-1m-BVM.text” = “Increase by”;
Note: Make sure to add the .text at the end of the Object-ID, the same thing for other elements (it’s not always .text so be wary), it’s what you would use in code [I guess] to access the text property. You can use the rest of the .strings file previously autogenerated to help you with that.
##A Better Way
I forgot that shipping with OSX there is a great utility called “FileMerge” that compares the differences between two files.
Here’s what to do (works even if you need to edit a lot of entries):
- Open Xcode and turn on a new localization
- Generate the .strings file for the localization
- Drag the strings file for the localization you want to update on the left and the .strings file that Xcode just generated on the right (or vice-versa)
- On the next screen, you will see both files side by side with all the differences highlighted. Now just copy and paste whatever you want to change.