CodeFactor Codecov CodeRabbit Dart Code Metrics CI checks Pub points Last commit GitHub issues GitHub stars License: MIT Agent Skill Pub package Try in DartPad FOSSA Status FOSSA Status

This ISO-driven, pure Dart, fully tested and dependency-free package provides CLDR-like translations for currency names in 149 different locales. For Flutter-ready widgets (like currency picker) please use world_countries package. For Dart-only use - it's recommended to use together with sealed_currencies package.

Features

  • 149 locales bundled, with different coverage: 89 languages have at least 90% of the names, 38 have a part of them (13 of those only a few names), and 22 regional and script locales hold only the names that differ from their parent locales.
  • Three-letter ISO 4217 Alpha code lookup.
  • Fallback locale support, including parent locales (e.g. bs_Cyrl_BA → bs_Cyrl → bs). A script locale falls back to its language even if the language is written in another script (pa_Arab → pa): the result has the names of both, so show the first entry of each ISO code. Where the script locale has no name, that entry is the language's one, and it comes before any name of fallbackLocale.
  • Allows injecting custom translations, for new locales or in place of a bundled one (an injected locale replaces the bundled locale with the same key entirely).
  • Conditional formatting support, plus alternative names for injected translations (the bundled ones ship none, so they skip that lookup).
  • Tree-shakable via dart define flags.

Tip

Translations are provided in sentence case to ensure correct display for leading UI labels, avoiding ambiguous re-capitalization logic. To adapt these values for inline or mid-sentence usage, prefer the formatter callback.

Getting started

To use this package, add l10n_currencies as a dependency in your pubspec.yaml file.

dependencies:
  l10n_currencies: any

Then import the package in your Dart code:

import 'package:l10n_currencies/l10n_currencies.dart';

Note

Every l10n_* package exports its own IsoLocaleMapper, LocaleKey and LocaleMap. To import several of them in one file, use show (e.g. show CurrenciesLocaleMapper) or an import prefix.

Tip

Tree-shakable builds can be achieved by providing dart define flags to exclude unused locales. Without them, all 149 locales are compiled in: compared to an English-only build, that is over 1.4 MB more in a native (AOT) build and over 0.9 MB more of minified JS. For example, to include only EN and SK locales, use: dart run -Dl10n-en=true -Dl10n-sk=true or flutter run --dart-define=l10n-en=true --dart-define=l10n-sk=true Parent locales of the enabled ones are kept automatically (l10n-sw_cd=true also keeps sw), and l10n-<locale>=false drops a single locale. Enable the locale passed as fallbackLocale too.

Warning

Only flags of locales bundled in this package (its lib/src/data locales, which availableLocales lists in a build without flags), spelled like the locale or lowercased, switch it to this opt-in mode. Flags of other locales, such as l10n-en_US, l10n-pt_BR or the l10n-fil alias, are ignored: --dart-define=l10n-en=true --dart-define=l10n-pt_BR=true keeps English only and drops Portuguese. Name the bundled locale instead: l10n-pt, and l10n-tl for Flutter's fil (Filipino). In debug builds, localize() prints a warning the first time a requested locale and all its parents are missing for this reason.

Usage

Use the CurrenciesLocaleMapper class to localize currency names. Create an instance and use the localize method to get translations:

void main() {
  /// Create an instance of the mapper directly.
  final mapper = CurrenciesLocaleMapper();

  /// Define some ISO codes to localize (e.g., `USD` for US Dollar,
  /// `RUB` for Russian Ruble, etc.).
  final isoCodes = {"USD", "RUB", "PLN"};

  /// Localize the codes with an optional main locale (e.g., "sk" for Slovak),
  /// and an optional fallback locale (e.g., "cs" for Czech).
  final localized =
      mapper.localize(isoCodes, mainLocale: "sk", fallbackLocale: "cs");

  print("Names count: ${localized.length}"); // Prints: "Names count: 6".

  /// Print out the localized names.
  localized.forEach(
    (currency, l10n) => print(
      'Localized name of currency with ISO code "${currency.isoCode}" '
      'for locale "${currency.locale}" is "$l10n"',
    ),
  );
}

Important

Mapper instances are designed for single-use only. Bundled locales are built per localize() call and never stored in the mapper. Once localize() returns names, the mapper drops the translations injected via other and cannot be reused. Create a new instance if you need to localize again.

FAQ

  • No dependencies: This package has no dependencies, not even meta, ensuring that you won't have any issues or conflicts with other dependencies.
  • Memory efficient: Bundled locales are instantiated on demand, per localize() call, and never retained by the mapper - only the locales a call matches are built.
  • Rich data: This package offers tons of translations (all GlobalMaterialLocalizations and GlobalCupertinoLocalizations locales except Swiss German gsw, and more). Like in CLDR, some less common locales translate only a part of the names: their parent locales cover the rest first, then the fallbackLocale.
  • High code coverage: The code in this package has 100% code coverage, providing confidence in its reliability and stability.
  • Comprehensive documentation: This package provides full documentation for every non-code generated public member, usually with examples, ensuring clarity and ease of use.
  • Mirrored Repository: The GitHub repository, including all package tags, is mirrored on GitLab, providing an alternative access point should GitHub become unavailable.
  • Industry adopted: This package is actively used in production by numerous European companies, ensuring its efficacy and robustness in real-world scenarios.
  • Verified publisher: Published and maintained under an active, verified pub.dev publisher account since 2022.
  • Lightweight: This package keeps under 500 KB, ensuring it fits within the pub cache limit. This leads to quick, low-bandwidth downloads and faster caching, minimizing resource impact.
  • MIT license: This package and sources are released under the MIT license, which is a permissive license that allows users to use, modify, and distribute the code with minimal restrictions. The MIT license is considered better than most other open-source licenses because it provides flexibility and allows users to incorporate the code into their projects without worrying about legal implications.

Do you have AI agent instructions or skills?

Yes. This package bundles an official agent skill compliant with the Agent Skills specification.

To install it into your project for AI agents (Cursor, Claude Code, GitHub Copilot, Gemini):

dart run skills@ get -p l10n_currencies

Select l10n-currencies-localization when prompted.

Important

Key rule for LLM agents: CurrenciesLocaleMapper instances are designed for single-use only. They drop the translations injected via other once localize() returns names. Never cache or reuse mapper instances—always instantiate a new mapper per request and cache the localized result strings instead.

Additional information

If you like this package, please give it a star or like. For more information on using this package, check out the API documentation. PRs or ideas are always welcome. If you have any issues or suggestions for the package, please file them in the GitHub repository.

Note

Contributing on Windows: dart test also lints the bundled agent skill (test/agent_skills_test.dart), which starts dart pub publish via the dart.exe found on PATH. A Flutter-only setup puts just the dart.bat wrapper there, so this test fails with "needs the Dart SDK on PATH". Add <flutter>\bin\cache\dart-sdk\bin (or a standalone Dart SDK) to PATH.

References, credits and sources

Libraries

l10n_currencies
Provides currency translations for different locales.