<<

NAME

Koha::I18N - Internationalization functions for Koha

SYNOPSIS

    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();

DESCRIPTION

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.

FUNCTIONS

init

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.

__x

    my $translated = __x('Hello {name}', name => 'World');

Translation with variable substitution. Variables in {brackets} are replaced with the corresponding values from the provided hash.

__n

    my $translated = __n('one item', '{count} items', $count);

Plural-aware translation. Returns singular or plural form based on the count.

__nx

    my $translated = __nx('one item', '{count} items', $count, count => $count);

Plural-aware translation with variable substitution.

__xn

Alias for __nx.

__p

    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).

__px

    my $translated = __px('context', 'Hello {name}', name => 'World');

Context-aware translation with variable substitution.

__np

    my $translated = __np('context', 'one item', '{count} items', $count);

Context-aware plural translation.

__npx

    my $translated = __npx('context', 'one item', '{count} items', $count, count => $count);

Context-aware plural translation with variable substitution.

N__

    my $msgid = N__('Text for later translation');

No-operation translation marker. Returns the original text unchanged but marks it for extraction by translation tools.

N__n

    my $msgid = N__n('singular', 'plural');

No-operation plural translation marker.

N__p

    my $msgid = N__p('context', 'Text for later translation');

No-operation context translation marker.

N__np

    my $msgid = N__np('context', 'singular', 'plural');

No-operation context plural translation marker.

available_locales

    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.

AUTHOR

Koha Development Team

COPYRIGHT

Copyright 2012-2014 BibLibre

LICENSE

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.

<<