Skip to main content

Localization & Translations

The Reachu SDK supports multiple languages through a configurable translation system. You can define translations directly in your configuration JSON file or in a separate file.

Overview

The localization system provides:

  • Multi-language supportfor all SDK components
  • Separate translation filesto keep config clean
  • Default English translationsbuilt-in
  • Fallback languagesupport
  • Easy key managementwith centralized translation keys

Configuration

To keep your configuration file clean, use a separate file for translations:

reachu-config.json:

reachu-config.json
{
"apiKey": "your-api-key",
"environment": "sandbox",
"localization": {
"defaultLanguage": "es",
"fallbackLanguage": "en",
"translationsFile": "reachu-translations"
}
}

reachu-translations.json(in the same folder):

reachu-translations.json
{
"translations": {
"en": {
"cart.title": "Cart",
"cart.empty": "Your cart is empty",
"checkout.title": "Checkout"
},
"es": {
"cart.title": "Carrito",
"cart.empty": "Tu carrito está vacío",
"checkout.title": "Checkout"
},
"no": {
"cart.title": "Handlekurv",
"cart.empty": "Handlekurven din er tom",
"checkout.title": "Kasse"
}
}
}

Option 2: Inline Translations (For Few Translations)

If you prefer everything in one file:

reachu-config.json
{
"apiKey": "your-api-key",
"environment": "sandbox",
"localization": {
"defaultLanguage": "es",
"fallbackLanguage": "en",
"translations": {
"en": {
"cart.title": "Cart",
"checkout.title": "Checkout"
},
"es": {
"cart.title": "Carrito",
"checkout.title": "Checkout"
}
}
}
}

File Structure

YourApp/
Configuration/
reachu-config.json ← Main configuration
reachu-translations.json ← Translations (optional)

Configuration Properties

  • defaultLanguage: Default language (e.g., "en", "es", "no", "sv")
  • fallbackLanguage: Fallback language if translation missing (default: "en")
  • translationsFile: Name of external translation file (without .json extension)
  • translations: Object with translations by language (optional if using translationsFile)

Usage in Code

ContentView.swift
import ReachuCore

struct ContentView: View {
var body: some View {
VStack {
// Use helper function
Text(RLocalizedString("cart.title"))

// With default value
Text(RLocalizedString("cart.title", defaultValue: "Cart"))
}
}
}

Option 2: Direct Access

ContentView.swift
import ReachuCore

struct ContentView: View {
var body: some View {
VStack {
// Direct access
Text(ReachuLocalization.shared.getString("cart.title"))

// With default value
Text(ReachuLocalization.shared.getString("cart.title", defaultValue: "Cart"))
}
}
}

Option 3: Change Language Dynamically

SettingsView.swift
import ReachuCore

struct SettingsView: View {
@State var selectedLanguage = "en"

var body: some View {
Form {
Picker("Language", selection: $selectedLanguage) {
Text("English").tag("en")
Text("Español").tag("es")
Text("Norsk").tag("no")
}
.onChange(of: selectedLanguage) { newLanguage in
ReachuLocalization.shared.setLanguage(newLanguage)
}
}
}
}

Available Translation Keys

Common

  • common.addToCart - "Add to Cart"
  • common.remove - "Remove"
  • common.close - "Close"
  • common.cancel - "Cancel"
  • common.confirm - "Confirm"
  • common.continue - "Continue"
  • common.back - "Back"
  • common.next - "Next"
  • common.done - "Done"
  • common.loading - "Loading..."
  • common.error - "Error"
  • common.success - "Success"
  • common.retry - "Retry"
  • common.apply - "Apply"
  • common.save - "Save"
  • common.edit - "Edit"
  • common.delete - "Delete"

Cart

  • cart.title - "Cart"
  • cart.empty - "Your cart is empty"
  • cart.emptyMessage - "Add products to continue with checkout"
  • cart.itemCount - "Items"
  • cart.items - "items"
  • cart.item - "item"
  • cart.quantity - "Quantity"
  • cart.subtotal - "Subtotal"
  • cart.total - "Total"
  • cart.shipping - "Shipping"
  • cart.tax - "Tax"
  • cart.discount - "Discount"
  • cart.removeItem - "Remove item"
  • cart.updateQuantity - "Update quantity"

