intl4xA lightweight, modular library for internationalization (i18n) in Dart, providing locale-sensitive formatting, featuring:
We're actively iterating on the API for this package. Please provide feedback via our issue tracker.
This package currently increases binary size in non-web builds significantly. To remedy, compile your app the experimental flag record-use
dart --enable-experiment=record-use build cli --target my-binary-name.dart
This library uses different backends on different platforms:
Intl functionalities for web-only applications, reducing bundle size.Add intl4x to your pubspec.yaml:
dart pub add intl4x
There are still some features missing:
Format DateTime objects into locale-sensitive strings for dates, times, and time zones.
import 'package:intl4x/datetime_format.dart'; void main() { final dateTime = DateTime(2024, 7, 1, 8, 50, 07); final germanLocale = Locale.parse('de-DE'); final formatter = DateTimeFormat.yearMonthDayTime( locale: germanLocale, length: DateTimeLength.long, ).withTimeZoneLong(); // Format with a specific timezone print(formatter.format(dateTime, 'Europe/Berlin')); // prints "1. Juli 2024 um 10:50:07 Mitteleuropäische Sommerzeit" }
Format numbers as decimals, percentages, or in compact form with locale-specific rules.
import 'package:intl4x/number_format.dart'; void main() { final locale = Locale.parse('en-US'); final compactFormat = NumberFormat.compact(locale: locale); print(compactFormat.format(12345)); // "12K" final percentFormat = NumberFormat.percent(locale: locale); print(percentFormat.format(0.987)); // "99%" }
Sort lists of strings with locale-aware collation.
import 'package:intl4x/collation.dart'; void main() { final list = ['Z', 'a', 'z', 'ä']; final german = Collation(locale: Locale.parse('de-DE')); list.sort(german.compare); print(list); // prints "[a, ä, z, Z]" }
Get localized display names for locales, regions, scripts, and currencies.
import 'package:intl4x/display_names.dart'; void main() { final displayNames = DisplayNames(locale: Locale.parse('en')); print(displayNames.ofLocale(Locale.parse('fr-CA'))); // "Canadian French" print(displayNames.ofRegion('419')); // "Latin America" }
Join lists of items into a grammatically correct, locale-sensitive string.
import 'package:intl4x/list_format.dart'; void main() { final list = ['apples', 'bananas', 'oranges']; final english = Locale.parse('en'); print(list.joinAnd(locale: english)); // "apples, bananas, and oranges" print(list.joinOr(locale: english)); // "apples, bananas, or oranges" }
Select the correct plural category for a given number based on locale rules (e.g., one, few, many).
import 'package:intl4x/plural_rules.dart'; void main() { final rules = PluralRules( locale: Locale.parse('en-US'), type: PluralType.ordinal, ); print(rules.select(1)); // PluralCategory.one (st) print(rules.select(2)); // PluralCategory.two (nd) print(rules.select(3)); // PluralCategory.few (rd) print(rules.select(4)); // PluralCategory.other (th) }
Change the case of strings according to locale-specific rules.
import 'package:intl4x/case_mapping.dart'; void main() { final tr = Locale.parse('tr'); final en = Locale.parse('en'); final upper = 'TICKET'; print(upper.toLocaleLowerCase(en)); // ticket print(upper.toLocaleLowerCase(tr)); // tıcket final lower = 'i'; print(lower.toLocaleUpperCase(en)); // I print(lower.toLocaleUpperCase(tr)); // İ }