intl4xA lightweight, modular library for internationalization (i18n) in Dart, providing locale-sensitive formatting, featuring:
This package has now moved from experimental to preview. We will not ship any breaking changes, but are still iterating on some components. Please provide feedback via our issue tracker!
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 08: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 form for a given number based on locale rules.
import 'package:intl4x/plural_rules.dart'; void main() { final rules = PluralRules( locale: Locale.parse('en-US'), type: PluralType.ordinal, ); String numberPlural(int i) => rules.select(i, one: 'st', two: 'nd', few: 'rd', other: 'th'); print(numberPlural(1)); // 'st' print(numberPlural(2)); // 'nd' print(numberPlural(3)); // 'rd' print(numberPlural(4)); // '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)); // İ }