Reputation: 1699
I use Xcode 5 in a project. and the project need to localization. Xcode had help me generated Localizable.strings
it looks like
/* Class = "IBUIButton"; normalTitle = "2013-10-1"; ObjectID = "p5u-h7-pfJ"; */
"p5u-h7-pfJ.normalTitle" = "2013-10-1";
/* Class = "IBUILabel"; text = "Label"; ObjectID = "pBS-eN-YUz"; */
"pBS-eN-YUz.text" = "Label";
/* Class = "IBUITextField"; placeholder = "Input Name Here"; ObjectID = "pE4-WG-fPp"; */
"pE4-WG-fPp.placeholder" = "Input Name Here";
/* Class = "IBUILabel"; text = "Detail"; ObjectID = "qSu-Mo-baT"; */
"qSu-Mo-baT.text" = "Detail";
but how should I do if I want to add new UI in the storyboard. How can I add new key-value?
Upvotes: 7
Views: 6561
Reputation: 1474
Make backup copies of a storyboard's .strings file for a locale that needs to be updated.
Select storyboard in the Project Navigator (in the left Xcode's pane), open File Inspector (right pane) and unmark checkbox for that locale.
In the 'Do you want to remove...' alert appeared, check 'Delete localized resource files from disk' checkbox and press 'Remove' button.
Mark back the same checkbox; this will generate localized resource file for the locale; it will contain entries for all objects including newly added but its contents will not be localized at all.
Merge this newly generated file with saved backup - this will restore all localizations you've done before.
Localize new objects.
Upvotes: 2
Reputation: 3603
Not sure if this is the "right" way or the best way, but here is what I do:
1) make any localizations LAST. In other words, first try to make sure that you do NOT need any changes made to the base storyboard. This may sound like a cop out but really, it's the best way to avoid hassles.
2) since that isn't always how things turn out, if you DO need to make changes, you can push them out to the localized files by changing them from "strings" to "storyboard" and then back. This will preserve your existing translations and work in any new stuff automatically, and as such it's better than outright deleting the localized files from the bundle.
I noticed that this may leave some redundant strings in the localized file from time to time, and sometimes you have to delete them manually or it won't compile correctly, but if there is any better way to do this, I'd like to know myself.
Upvotes: 1
Reputation: 2818
In your storyboard, every single Object has an ID. In the 'Utilities' view, 'Identity Inspector' thumb, 'Document' section, there is a field 'Object ID'
I've never used this, but I guess that, if you have a label with ID 141-wB-KQD
and you want to set its text property, you have to put in your Localizable.strings
:
"141-wB-KQD.text" = "the value you want";
Upvotes: 19
Reputation: 1438
If you want to localize your project views, just go to the storyboard click on the view controller, then go to File Inspector and click on Localize... you'll have one storyboard file for each language.
Upvotes: -1