6

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.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

2 Answers2

13

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.

enter image description here

ovejka
  • 999
  • 1
  • 16
  • 21
0

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.

Dave G
  • 12,042
  • 7
  • 57
  • 83