iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌐
[SwiftUI] Localizing Text with Embedded Images
Suppose you have text like the following:
Text("The symbol \(Image(systemName: "globe")) represents the earth.")
To localize this into Japanese, you can do it as follows. Simply replace the entire variable interpolation part with %@.
localizable.strings
"The symbol %@ represents the earth." = "%@という記号は地球を表しています。";
It works fine even if multiple Images are embedded.
Text("The symbol \(Image(systemName: "globe")) represents the earth and the symbol \(Image(systemName: "sun")) represents the sun.")
localizable.strings
"The symbol %@ represents the earth and the symbol %@ represents the sun." = "%1$@という記号は地球を表していて、%2$@という記号は太陽を表しています。";
I was quite worried about this, but I'm glad I finally found a very simple solution.
Discussion