common_locale_data 1.1.0 copy "common_locale_data: ^1.1.0" to clipboard
common_locale_data: ^1.1.0 copied to clipboard

A type-safe and tree-shakable API to access translated common data (measurement units, date fields, country names etc...)

example/main.dart

import 'package:common_locale_data/common_locale_data.dart';

void main() {
  // To preserve tree-shaking, you should explicitly choose the language your want
  // The compiler will only retain the languages that are explicitly referenced in your program
  // and discard all the others languages. It will make your deployed program smaller.

  // Setup the default language for English
  cld = CommonLocaleData.en;

  // If your app support several languages, dynamically choose the language you want
  var currentLanguage = 'en';
  cld = const {
    'en': CommonLocaleData.en,
    'fr': CommonLocaleData.fr,
  }[currentLanguage]!;

  // Units
  print(cld.units.lengthMeter); // meters
  print(cld.units.lengthMeter.long(3)); // 3 meters
  print(cld.units.lengthMeter.long(1)); // 1 meter

  print(cld.units.areaSquareMeter.long(3)); // 3 square meters
  print(cld.units.areaSquareMeter.short(3)); // 3 m²
  print(cld.units.areaSquareMeter.narrow(3)); // 3m²

  // Date fields
  print(cld.date.year.future.long(2)); // in 2 years
  print(cld.date.year.past.long(2)); // 2 years ago
  print(cld.date.year.next.long); // next year
  print(cld.date.year.previous.long); // last year

  // Territories
  print(cld.territories.africa); // Africa
  print(cld.territories.countries['US']); // United States

  // Languages
  print(cld.languages.languages['en']!.name); // English
}
1
likes
160
pub points
64%
popularity

Publisher

unverified uploader

A type-safe and tree-shakable API to access translated common data (measurement units, date fields, country names etc...)

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, intl

More

Packages that depend on common_locale_data