Skip to content

Instantly share code, notes, and snippets.

@AmrAbedal
Last active January 8, 2023 03:03
Show Gist options
  • Save AmrAbedal/4a8be2fedd13c3217698752db3a25bf9 to your computer and use it in GitHub Desktop.
Save AmrAbedal/4a8be2fedd13c3217698752db3a25bf9 to your computer and use it in GitHub Desktop.
iOS XIB Localization tips
"Welcome_back"="Welcome back";
"PromoCodeAmount"="You have a promo code for %d %@";
import Foundation
extension String {
var localized: String {
return NSLocalizedString(self, comment: "")
}
func getLocalized(arg: CVarArg...) -> String {
return String.init(format: self.localized,arguments: arg)
}
}
import UIKit
extension UIButton {
@IBInspectable
var localizednormalTextKey: String {
set{
setTitle(newValue, for: .normal)
}
get{
return titleLabel?.text ?? ""
}
}
@IBInspectable
var localizedSelectedTextKey: String {
set{
setTitle(newValue, for: .selected)
}
get{
return titleLabel?.text ?? ""
}
}
@IBInspectable
var localizedDisableTextKey: String {
set{
setTitle(newValue, for: .selected)
}
get{
return titleLabel?.text ?? ""
}
}
}
import UIKit
extension UILabel {
@IBInspectable
var localizedTextKey: String {
set{
self.text = newValue.localized
}
get{
return text ?? ""
}
}
}
import UIKit
extension UINavigationItem {
@IBInspectable
var localizedTextKey: String {
set{
self.title = newValue.localized
}
get{
return title ?? ""
}
}
}
import UIKit
extension UITextField {
@IBInspectable
var KeyPlaceholder: String {
set{
self.placeholder = newValue.localized
}
get{
return placeholder ?? ""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment