Strings Catalog (.xcstrings) plural rules without format (Xcode 15)

In stringsdict it was possible to define a format separately from the translation so you could do something like "n_days" which you could pass in an integer and it would return you only "Day" or "Days" without the actual value in it. And it's work great.

But now with the strings catalog it seems like the format specifier HAS to be in the value, otherwise it's not recognized. Is there now no way to pluralize anything without having the actual value inside the translation?

Cannot infer format specifier for string group because no numerical specifiers were found (en: %d.n_hours)

Accepted Reply

Hi,

Stringsdict and String Catalog Plural Variants are not suited for a string that has plurality but no number associated with that plural.
This would do the right thing in English, but many languages would have issues.
The plural rules are different between number-based plurals (one, two, few many, other) and non-number-based plurals (1, 2+).

It’s recommended here to have 2 different plain strings, controlled by if count == 1 { … } else { … }.

More information in this session at the time linked: https://developer.apple.com/wwdc21/10221?time=1330

Replies

Hi,

Stringsdict and String Catalog Plural Variants are not suited for a string that has plurality but no number associated with that plural.
This would do the right thing in English, but many languages would have issues.
The plural rules are different between number-based plurals (one, two, few many, other) and non-number-based plurals (1, 2+).

It’s recommended here to have 2 different plain strings, controlled by if count == 1 { … } else { … }.

More information in this session at the time linked: https://developer.apple.com/wwdc21/10221?time=1330

Hi, I have had the same problem you can achieve a string without a numerical specifier when editing the source code of the xcstrings file.

  1. right click .xcstrings > Open As > Source Code
  2. add this to strings object and edit this as your want:
"%lld day" : {
      "localizations" : {
        "de" : {
          "stringUnit" : {
            "state" : "translated",
            "value" : "%#@day@"
          },
          "substitutions" : {
            "day" : {
              "formatSpecifier" : "lld",
              "variations" : {
                "plural" : {
                  "one" : {
                    "stringUnit" : {
                      "state" : "translated",
                      "value" : "Tag"
                    }
                  },
                  "other" : {
                    "stringUnit" : {
                      "state" : "translated",
                      "value" : "Tage"
                    }
                  }
                }
              }
            }
          }
        },
        "en" : {
          "stringUnit" : {
            "state" : "translated",
            "value" : "%#@day@"
          },
          "substitutions" : {
            "day" : {
              "formatSpecifier" : "lld",
              "variations" : {
                "plural" : {
                  "one" : {
                    "stringUnit" : {
                      "state" : "translated",
                      "value" : "day"
                    }
                  },
                  "other" : {
                    "stringUnit" : {
                      "state" : "translated",
                      "value" : "days"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },

note: %lld day is translated in German

Its sad that we need to this every time manual by adding it to the source code.

  • Hi @Konsti_x08. We are also running into this same issue but considering we have our App translated in 14 languages we are also sad to have to do this manual work each time. Would it please be possible to confirm how you are calling these pluralized strings at the call site? Are you using NSLocalizedString or have you found a way to use String(localized: or another solution ? Thank you!

Add a Comment

It seems that xcstrings not support pluralization without number.

2 different plain strings, controlled by if count == 1 { … } else { … } sounds like kind of pornography.

Now I found only one way - to use legacy stringsdict file.