have googled around but found no solution:
Basically, i have a Localizable.strings set up, which i'm using in my code. However, it would be really sweet if i somehow could just refer those values in my XIB's too, so that i can avoid having to create one annoying XIB per language...
Is this possible?
To add Localizable. strings file, go to File->New->File , choose Strings File under Resource tab of iOS, name it Localizable. strings , and create the file. Now, you have a Localizable.
create a new file of type "Strings File", call it Localizable. strings. select the new file and navigate to File Inspector in the right hand side panel and click Localize... go to your project file to the Localizations section and add another language to the list - Xcode will create localization files for you.
There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file. the strings included in your project, that are particular to the current project: the name of your application, file names, registry values, properties etc.
You could implement a subclass of UILabel and have it automatically pull the localized value when it's initialized from the nib. In the XIB you would then just set the token (or english text if you prefer) and have UILabel pull the localized text from this value.
I present to you the swifty way
1. Create a subclass of UILabel
class LozalizedLabel : UILabel {
@IBInspectable var keyValue: String {
get {
return self.text!
}
set(value) {
self.text = NSLocalizedString(value, comment: "")
}
}
}
2. Set the class to be LocalizedLabel in IB
3. Enter your key from Localizable.strings directly in IB
Voila, now spend less time on creating useless IBOutlets just for making it a localizable UILabel.
NOTE This does not make the localized string show in the interface builder, but rather just the "key". So when building your TextView's remember to set constraints accordingly
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