I've found that I need to support localization from the very start.<p>I never display a quoted string. I always use Apple's tokenization (or create my own, if doing server code).<p>Apple has terrific support for localization, which puts the onus on us, to honor it. I have some basic extensions that I use to support localization in my coding[0-2], but there's also just stuff I need to keep in mind, all the time.<p>There has been discussion of how to deal with things like word order in different languages. For example, in Germanic languages, the modifier usually precedes the subject, while in Romance languages, it tends to be the opposite.<p>Thankfully, Apple supports the "$" format for sprintf strings[3], so we can do stuff like this:<p><pre><code> import Foundation
let localizationAssets = [
(format: "The %1$@ %2$@", modifier: "white", subject: "horse"),
(format: "Le %2$@ %1$@", modifier: "blanc", subject: "cheval")
]
func localizedHorse(_ inLocalization: Int) -> String {
String(
format: localizationAssets[inLocalization].format,
localizationAssets[inLocalization].modifier,
localizationAssets[inLocalization].subject
)
}
// English (Prints "The white horse")
print(localizedHorse(0))
// French (Prints "Le cheval blanc")
print(localizedHorse(1))
</code></pre>
[0] <a href="https://github.com/RiftValleySoftware/RVS_Generic_Swift_Toolbox/blob/master/Sources/RVS_Generic_Swift_Toolbox/RVS_Generic_Swift_Toolbox_Extensions/RVS_Foundation_Extensions.swift#L184">https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...</a><p>[1] <a href="https://github.com/RiftValleySoftware/RVS_Generic_Swift_Toolbox/blob/master/Sources/RVS_Generic_Swift_Toolbox/RVS_Generic_Swift_Toolbox_Extensions/RVS_Foundation_Extensions.swift#L192">https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...</a><p>[2] <a href="https://github.com/RiftValleySoftware/RVS_Generic_Swift_Toolbox/blob/master/Sources/RVS_Generic_Swift_Toolbox/RVS_Generic_Swift_Toolbox_Extensions/RVS_Foundation_Extensions.swift#L200">https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...</a><p>[3] <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW2" rel="nofollow noreferrer">https://developer.apple.com/library/archive/documentation/Co...</a>