Koha::I18N - Internationalization functions for Koha
use Koha::I18N;
# Basic translation functions
my $translated = __('Hello world');
my $with_vars = __x('Hello {name}', name => 'World');
my $plural = __n('one item', '{count} items', $count, count => $count);
# Context-aware translations
my $context = __p('menu', 'File');
# Get available system locales (explicitly imported)
use Koha::I18N qw(available_locales);
my $locales = available_locales();
This module provides internationalization (i18n) functions for Koha using the GNU gettext system. It handles locale setup, message translation, and provides utility functions for working with system locales.
The module automatically initializes the locale environment and provides a set of translation functions that support variable substitution, plural forms, and contextual translations.
Initializes the internationalization system by setting up locale environment variables and configuring gettext. This is called automatically when needed.
my $translated = __('Text to translate');
Basic translation function. Returns the translated text for the given message ID.
my $translated = __x('Hello {name}', name => 'World');
Translation with variable substitution. Variables in {brackets} are replaced with the corresponding values from the provided hash.
my $translated = __n('one item', '{count} items', $count);
Plural-aware translation. Returns singular or plural form based on the count.
my $translated = __nx('one item', '{count} items', $count, count => $count);
Plural-aware translation with variable substitution.
Alias for __nx.
my $translated = __p('context', 'Text to translate');
Context-aware translation. Allows the same text to be translated differently based on context (e.g., 'File' in a menu vs 'File' as a document type).
my $translated = __px('context', 'Hello {name}', name => 'World');
Context-aware translation with variable substitution.
my $translated = __np('context', 'one item', '{count} items', $count);
Context-aware plural translation.
my $translated = __npx('context', 'one item', '{count} items', $count, count => $count);
Context-aware plural translation with variable substitution.
my $msgid = N__('Text for later translation');
No-operation translation marker. Returns the original text unchanged but marks it for extraction by translation tools.
my $msgid = N__n('singular', 'plural');
No-operation plural translation marker.
my $msgid = N__p('context', 'Text for later translation');
No-operation context translation marker.
my $msgid = N__np('context', 'singular', 'plural');
No-operation context plural translation marker.
my $locales = Koha::I18N::available_locales();
Returns an arrayref of available system locales for use in system preferences.
Each locale is a hashref with: - value: The locale identifier (e.g., 'en_US.utf8', 'default') - text: Human-readable description (e.g., 'English (United States) - en_US.utf8')
Always includes 'default' as the first option. Additional locales are detected from the system using locale -a and filtered for UTF-8 locales.
Koha Development Team
Copyright 2012-2014 BibLibre
This file is part of Koha.
Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.