sway library

Sway — The localization layer for Flutter.

Features

  • Format + codegen — author nested JSON per locale, generate type-safe Dart (context.t.home.welcome(name: …)). Run dart run sway:codegen.
  • Overlay - debug floating bubble to switch locale / force RTL without changing device settings. Prefer Sway.debugOverlay under MaterialApp.builder for production shells; works with ARB / easy_localization / slang via adapters.
  • Migrate CLI — convert ARB, easy_localization, or slang into Sway JSON.

Quick links

  • Full integration: see the package README and doc/INTEGRATION.md
  • Overlay-only (keep ARB): see doc/OVERLAY_ONLY.md
  • Migration: see doc/MIGRATION.md

Tooling APIs that touch the filesystem live in package:sway/codegen.dart (CLI / VM only — not needed in your Flutter app import).

Classes

EasyLocalizationAdapter
Adapter for apps using easy_localization.
ForceRebuildScope
Wraps the app's MaterialApp/WidgetsApp to guarantee a full Localizations + Directionality remount on locale change.
IntlAdapter
Adapter for apps using Flutter gen-l10n / intl (ARB).
ListenableLocaleAdapter
Bridges an existing listenable locale owner (GetIt service, ChangeNotifier, ValueNotifier, etc.) into SwayOverlay without a hand-rolled adapter class.
ManualAdapter
Adapter for apps using a custom localization setup.
OverlayController
Manages the overlay's state: current locale, force RTL/LTR flags, expanded/collapsed state, and bubble position.
Sway
Namespace for Sway convenience APIs.
SwayFormatAdapter
Adapter for apps using Sway's own generated format.
SwayLocaleAdapter
Interface that the Sway overlay uses to interact with the host app's localization system.
SwayLocaleMeta
Metadata about a locale used by the overlay and codegen.
SwayOverlay
A floating, draggable locale-switching overlay for development.

Enums

PluralCategory
CLDR plural categories.

Constants

kRtlLanguageCodes → const Set<String>
Known RTL language codes.

Functions

isRtlLanguage(String languageCode) → bool
Returns true if languageCode is a known RTL language.
resolvePlural(String languageCode, num count) → PluralCategory
Resolves which plural category applies for a given count in languageCode.
supportedCategories(String languageCode) → Set<PluralCategory>
Returns the plural categories supported by languageCode.

Exceptions / Errors

SwayCodegenException
Thrown when codegen encounters an unrecoverable error.
SwayEncodingException
Thrown when a locale file has non-UTF8 encoding.
SwayFormatException
Base exception for all Sway format-related errors.
SwayJsonParseException
Thrown when a locale file contains invalid JSON syntax.
SwayValidationException
Thrown when validation detects a schema violation.