skip to Main Content

I have this Text in SwiftUI :

Text("Level (level.id)" + (level.isEnded ? " ended" : ""))

This string does not automatically go to the Strings catalog.
What is the best way to deal with this kind of text and localization ?

Thanks

2

Answers


  1. You could put the text together using individual words or parts of a sentence, but this can get complicated for full sentences in different languages.

    When the number of cases is limited as with your example, I would suggest using separate translations instead:

    Text(level.isEnded ? "LEVEL_ENDED (level.id)" : "LEVEL_NOT_ENDED (level.id)")
    
    "LEVEL_ENDED %lld" = "Level %lld ended";
    "LEVEL_NOT_ENDED %lld" = "Level %lld";
    
    Login or Signup to reply.
  2. You can also do this:

     Text("Level (level.id) ( Text(level.isEnded ? "ended" : "") )")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search