0. 들어가기 전에..
기본적인 로컬라이즈(지역화) 방법은 아래 블로그를 참고하시면 쉽게 설정할 수 있습니다.
http://trend21c.tistory.com/1689
1. 스토리보드 로컬라이즈
protocol StroyBoardLocalizable {
var LocalizerKey: String? { get set }
일단, Label, Button, TextField 등 아웃렛에 사용할 프로토콜을 선언해주고..
extension UILabel: StroyBoardLocalizable {
@IBInspectable var LocalizerKey: String? {
get { return nil }
set(key) {
text = key?.localized
}
}
}
extension UIButton: StroyBoardLocalizable {
@IBInspectable var LocalizerKey: String? {
get { return nil }
set(key) {
setTitle(key?.localized, for: .normal)
}
}
}
위와 같이 Inspectable를 사용에서 스토리보드에 LocalizerKey를 추가하였습니다.
extension String {
var localized: String {
return NSLocalizedString(self, comment: self)
}
}
위와 같이 String에 로컬라이즈를 위해 Extension를 해주고나서, Localizable.strings 같은 로컬라이즈 파일에서 작성을 해주면 스토리보드에서 로컬라이즈를 할 필요가 없습니다.
2. 한계점
3. 참고 링크
'Programer > iOS' 카테고리의 다른 글
[Fastlane] iOS App 자동 배포 해보기 (0) | 2019.04.10 |
---|---|
[UI] TableView에서 이미지 크기에 따라 Cell 크기 조정하기 (0) | 2019.01.18 |
[FP] Imperative -> Declarative 예제를 통해 바꿔보기 (FizzBuzz) (0) | 2018.07.16 |
[FP] 함수 & 고차함수 vs 클로저 (0) | 2018.07.12 |
[FP] Functional Programing 용어 정리 (0) | 2018.07.10 |