GettextTranslator.Util.LanguageNames (gettext_translator v0.8.0)

Copy Markdown View Source

Maps POSIX language codes to full language names and ISO codes. Used primarily for TranslateGemma prompt formatting.

Summary

Functions

Returns the ISO/BCP47 language code for a given POSIX locale code.

Returns the full language name for a given POSIX locale code.

Functions

iso_code(posix_code)

@spec iso_code(String.t()) :: String.t()

Returns the ISO/BCP47 language code for a given POSIX locale code.

Converts POSIX underscore format (pt_BR) to BCP47 hyphen format (pt-BR).

Examples

iex> GettextTranslator.Util.LanguageNames.iso_code("en")
"en"

iex> GettextTranslator.Util.LanguageNames.iso_code("pt_BR")
"pt-BR"

iex> GettextTranslator.Util.LanguageNames.iso_code("zh_CN")
"zh-Hans"

language_name(posix_code)

@spec language_name(String.t()) :: String.t()

Returns the full language name for a given POSIX locale code.

Falls back to the base language if the full code is not found, and to the code itself if no mapping exists.

Examples

iex> GettextTranslator.Util.LanguageNames.language_name("en")
"English"

iex> GettextTranslator.Util.LanguageNames.language_name("pt_BR")
"Portuguese"

iex> GettextTranslator.Util.LanguageNames.language_name("unknown")
"unknown"