Skip to content

Flutter .arb Localization

Replexica supports Flutter's Application Resource Bundle (.arb) format, making it easy to manage translations for your Flutter apps across multiple platforms.

Setting Up

To use Replexica with .arb files, configure your i18n.json as follows:

json
{
  "version": 1.2,
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "buckets": {
    "flutter": {
      "include": [
        "lib/l10n/[locale].arb"
      ]
    }
  }
}

TIP

Note the use of [locale] in the path, which Replexica will replace with the appropriate locale code.

How It Works

The .arb file is a JSON-based format that Flutter uses for localization. It supports both simple key-value pairs and more complex structures for pluralization and placeholders.

Here's an example of an .arb file structure:

json
{
  "helloWorld": "Hello World!",
  "@helloWorld": {
    "description": "The conventional newborn programmer greeting"
  },
  "welcomeUser": "Welcome, {username}!",
  "@welcomeUser": {
    "description": "A welcome message",
    "placeholders": {
      "username": {
        "type": "String",
        "example": "John Doe"
      }
    }
  },
  "itemCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}",
  "@itemCount": {
    "description": "A message showing the number of items",
    "placeholders": {
      "count": {
        "type": "num",
        "format": "compact"
      }
    }
  }
}

Localizing

To localize your .arb files, run:

npx replexica@latest i18n

Replexica will process your source .arb file and create or update the target language files.

Features

  1. Simple Strings: Replexica handles basic key-value translations.

  2. Placeholders: The loader preserves placeholders like {username} in translated strings.

  3. Pluralization: Replexica supports Flutter's plural syntax, ensuring correct translations for different quantity scenarios.

  4. Metadata: The loader preserves metadata for each string, including descriptions and placeholder information.

  5. Incremental Updates: Only new or changed strings are translated, saving time and processing power.

Pro Tips

  1. Consistency: Use consistent naming conventions for your ARB keys across your project.

  2. Context: Utilize the description field in your ARB files to provide context: Replexica's AI takes this into account for more accurate translations.

  3. Placeholders: When using placeholders, provide examples in the ARB file. This helps Replexica's AI understand the context better.

  4. Testing: Use Flutter's built-in localization testing tools to ensure your translations work correctly in your app.

  5. Multiple Files: If your project uses multiple .arb files, you can include them all in your i18n.json config:

    json
    "flutter": {
      "include": [
        "lib/l10n/[locale].arb",
        "lib/l10n/[locale]_additional.arb"
      ]
    }

By leveraging these features and tips, you can maintain a robust, scalable localization setup for your Flutter projects using the .arb format, seamlessly integrating with your existing development workflow.

For more information on other localization formats supported by Replexica, check out our documentation for other file types.