Skip to content

kumarneel/SwiftLingo

Repository files navigation

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 Localizable called where you would like to store your localized information
  • Create a .swift file called LocalizableStrings

  • Create a .xcstrings 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.xcstrings file. The new language will automatically appear next to English
Screenshot 2023-12-15 at 1 22 24 PM

Usage

Create your first key in your English Translation file

"log_in_title" = "Login";

Screenshot 2024-01-10 at 4 44 45 PM

Import SPM SwiftLingo Package

Initialize in AppDelegate or anywhere AND RUN ON SIMULATOR


// '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"
)

Watch as files auto-populate once logs are complete

Screenshot 2024-01-10 at 4 50 20 PM

Use localized string variable in View

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()
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages