LinuxCommandLibrary

localedef

Create locale definitions from specification files

TLDR

List compiled locales

$ localedef --list-archive
copy

Display help
$ localedef [[-?|--help]]
copy

SYNOPSIS

localedef [OPTION...] OUTPUT_PATH

PARAMETERS

-i inputfile, --input-file=inputfile
    Specifies the path to the locale definition source file to be compiled.

-f charmap, --charmap=charmap
    Specifies the character map (or codeset) to be used for the locale. This defines the character set encoding for the locale, e.g., 'UTF-8' or 'ISO-8859-1'.

-c, --no-archive
    By default, compiled locales are added to a system-wide locale archive. This option prevents the locale from being added to the archive, storing it as an individual file instead.

-A archive_path, --add-to-archive=archive_path
    Adds the compiled locale to a specified locale archive file, rather than the default system archive.

--force
    Forces localedef to overwrite an existing locale definition without prompting.

--check
    Performs a syntax check on the input file but does not compile or install the locale. Useful for validating locale definitions.

-v, --verbose
    Produces more detailed output during the compilation process, showing progress and information about the processed definitions.

--no-warnings
    Suppresses all warning messages during compilation.

--warnings=level
    Sets the warning level. Common levels include 'error' (treat warnings as errors) or 'all' (show all possible warnings).

DESCRIPTION

The localedef command is a utility used to compile locale definition source files into a binary locale object. These binary files are then utilized by C library functions (such as setlocale(3), strcoll(3), and strftime(3)) to provide language and culture-specific behaviors for applications running on a Linux system.

A locale definition file, typically with a .ld or .def extension, contains detailed specifications for various locale categories, including character classification, collation sequences, monetary formatting, date and time representation, and message formatting. When localedef processes such a file, it checks the syntax and semantics, and then generates a compact, optimized binary representation of the locale data.

This compiled locale data is crucial for internationalization (i18n) and localization (l10n), enabling systems to correctly display and process text, numbers, and dates according to regional conventions. The output binary files are usually stored in system-wide directories like /usr/lib/locale or /usr/share/locale, making them accessible to all applications that rely on the system's locale settings.

CAVEATS

Compiling locales generally requires root privileges to write to system directories (e.g., /usr/lib/locale).
Incorrect or malformed locale definitions can lead to unexpected behavior in applications that rely on locale data.
Care must be taken to match the specified character map with the actual encoding of the input source file to avoid corruption.

LOCALE SOURCE FILES

Locale definition source files (e.g., en_US.UTF-8.ld) are plain text files structured into categories like LC_CTYPE (character classification), LC_COLLATE (string comparison), LC_MONETARY (currency formatting), LC_NUMERIC (numeric formatting), LC_TIME (date and time formatting), and LC_MESSAGES (affirmative/negative responses). These categories collectively define the locale's behavior across various aspects.

OUTPUT LOCATION AND LOCALE ARCHIVE

Compiled locale files are typically stored in a directory structure under /usr/lib/locale/ or /usr/share/locale/, where each locale gets its own subdirectory (e.g., /usr/lib/locale/en_US.UTF-8/). For performance, many systems also maintain a 'locale archive' (e.g., /usr/lib/locale/locale-archive), which is a single file containing all compiled locales. This archive allows applications to load locale data more efficiently, reducing disk I/O when switching locales.

HISTORY

localedef is a fundamental utility in Linux and Unix-like operating systems, stemming from the POSIX standard for internationalization (i18n). Its functionality has been a core component of the GNU C Library (glibc) for decades, providing the necessary infrastructure to compile human-readable locale source definitions into machine-readable binary formats. This process is essential for enabling applications to adapt to diverse linguistic and cultural conventions, reflecting its long-standing importance in system-level internationalization efforts.

SEE ALSO

locale(1), setlocale(3), localectl(1), charmap(5), locale(5), iconv(1)

Copied to clipboard