简体   繁体   中英

Swift - How to use localisation from Shared Extension

How can I use container apps localized strings from shared extension in Swift. I have already added containers strings files into extension -> build phase -> compile sources but its still not working. Should I set anything in configuration? From main container app strings are translated but from shared extension it shows only the string keys/ids for texts.

You need to change target membership of the Localizable.strings file. Select Localizable.strings in the Project Navigator on the left, then open File Inspector on the right and add checkmark next to your extension target in the "Target Membership" field.

在此处输入图片说明

There are a couple things to check:

  • One is the solution offered here by @ovejka - click on your string localization file and ensure, in the rightside settings pane, that the file applies to your widget as well as your main app (target membership).
  • Another is to ensure that your storyboard strings file, which should have been created automatically when you added a second language to your app, has the proper translations.
  • If neither of those work, given that a widget is quite small and likely only has few labels, you could add a switch statement to 'viewWillAppear' to translate each label based on the detected language

Finally, none of those seemed to be working for me in the simulator or even by switching the schema language and running it on my actual phone.

It turns out, it was working all along and the simulated language wasn't applying to the widget. I turned my actual phone's language to Spanish, run the new version of my app, and the widget was translated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM