Issues with String Catalogs comments and git

Hello,

I migrated a project to use String Catalogs (Localizable.xcstrings) instead of Localized.strings and Localized.stringsdict files.

So far so good, but since I use a lot localized strings in my project, there are quite some localizations used more than once in different contexts and thus with different comments.

For example:

Source file 1:

String(localized: "Something", comment: "Button title for context1")

Source file 2:

String(localized: "Something", comment: "Column title for context2")

This results to a Localized.xcstrings file with this content:

{
  "sourceLanguage" : "en",
  "strings" : {
    "Something" : {
      "comment" : "Column title for context2\nButton title for context1"
    }
  },
  "version" : "1.0"
}

The main problem with this is, that the order of the concatenated comment changes randomly during each build. After the next Xcode build (without any code changes), the same Localized.xcstrings file might look like this:

{
  "sourceLanguage" : "en",
  "strings" : {
    "Something" : {
      "comment" : "Button title for context1\nColumn title for context2"
    }
  },
  "version" : "1.0"
}

This leads to false positives when trying to commit changes to a git repository, which is quite annoying.

Am I the only one, having issues with comments in String Catalogs and git?

It seems to me that you shouldn't really be using the same key for both of these localized strings, since they are used in different places. Even if the localized strings come out the same in general, it's a risky assumption that the different UI contexts (column titles and button titles in your example) won't require different strings for some languages. For example, in some languages the string might need to be capitalized differently in these 2 places.

If you really do want to use the exact same localized string in both places, I'd recommend that you use the same comment everywhere in your source code, describing both intended uses. If you fully specify the comment this way, you avoid confusion for the translator too.

Otherwise, you should use a unique string at each call site, such as "Something-List-Title" and "Something-Button-Title", and use the comments to clarify exactly what needs to be localized.

I also recommend that you use Feedback Assistant to submit a enhancement request for (say) a way of controlling the concatenation of comment strings, to avoid the source code mismatch issue if the comments happen to be different.

Issues with String Catalogs comments and git
 
 
Q