I want to localize my application; I am using Swift 2. I followed this tutorial but I experience 2 issues.
I localized multiple images the same way for German and English. One set of images (the en and de versions of an image) disappear for both languages. I added them, they are in the project's folder and I can not spot any difference to other images I localized.
I tried
…nothing helped. Any idea?
NSLocalizedString
& Localizable.strings
I created a Localizable.strings
for localizing my app's strings. Here is how I make them localizable:
button.setTitle(NSLocalizedString("buttonTitle", comment: "MyButton"), forState: .Normal)
In the Localizable.strings
for English I added:
"buttonTitle" = "MyButton"
…and for German:
"buttonTitle" = "MeinButton"
Now, Xcode does not show any errors in code but it says
Read failed:
The data couldn't be read because it isn't in the correct format.
Any ideas?
Thank you in advance :)
Issue #2 was resolved, I missed a ;
there. Thanks to codingVoldemort!
Import Localize at the top of each Swift file that will contain localized text. Add .localized () following any String object you want translated: To get an array of available localizations:
Localize-Swift is a simple framework that improves i18n and localization in Swift iOS apps - providing cleaner syntax and in-app language switching. Keep the Localizable.strings file your app already uses.
Luckily, Apple has made changes and improvements in SwiftUI that take a lot of the guesswork out of your localization workflow. Export and import strings from and to your project. Preview localizations while developing. Use new techniques to work with localized strings. Localize asset catalog items. Use Markdown to format localized strings.
In this tutorial I want to show how to translate a text string in Swift code file to a different language. Suppose you have an English text string in your .swift code: The text can be internationalized with NSLocalizedString function: The comment will be passed along with the text to translators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With