OPENLOCALE / DOCUMENTATION

Make the world
feel a little closer.

A shared translation catalog. Native resources. Typed calls in the languages you already use.

Download the working starter

Getting started

Download and extract the starter. Open a terminal in its openlocale directory. Use a full-ICU Node 24 installation and Go 1.24 or newer to run all local checks.

npm ci
npm run build
npm run verify

The build validates all locales before generating four independent packages in generated/. The verification command checks generated output, compiler and browser-runtime tests, TypeScript types, and Go integration behavior.

The starter is a working source project. Package names and the Go module path are examples. Update openlocale.config.json before publishing your packages.

The configured locales are English (en), Spanish (es), French (fr), Hausa (ha), Igbo (ig), Yoruba (yo), Efik (efi) and Nigerian Pidgin (pcm). Each has a basic greeting. The non-English greetings are drafts for language review; untranslated messages explicitly use English text and plural rules.

The catalog

Declare each message in catalog/messages.json. Its arguments array defines the shared API and the order used by generated native resources.

{
  "messages": {
    "welcome_user": {
      "description": "A greeting for a returning user.",
      "arguments": [{ "name": "name", "type": "string" }]
    },
    "unread_messages": {
      "description": "Number of unread messages.",
      "arguments": [{ "name": "count", "type": "integer" }],
      "plural": "count"
    }
  }
}

The complete English source contains every message. Locales in partialLocales may start small, for example locales/efi.json contains {"hello": "Mọkọm"}. Missing messages fall back to English; supplied messages still receive full validation.

A plural message is supplied as a complete locale-specific group:

{
  "welcome_user": "Welcome back, {name}!",
  "unread_messages": {
    "one": "You have {count} unread message.",
    "other": "You have {count} unread messages."
  }
}
  • Use flat lower_snake_case keys and named {arguments}. Repeat or reorder placeholders freely.
  • Use {{ and }} for literal braces. For example, {{name}} displays {name}.
  • Argument types are string and signed 32-bit integer. Plural counts must be non-negative integers.
  • Plural categories are locale-specific. The validator requires every category for that locale, plus other.
  • Add another canonical BCP 47 locale tag to the config, then create its matching JSON file.

Efik plain strings work without ICU plural data. Efik plural messages currently use the English source until reviewed plural support is available; the compiler never borrows the host machine’s default language rules.

Full ICU expressions, gender/select rules, ordinals, and decimal plural counts are outside this version’s grammar. Pass dates, currencies, and decimal values as strings formatted by the consuming application. Markup is treated as plain text.

React

Install the generated web package into an existing React app. This example uses a local folder; the same package can be packed into a tarball or published to your registry.

npm install ../openlocale/generated/web i18next react-i18next

Initialize i18next before rendering:

import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import {
  resources, namespace, sourceLocale
} from '@openlocale/translations';

await i18next.use(initReactI18next).init({
  resources,
  lng: 'en',
  fallbackLng: sourceLocale,
  defaultNS: namespace,
  interpolation: { escapeValue: false },
});

Use the generated hook for typed calls:

import { useOpenLocale } from '@openlocale/translations/react';

function Greeting() {
  const { strings } = useOpenLocale();
  return <h1>{strings.welcomeUser({ name: 'Ada' })}</h1>;
}

Call i18next.changeLanguage('fr') to update React subscribers. The wrapper selects the translated resource through i18next, then safely substitutes arguments using OpenLocale’s grammar. Use the typed wrapper rather than raw t() calls for these resources.

For server-side rendering, create an i18next instance per request and provide it through I18nextProvider. Render results as text, not raw HTML.

Android / Jetpack Compose

Include generated/android as a Gradle library module, or integrate its resources and generated Kotlin file into your module with the configured namespace. Align the Gradle plugin versions with your host application.

import dev.openlocale.translations.Translations

@Composable
fun Greeting() {
    Text(Translations.welcomeUser(name = "Ada"))
    Text(Translations.unreadMessages(count = 21))
}

Outside Compose, call the context overload:

val greeting = Translations.welcomeUser(context, "Ada")

Android manages the active app locale and resource fallback. Plural messages use R.plurals; regular messages use R.string. The generated APIs preserve argument positions across reordered translations.

The included library targets minimum SDK 21 and compile SDK 35. JDK 17 and Gradle 8.11.1 are used by the integration build.

SwiftUI

Add generated/ios as a local Swift package. It includes localized resources in its own bundle and strongly typed Swift accessors.

import SwiftUI
import OpenLocale

struct Greeting: View {
    @Environment(\.locale) private var locale

    var body: some View {
        let strings = L10n(locale: locale.identifier)
        Text(strings.welcomeUser(name: "Ada"))
    }
}

Recreate L10n when the SwiftUI environment locale changes. An explicit locale matches a supported localization, removes subtags if needed, and finally falls back to the source locale. L10n() uses the package’s preferred system localization.

Apple .stringsdict resources handle plurals. The package supports iOS 15+ and macOS 12+. SwiftGen is not required.

Go backend

Use the generated Go module with your configured import path. All locale JSON is embedded in the binary, so no translation files need to be deployed separately.

import translations "example.com/openlocale/translations"

strings, err := translations.New("fr-CA,fr;q=0.9,en;q=0.8")
if err != nil {
    return err
}

greeting, err := strings.WelcomeUser("Ada")
if err != nil {
    return err
}

The immutable translation bundle is loaded once. Reuse a translator for the same language preferences, or create one per request. In a handler, pass the request’s Accept-Language header to New. Typed methods return (string, error).

Delivery & updates

Keep the catalog and generated files in version control. After an edit, regenerate, review the diff, and verify:

npm run build
npm run verify

The included GitHub workflow validates the compiler and web APIs on Windows and Linux, runs native Swift tests on macOS, and builds and tests the Android resources on Linux. Successful runs upload all four packages as an artifact.

  • React: pack generated/web or publish it to your npm registry.
  • Android: consume the Gradle module, copy generated resources through a reviewed PR, or publish its AAR.
  • Swift: publish the contents of generated/ios at the root of a dedicated Swift package repository.
  • Go: publish the generated module at the configured import path. Subdirectory modules require matching import paths and version-tag prefixes.

Each app adopts updates through its normal build and release process. There is no over-the-air delivery. Platform runtimes can use different CLDR versions, so test your supported locales on representative OS versions.

For detailed behavior and implementation notes, see the README.md included in the starter.