ローカライズ
Localizable.strings を更新します。
キー
SwiftGen を使ってコード生成しているので、キーは CamelCase で適当な粒度で .
で区切ってグルーピングします。
画面名.要素
または 画面名.要素.状態
となるようにしてください。
画面名は AccountListViewController
の場合 AccountList
とします。ViewController を付けると長くなるので省略します。
例
class ConfirmViewController: UIViewController {
@IBOutlet private var detailLabel: UILabel {
didSet {
detailLabel.text = L10n.FooBar.detailText
}
}
@IBOutlet private var decideButton: UIButton {
didSet {
decideButton.setTitle(L10n.FooBar.Decide.normal, .normal)
decideButton.setTitle(L10n.FooBar.Decide.disabled, .normal)
}
}
override func viewDidLoad() {
super.viewDidLoad()
title = L10n.FooBar.title
}
}
/* No comment provided by engineer. */
"FooBar.title" = "確認画面";
/* No comment provided by engineer. */
"FooBar.detailText" = "この内容でよろしいですか?";
/* No comment provided by engineer. */
"FooBar.decide.normal" = "決定";
/* No comment provided by engineer. */
"FooBar.decide.disabled" = "項目を選択してください";
画面以外の要素のローカライズ
UIView のサブクラスや enum など、型に紐付いて様々な画面で使う文言があるときは、画面名.要素
ではなく 型名.要素
を使います。
enum
enum HogeState {
case wating
case progress
case finish
}
extension HogeState {
var localizedString: String {
switch self {
case .wating:
return L10n.HogeState.wating
case .progress:
return L10n.HogeState.progress
case .finish:
return L10n.HogeState.finish
}
}
}
/* No comment provided by engineer. */
"HogeState.wating" = "待機中";
/* No comment provided by engineer. */
"HogeState.progress" = "処理中";
/* No comment provided by engineer. */
"HogeState.finish" = "終了";
UIView などの suffix がつくクラス
suffix を省略せずにクラス名をキーとします。
class FollowButton: UIButton {
override func awakeFromNib() {
super.awakeFromNib()
setTitle(L10n.FollowButton.title, for: .normal)
}
}
/* No comment provided by engineer. */
"FollowButton.title" = "フォローする";
それ以外の共通のローカライズ
OK
のような複数の画面で使う言葉は Common
としてグルーピングします。
修正する場合は影響範囲に注意してください。
/* No comment provided by engineer. */
"Common.OK" = "OK";
複数形のローカライズ
Localizable.stringsdict にエントリを追加します。L10n に数値を渡すメソッドとして追加されます。 キー名のルールは Localizable.strings と同様にして下さい。VARIABLE には最低限 other を含めます。