Are unused strings in a swift package optimized?

If I create a swift package with 1000 strings in the Localizable.strings file for English, but I only end up using 10 of the strings in my app, will the other 990 strings be optimized away?

I am pretty sure that Localizable.strings files for languages not supported by the app are excluded, but I wanted to confirm whether Xcode is capable of detecting unused strings.

Answered by Systems Engineer in 763873022

Hi, I suggest you take a look at the new String Catalog feature, which can detect unused (stale) strings:
https://developer.apple.com/wwdc23/10155
You can then remove all stale strings. There is no automatic optimization otherwise in .strings files.

  

If you have plurals like 3 pages, please check Stringdict or Plural Variants in String Catalogs. https://developer.apple.com/wwdc21/10221?time=1193
If you have plurals like My pages, please create 2 strings My page and My pages controlled by if/else. https://developer.apple.com/wwdc21/10221?time=1330
Concatenating (with +) is not recommended as it doesn’t let other languages reorder or change words.

I don't think so. In fact, it is virtually impossible.

Imagine you have an entry:

"My back pages"

Then in code, you have str that you localize

var number : Int
let str = "My back page" + (number >= 2 ? "s" : "")

How could the compiler know whether number will be or not be >= 2 at some point in execution ?

Accepted Answer

Hi, I suggest you take a look at the new String Catalog feature, which can detect unused (stale) strings:
https://developer.apple.com/wwdc23/10155
You can then remove all stale strings. There is no automatic optimization otherwise in .strings files.

  

If you have plurals like 3 pages, please check Stringdict or Plural Variants in String Catalogs. https://developer.apple.com/wwdc21/10221?time=1193
If you have plurals like My pages, please create 2 strings My page and My pages controlled by if/else. https://developer.apple.com/wwdc21/10221?time=1330
Concatenating (with +) is not recommended as it doesn’t let other languages reorder or change words.

Are unused strings in a swift package optimized?
 
 
Q