0

I have created a Localizable.strings file in Xcode to handle translating my iOS app into several different languages. I have the following code at one point in the app:

Text("\(tasks.count) Tasks")

In other parts of the code where the string is simply "Tasks", I am able to translate this into Spanish relatively easily using the following localizable.string:

"Tasks" = "Tareas";

This does not work when I try to translate the "(tasks.count) Tasks". The 'Tasks' never gets converted. I tried the following localizable.string:

"%@ Tasks" = "%@ Tareas";

That also didn't work. Has anyone run into a similar problem? How did you fix this issue?

Thanks -

FontFamily
  • 355
  • 4
  • 13
  • Am I supposed to use "NSLocalizedString"? – FontFamily Dec 14 '20 at 03:27
  • https://stackoverflow.com/questions/62042521/localization-with-string-interpolation-in-swiftui I've also followed the advice in that SO, but that also doesn't seem to work. – FontFamily Dec 14 '20 at 04:10
  • I also followed @Asperi advice here: https://stackoverflow.com/questions/61684038/swiftui-localization-of-a-dynamic-text?rq=1 - that also doesn't seem to work. In fact, none of my dynamic text strings are working. It's gotta be with the way they are constructed. – FontFamily Dec 14 '20 at 04:17

1 Answers1

0

This is really frustrating and I don't really understand why this works and the alternatives I explored don't work. Here is the solution:

Text(String(format: NSLocalizedString("Tasks %d", comment: ""),
                                tasks.count))

My string was:

"Tasks %d" = "Tareas %d";

I'm hoping someone has a good explanation as to why reformatting a dynamic text string as above is needed instead of using the conventional Text("(xyz) Text")

FontFamily
  • 355
  • 4
  • 13