Localization is time-consuming so I made a package to automate the task.
- Import the pacakge
https://github.com/kumarneel/SwiftLingo
- Setup a folder
Localizable
called where you would like to store your localized information
-
Create a
.swift
file calledLocalizableStrings
-
Create a
.xcstrings
file calledLocalizable
, Xcode will automatically call it by this name
- Go to Project Settings tab
Info
- Go to the Localization Section
- Click
+
and add any Language that you would like to translate into
- NOTE, these language codes are important and will passed into SwiftPackage Initializer
- Go back to your
Localizable.xcstrings
file. The new language will automatically appear next to English
"log_in_title" = "Login";
// 'fr' is the French Language Code
SL.initialize(
// Path to the root directory where files are stored
directoryPath: "/Users/photos/Desktop/Localization/SwiftLingoTest/SwiftLingoTest/Localization",
desiredLanguages: ["en", "fr"],
openAPIKey: "your_API_KEY"
)
import SwiftUI
import SwiftLingo
struct ContentView: View {
var body: some View {
VStack {
Text(LocalizableStrings.log_in_title)
}
.padding()
.onAppear {
SL.initialize(
directoryPath: "/Users/photos/Desktop/RE/TestSwiftLingo/TestSwiftLingo/Localizable",
desiredLanguages: ["en", "fr"],
openAPIKey: "YOUR_API_KEY"
)
}
}
}
#Preview {
ContentView()
}