LoginSignup
5
5

More than 3 years have passed since last update.

SwiftUI Localization「Hello, World!」->「こんにちは、世界!」

Posted at

ベース

alt

Program

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Localizable.strings作成

alt

alt

alt

Localizationの「Localize...」押下
alt

Localizationsに言語追加

例:日本語追加
alt

alt

Localizable.strings配下にファイルが追加される
alt

Localizable.strings (Japanese)編集

"Hello, World!" = "こんにちは、世界!";

alt

追加した言語を表示させる

「ContentView_Previews」に「.environment(.locale, .init(identifier: "ja"))」追加

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .environment(\.locale, .init(identifier: "ja"))
    }
}

「Edit Scheme...」からでも可能
alt

alt

結果

alt

5
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5