DateTime::Locale(3) User Contributed Perl Documentation DateTime::Locale(3)

# [SYNOPSIS](#SYNOPSIS)

```
  use DateTime::Locale;
  my $loc = DateTime::Locale->load('en-GB');
  print $loc->native_name, "\n", $loc->datetime_format_long, "\n";
  # but mostly just things like ...
  my $dt = DateTime->now( locale => 'fr' );
  print "Aujourd'hui le mois est " . $dt->month_name, "\n";
```

# [DESCRIPTION](#DESCRIPTION)

DateTime::Locale is primarily a factory for the various locale subclasses. It also provides some functions for getting information on all the available locales.

If you want to know what methods are available for locale objects, then please read the DateTime::Locale::FromData documentation.

# [USAGE](#USAGE)

This module provides the following class methods:

## DateTime::Locale-&gt;load( $locale\_code | $locale\_name )

Returns the locale object for the specified locale code or name - see the DateTime::Locale::Catalog documentation for the list of available codes and names. The name provided may be either the English or native name.

If the requested locale is not found, a fallback search takes place to find a suitable replacement.

The fallback search order is:

```
  {language}-{script}-{territory}
  {language}-{script}
  {language}-{territory}-{variant}
  {language}-{territory}
  {language}
```

Eg. For the locale code "es-XX-UNKNOWN" the fallback search would be:

```
  es-XX-UNKNOWN   # Fails - no such locale
  es-XX           # Fails - no such locale
  es              # Found - the es locale is returned as the
                  # closest match to the requested id
```

Eg. For the locale code "es-Latn-XX" the fallback search would be:

```
  es-Latn-XX      # Fails - no such locale
  es-Latn         # Fails - no such locale
  es-XX           # Fails - no such locale
  es              # Found - the es locale is returned as the
                  # closest match to the requested id
```

If no suitable replacement is found, then an exception is thrown.

The loaded locale is cached, so that **locale objects may be singletons**. Calling "DateTime::Locale-&gt;register\_from\_data", "DateTime::Locale-&gt;add\_aliases", or "DateTime::Locale-&gt;remove\_alias" clears the cache.

## [DateTime::Locale-&gt;codes](#DateTime::Locale)

```
  my @codes = DateTime::Locale->codes;
  my $codes = DateTime::Locale->codes;
```

Returns an unsorted list of the available locale codes, or an array reference if called in a scalar context. This list does not include aliases.

## [DateTime::Locale-&gt;names](#DateTime::Locale~2)

```
  my @names = DateTime::Locale->names;
  my $names = DateTime::Locale->names;
```

Returns an unsorted list of the available locale names in English, or an array reference if called in a scalar context.

## [DateTime::Locale-&gt;native\_names](#DateTime::Locale~3)

```
  my @names = DateTime::Locale->native_names;
  my $names = DateTime::Locale->native_names;
```

Returns an unsorted list of the available locale names in their native language, or an array reference if called in a scalar context. All native names use UTF-8 as appropriate.

## DateTime::Locale-&gt;register\_from\_data( $locale\_data )

This method allows you to register a custom locale. The data for the locale is specified as a hash (or hashref) where the keys match the method names given in DateTime::Locale::FromData.

If you just want to make some small changes on top of an existing locale you can get that locale's data by calling "$locale-&gt;locale\_data".

Here is an example of making a custom locale based off of "en-US":

```
  my $locale = DateTime::Locale->load('en-US');
  my %data   = $locale->locale_data;
  $data{code}               = 'en-US-CUSTOM';
  $data{time_format_medium} = 'HH:mm:ss';
  DateTime::Locale->register_from_data(%data);
  # Prints 18:24:38
  say DateTime->now( locale => 'en-US-CUSTOM' )->strftime('%X');
  # Prints 6:24:38 PM
  say DateTime->now( locale => 'en-US' )->strftime('%X');
```

The keys that should be present in the hash are the same as the accessor methods provided by DateTime::Locale::FromData, except for the following:

[The \*\_code methods](#The)

While you should provide a "code" key, the other methods like "language\_code" and "script\_code" are determined by parsing the code.

[All "id" returning methods](#All)

These are aliases for the corresponding \*code methods.

"prefers\_24\_hour\_time"

This is determined by looking at the short time format to see how it formats hours,

"date\_format\_default" and "time\_format\_default"

These are the corresponding medium formats.

"datetime\_format" and "datetime\_format\_default"

This is the same as the medium format.

"date\_formats" and "time\_formats"

These are calculated as needed.

"available\_formats"

This should be provided as a hashref where the keys are things like "Gy" or "MMMEd" and the values are an actual format like "y G" or "E, MMM d".

"locale\_data"

This is everything you pass in.

# [LOADING LOCALES IN A PRE-FORKING SYSTEM](#LOADING_LOCALES_IN_A_PRE)

If you are running an application that does pre-forking (for example with Starman), then you should try to load all the locales that you'll need in the parent process. Locales are loaded on-demand, so loading them once in each child will waste memory that could otherwise be shared.

# [CLDR DATA BUGS](#CLDR_DATA_BUGS)

Please be aware that all locale data has been generated from the CLDR (Common Locale Data Repository) project locales data). The data is incomplete, and may contain errors in some locales.

When reporting errors in data, please check the primary data sources first, then where necessary report errors directly to the primary source via the CLDR bug report system. See &lt;http://unicode.org/cldr/filing\_bug\_reports.html&gt; for details.

Once these errors have been confirmed, please forward the error report and corrections to the DateTime mailing list, datetime@perl.org.

# [AUTHOR EMERITUS](#AUTHOR_EMERITUS)

Richard Evans wrote the first version of DateTime::Locale, including the tools to extract the CLDR data.

# [SEE ALSO](#SEE_ALSO)

datetime@perl.org mailing list

2026-10-30 perl v5.44.0

---

Document: DateTime::Locale(3pm) from perl-datetime-locale 1.47-r0 (Chainguard OS)
Source: https://github.com/houseabsolute/DateTime-Locale
