swift-localize syncs translations from Google Sheets directly into your Xcode project's .xcstrings string catalogs.
Google Sheets is the source of truth: new keys appear in the app, renamed keys replace old ones, and removed keys are deleted from the catalog.
- macOS 14+
- Swift 6.2 toolchain (or compatible with this package)
- A Google Cloud service account with access to Google Sheets API
- Authenticate with Google using a service account JSON key.
- Read spreadsheet tabs and values.
- Parse translation rows (
keycolumn + one column per language). - For each tab, write translations directly into the mapped
.xcstringsfile inside your Xcode project.- Tabs not listed in
stringCatalogsfall back to writing intooutputDirectory.
- Tabs not listed in
Each sheet tab maps to one .xcstrings file. Rows follow this convention:
| key | de | en | fr |
|---|---|---|---|
| welcome_title | Willkommen | Welcome | Bienvenue |
| button_ok | OK | OK | OK |
The first column is the localization key. Subsequent columns are BCP-47 language codes.
- Open Google Cloud Console and create/select a project.
- Enable the Google Sheets API.
- Create a service account.
- Create and download a JSON key file.
- Share your target Google Sheet with the service account email (Viewer permission is sufficient).
Save the JSON key file locally, for example as ./credentials/google_drive_credentials.json.
Create a config file — typically placed next to your .xcodeproj:
{
"credentialsPath": "./credentials/google_drive_credentials.json",
"spreadsheetId": "YOUR_SPREADSHEET_ID",
"localizationPath": "./MyApp",
"sourceLanguage": "de"
}All paths are resolved relative to the config file's location. Each sheet tab is written as <localizationPath>/<tabName>.xcstrings directly into your Xcode project folder.
From the package root:
swift run swift-localize-cli --config /path/to/localize.jsonDefault (looks for ./localize.json in the current directory):
swift run swift-localize-cliShow help:
swift run swift-localize-cli --helpBuild a release binary:
swift build -c releaseBinary location:
.build/release/swift-localize-cli
Add the package to your Package.swift:
dependencies: [
.package(url: "<repository-url>", from: "0.1.0")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "swift-localize", package: "swift-localize")
]
)
]Then call it from your code:
import swift_localize
let config = try LocalizerConfig.load(from: "./localize.json")
let localizer = Localizer(config: config)
try await localizer.run()| Key | Required | Description |
|---|---|---|
credentialsPath |
Yes | Path to Google service account JSON key file. |
spreadsheetId |
Yes | Spreadsheet ID from the Google Sheets URL. |
localizationPath |
Yes | Directory inside your Xcode project where .xcstrings files live. Each tab is written as <localizationPath>/<tabName>.xcstrings. |
sourceLanguage |
Yes | BCP-47 language code used as source language (e.g. de). |
Run tests:
swift test