SwiftLingo

Localization is time-consuming so I made a package to automate the task.

Steps to setup, only take a few minutes!

  1. Import the pacakge https://github.com/kumarneel/SwiftLingo
  2. Setup a folder where you would like to store your localized information
  • Create a .swift file called LocalizableStrings

  • Create a .string file called Localizable, Xcode will automatically call it by this name

    Screenshot 2023-12-15 at 1 14 05 PM
  1. Go to Project Settings tab Info
  • Go to the Localization Section
Screenshot 2023-12-15 at 1 15 46 PM
  1. Click + and add any Language that you would like to translate into
  • NOTE, these language codes are important and will passed into SwiftPackage Initializer
Screenshot 2023-12-15 at 1 18 39 PM
  1. Go back to your Localizable.strings file. Go to the navigation tab on the right and click Localize...
Screenshot 2023-12-15 at 1 22 24 PM
  1. Check the languages you just added to be localized
Screenshot 2023-12-15 at 1 23 10 PM
  1. They will now appear under the file you have created
Screenshot 2023-12-15 at 1 23 40 PM

Usage

Create your first key in your English Translation file

"log_in_title" = "Login";

Import SwiftLingo

Initialize in AppDelegate or anywhere AND RUN ON SIMULATOR

// Path to root directory where files are stored
// 'fr' is the French Language Code
SL.initialize(
    directoryPath: "/Users/photos/Desktop/Localization/SwiftLingoTest/SwiftLingoTest/Localization",
    desiredLanguages: ["en", fr"],
    openAPIKey: "your_API_KEY"
)

Watch as files auto-populate once logs are complete

Screenshot 2023-12-15 at 3 11 55 PM

Use localized string variable in View

struct ContentView: View {
    var body: some View {
        VStack {
            Text(LocalizableStrings.log_in_title)
        }
        .padding()
    }
}

GitHub

View Github