SwiftUI string interpolation and localisation

Hello,


I was watching the WWDC video:

Introducing SwiftUI: Building Your First App

https://developer.apple.com/videos/play/wwdc2019/204/


The had some sample code at 48:32 for localising the string used in in


Text("\(room.capacity) people")


They used a stringdict file, but didn't expand on the details of configuring the string (here's the file I created in plain xml):


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>%lld people</key>
  <dict>
  <key>NSStringLocalizedFormatKey</key>
  <string>%#@VARIABLE@</string>
  <key>VARIABLE</key>
  <dict>
  <key>NSStringFormatSpecTypeKey</key>
  <string>NSStringPluralRuleType</string>
  <key>NSStringFormatValueTypeKey</key>
  <string></string>
  <key>zero</key>
  <string></string>
  <key>one</key>
  <string></string>
  <key>two</key>
  <string></string>
  <key>few</key>
  <string></string>
  <key>many</key>
  <string></string>
  <key>other</key>
  <string></string>
  </dict>
  </dict>
</dict>


The only thing they showed in the conference video was


<key>%lld people</key>


What should I do to complete the details for this string (in the Localizable.stringdict file) to be picked up by SwiftUI automatically and be localised (e.g. in french?), I did the other strings (the plain - not interpolated ones) in a Localizable.strings file and they localised fine.


Also, is that %lld people (as two Ls or two capital i's in the %LLD or %IID?)


Thanks

Replies

Why do you bother with xml here and not create the plist dirctly in XCode ?


-> New file

Select resource section

Select property list.


You can later open in XML, but it is easier to start this way.

I obviously didn't use XML, I just couldn't attach an image of the .stringdict file to the post... I just added an XML to the question for illustration purposes, so you can see the contents of the default file/value in the dictionary and can suggest what values need to be modified...

Watched the video.


Looks like %lld is a directive for setting locale layout direction

My understanding is that you need to call it like :


Text("\(room.capacity) people", comment: "Capacity")


in order to call to the localization Text() initializer :

public init(_ key: LocalizedStringKey, tableName: String? = nil, bundle: Bundle? = nil, comment: StaticString? = nil)

However that's not what Apple does in the video... Did it maybe change in the last few months? Many things did in that video demo's code.

You're right, my mistake.

Could also use %ld

https://forums.developer.apple.com/thread/117967