logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

I18N::LangTags::Detect - detect the user's language preferences

Author

Sean M. Burke "sburke@cpan.org" perl v5.40.1 2025-07-03 I18N::LangTags::Detect(3perl)

Description

It is a common problem to want to detect what language(s) the user would prefer output in.

Environment

This module looks at several environment variables: REQUEST_METHOD, HTTP_ACCEPT_LANGUAGE, LANGUAGE, LC_ALL, LC_MESSAGES, and LANG. It will also use the Win32::Locale module, if it's installed and IGNORE_WIN32_LOCALE is not set to a true value in the environment.

Functions

This module defines one public function, I18N::LangTags::Detect::detect(). This function is not exported (nor is even exportable), and it takes no parameters. In scalar context, the function returns the most preferred language tag (or undef if no preference was seen). In list context (which is usually what you want), the function returns a (possibly empty) list of language tags representing (best first) what languages the user apparently would accept output in. You will probably want to pass the output of this through I18N::LangTags::implicate_supers_tightly(...) or I18N::LangTags::implicate_supers(...), like so: my @languages = I18N::LangTags::implicate_supers_tightly( I18N::LangTags::Detect::detect() );

Name

I18N::LangTags::Detect - detect the user's language preferences

See Also

I18N::LangTags, Win32::Locale, Locale::Maketext. (This module's core code started out as a routine in Locale::Maketext; but I moved it here once I realized it was more generally useful.)

Synopsis

use I18N::LangTags::Detect; my @user_wants = I18N::LangTags::Detect::detect();

See Also