Swift: Localization in Storyboard - Labels not added to Main.strings?

≯℡__Kan透↙ 提交于 2020-01-24 02:19:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!