问题
When I try to localize my app and I create a new Main.strings file for the target language, everything I have created in interface builder (labels, buttons, ...) is added to the new Main.strings files (base and language versions) and I can localize the text accordingly.
But when I later add a label or a button to a ViewController in interface builder, it is not automatically added to the Main.strings files for the base and language version.
So, how can I find out what the ObjectID for the button/label is so that I can add it to the strings files?
Or is there another way to force Xcode to add newly added labels and buttons to those files automatically?
回答1:
After selecting UILabel
from storyboard, You can find object id of UILabel
in right panel:
Then you can set text of label as below in your Main.string
file:
"v12-vM-an5.text" = "Phone";
回答2:
Dhaval Bhimani's answer is the easiest solution for localizing a small number of newly added view components. If you want to regenerate all the localizations for a storyboard, select the Main.storyboard-> deselect the localization check boxes for all the languages. check the 'Delete localized resource files from disk' check box now make sure your newly added labels and buttons are there and localize again by selecting languages. Just in case backup your string files before that
回答3:
Use ibtool to extract the strings in your storyboard.
Open the Terminal application Locate your Base.lproj directory Use this line to extract the strings:
ibtool MainStoryboard.storyboard --generate-strings-file file_name.strings
After ibtool extracts the strings to file_name.strings, you can copy and paste it to your original .strings file
(Originally appread here Is it possible to update a localized storyboard's strings?)
来源:https://stackoverflow.com/questions/48240039/swift-localization-in-storyboard-labels-not-added-to-main-strings