HoraLocale class abstract

Abstract base class for locale definitions.

Implement this class to add support for a new language. All locale classes should be immutable with const constructors for optimal performance and tree-shaking.

Built-in Locales

Hora includes 143 locale definitions. The most common are:

  • HoraLocaleEn - English (default)
  • HoraLocaleZhCn - Chinese (Simplified)

Import additional locales from package:hora/src/locales/:

import 'package:hora/src/locales/ja.dart'; // Japanese
import 'package:hora/src/locales/ko.dart'; // Korean
import 'package:hora/src/locales/de.dart'; // German

Usage

// Per-instance locale
final h = Hora.now(locale: const HoraLocaleJa());
print(h.format('MMMM D日')); // 12月 5日

// Change locale on existing instance
final h2 = h.withLocale(const HoraLocaleEn());

// Global default locale
Hora.globalLocale = const HoraLocaleZhCn();

Creating Custom Locales

class HoraLocaleEs extends HoraLocale {
  const HoraLocaleEs();

  @override
  String get code => 'es';

  @override
  List<String> get months => const [
    'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
    'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'
  ];

  @override
  List<String> get monthsShort => const [...];

  @override
  List<String> get weekdays => const [...];

  @override
  List<String> get weekdaysShort => const [...];

  @override
  List<String> get weekdaysMin => const [...];

  // Optional overrides for formats, relativeTime, ordinal, meridiem
}
Implementers
Available extensions
Annotations
  • @immutable

Constructors

HoraLocale()
const

Properties

code String
The locale code (e.g., 'en', 'zh-cn', 'ja').
no setter
formats HoraFormats
Localized date formats.
no setter
hashCode int
The hash code for this object.
no setteroverride
invalidDate String
Invalid date string.
no setter
months List<String>
Full month names (January, February, ...).
no setter
monthsShort List<String>
Abbreviated month names (Jan, Feb, ...).
no setter
relativeTime HoraRelativeTime
Relative time expressions.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
weekdays List<String>
Full weekday names starting from Sunday.
no setter
weekdaysMin List<String>
Minimum weekday names (Su, Mo, ...).
no setter
weekdaysShort List<String>
Short weekday names (Sun, Mon, ...).
no setter
weekStart int
First day of week.
no setter
yearStart int
Minimum days in the first week of year.
no setter

Methods

meridiem(int hour, int minute, {bool lowercase = false}) String
Returns the meridiem indicator (AM/PM or locale equivalent).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ordinal(int n, [String? unit]) String
Returns the ordinal suffix for a number (1st, 2nd, 3rd, etc.).
toString() String
A string representation of this object.
inherited
update({String? code, List<String>? months, List<String>? monthsShort, List<String>? weekdays, List<String>? weekdaysShort, List<String>? weekdaysMin, int? weekStart, int? yearStart, String? invalidDate, HoraFormats? formats, HoraRelativeTime? relativeTime, String ordinal(int n, String? unit)?, String meridiem(int hour, int minute, {bool lowercase})?}) UpdatedLocale

Available on HoraLocale, provided by the UpdateLocaleExtension extension

Creates a new locale with updated properties.
updateFormats({String? lt, String? lts, String? l, String? ll, String? lll, String? llll}) UpdatedLocale

Available on HoraLocale, provided by the UpdateLocaleExtension extension

Creates a new locale with updated formats.
updateRelativeTime({String? future, String? past, String? s, String? m, String? mm, String? h, String? hh, String? d, String? dd, String? w, String? ww, String? mo, String? mos, String? y, String? yy}) UpdatedLocale

Available on HoraLocale, provided by the UpdateLocaleExtension extension

Creates a new locale with updated relative time.

Operators

operator ==(Object other) bool
The equality operator.
override