Checkout

  • checkout.title - "Checkout"
  • checkout.proceed - "Proceed to Checkout"
  • checkout.initiatePayment - "Initiate Payment"
  • checkout.completePurchase - "Complete Purchase"
  • checkout.purchaseComplete - "Purchase Complete!"
  • checkout.purchaseCompleteMessage - "Your order has been confirmed..."
  • checkout.paymentFailed - "Payment Failed"
  • checkout.paymentFailedMessage - "Your payment could not be processed..."
  • checkout.tryAgain - "Try Again"
  • checkout.goBack - "Go Back"
  • checkout.processingPayment - "Processing Payment"
  • checkout.processingPaymentMessage - "Please complete your payment..."

Address

  • address.shipping - "Shipping Address"
  • address.billing - "Billing Address"
  • address.firstName - "First Name"
  • address.lastName - "Last Name"
  • address.email - "Email"
  • address.phone - "Phone"
  • address.address - "Address"
  • address.city - "City"
  • address.state - "State"
  • address.zip - "ZIP"
  • address.country - "Country"

Payment

  • payment.method - "Payment method"
  • payment.selectMethod - "Select a payment method to continue"
  • payment.noMethods - "No payment methods available"
  • payment.schedule - "Payment Schedule"
  • payment.downPaymentDueToday - "Down payment due today"
  • payment.installment - "Installment"
  • payment.payNext - "Pay next"
  • payment.confirmWithKlarna - "Confirm with Klarna"

Product

  • product.details - "Details"
  • product.description - "Description"
  • product.options - "Options"
  • product.inStock - "In Stock"
  • product.outOfStock - "Out of Stock"
  • product.sku - "SKU"
  • product.supplier - "Supplier"
  • product.category - "Category"
  • product.stock - "Stock"
  • product.available - "available"
  • product.noImage - "No Image Available"

Order

  • order.summary - "Order Summary"
  • order.id - "Order ID:"
  • order.review - "Review Order"
  • order.reviewContent - "Order review content..."
  • order.productSummary - "Product Summary"
  • order.totalForItem - "Total for this item:"
  • order.colors - "Colors:"

Shipping

  • shipping.options - "Shipping Options"
  • shipping.required - "Required"
  • shipping.noMethods - "No shipping methods available..."
  • shipping.calculated - "Shipping is calculated automatically..."
  • shipping.total - "Total shipping"

Discount

  • discount.code - "Discount Code"
  • discount.applied - "Discount applied"
  • discount.removed - "Discount removed"
  • discount.invalid - "Invalid discount code"

Validation

  • validation.required - "This field is required"
  • validation.invalidEmail - "Please enter a valid email address"
  • validation.invalidPhone - "Please enter a valid phone number"
  • validation.invalidAddress - "Please enter a complete address"

Errors

  • error.network - "Network error. Please check your connection."
  • error.server - "Server error. Please try again later."
  • error.unknown - "An unknown error occurred"
  • error.tryAgainLater - "Please try again later"

Supported Languages

The SDK supports any ISO 639-1 language code (2 letters). Common ones:

  • en - English
  • es - Español (Spanish)
  • no - Norsk (Norwegian)
  • sv - Svenska (Swedish)
  • da - Dansk (Danish)
  • fi - Suomi (Finnish)
  • de - Deutsch (German)
  • fr - Français (French)
  • pt - Português (Portuguese)
  • it - Italiano (Italian)

Default Behavior

If no translation files are provided:

  • SDK uses built-in English translations
  • Components display in English
  • No errors or warnings
  • App functions normally

Complete Example

App.swift
import SwiftUI
import ReachuCore
import ReachuUI

@main
struct MyApp: App {
init() {
// Load configuration (includes translations)
ConfigurationLoader.loadConfiguration()

// Set initial language
ReachuLocalization.shared.setLanguage("es")
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

struct ContentView: View {
var body: some View {
NavigationView {
VStack {
// Uses translations automatically
Text(RLocalizedString("cart.title"))
.font(.title)

Text(RLocalizedString("cart.empty"))
.foregroundColor(.secondary)
}
.navigationTitle(RLocalizedString("checkout.title"))
}
}
}

Best Practices

DO

  • Keep translations in a separate file for maintainability
  • Use consistent key naming (category.key)
  • Provide fallback translations for all languages
  • Test translations in your app before release
  • Use ISO 639-1 language codes

DON'T

  • Don't hardcode strings in Swift code
  • Don't mix languages in the same translation file
  • Don't use special characters that might cause JSON issues
  • Don't delete keys that are in use without checking first
  • Don't translate proper nouns or brand names

Updating Translations

When updating translations:

  1. Modify reachu-translations.json file
  2. Ensure JSON is valid
  3. Rebuild your app
  4. Translations load automatically

The SDK automatically loads translations when the app starts, so no code changes are needed after updating translation files.