Kernel::Language

NAME

Kernel::Language – global language interface

DESCRIPTION

All language functions.

PUBLIC INTERFACE

new()

create a language object. Do not use it directly, instead use:

    use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new(
        'Kernel::Language' => {
            UserLanguage => 'de',
        },
    );
    my $LanguageObject = $Kernel::OM->Get('Kernel::Language');

Translatable()

this is a no-op to mark a text as translatable in the Perl code.

Translate()

translate a text with placeholders.

        my $Text = $LanguageObject->Translate('Hello %s!', 'world');

FormatTimeString()

formats a timestamp according to the specified date format for the current language (locale).

    my $Date = $LanguageObject->FormatTimeString(
        '2009-12-12 12:12:12',  # timestamp
        'DateFormat',           # which date format to use, e. g. DateFormatLong
        0,                      # optional, hides the seconds from the time output
        0,                      # optional, forces the method to add the timezone info if possible
    );

Please note that the TimeZone will not be applied in the case of DateFormatShort (date only) to avoid switching to another date.

If you only pass an ISO date ('2009-12-12'), it will be returned unchanged. Invalid strings will also be returned with an error logged.

Time()

Returns a time string in language format (based on translation file).

    $Time = $LanguageObject->Time(
        Action => 'GET',
        Format => 'DateFormat',
    );

    $TimeLong = $LanguageObject->Time(
        Action => 'GET',
        Format => 'DateFormatLong',
    );

    $TimeLong = $LanguageObject->Time(
        Action => 'RETURN',
        Format => 'DateFormatLong',
        Year   => 1977,
        Month  => 10,
        Day    => 27,
        Hour   => 20,
        Minute => 10,
        Second => 05,
    );

These tags are supported: %A=WeekDay;%B=LongMonth;%T=Time;%D=Day;%M=Month;%Y=Year;

Note that %A only works correctly with Action GET, it might be dropped otherwise.

Also note that it is also possible to pass HTML strings for date input:

    $TimeLong = $LanguageObject->Time(
        Action => 'RETURN',
        Format => 'DateInputFormatLong',
        Mode   => 'NotNumeric',
        Year   => '<input value="2014"/>',
        Month  => '<input value="1"/>',
        Day    => '<input value="10"/>',
        Hour   => '<input value="11"/>',
        Minute => '<input value="12"/>',
        Second => '<input value="13"/>',
    );

Note that %B may not work in NonNumeric mode.

LanguageChecksum()

This function returns an MD5 sum that is generated from all loaded language files and their modification timestamps. Whenever a file is changed, added or removed, this checksum will change.

LanguageStats()

This method is auto-generated by Dev::Tools::TranslationsUpdate.

HumanReadableDataSize()

Produces human readable data size.

    my $SizeStr = $LanguageObject->HumanReadableDataSize(
        Size => 123,  # size in bytes
    );

Returns

    $SizeStr = '123 B';         # example with decimal point: 123.4 MB

NumberToLocaleString()

converts provided number to the localized string (thousand and decimal separators), based on the user language. Avoid usage of this method for the data that is returned to the frontend, since it's localized there. Still, it's needed for some places, like Template generator.

    my $LocaleString = $LanguageObject->NumberToLocaleString(
        Number               => '1234.5',
        MinimumDecimalPlaces => 2,             (optional) minimum number of desired decimal places (default 2)
        MaximumDecimalPlaces => 2,             (optional) maximum number of desired decimal places (default 2)
    );

Returns

    $LocaleString = '1,234.50';
Scroll to Top