The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Table::Trans - simple translations for templating

SYNOPSIS

    use Table::Trans;

VERSION

This documents version 0.00_01 of Table-Trans corresponding to git commit bcdc6d76d92a1a70412803559f8e2dd72419537f released on Fri Jan 29 08:47:28 2021 +0900.

DESCRIPTION

Very simple translation storage based on the Table::Readable format. We made this because TMX (Translation Memory eXchange, an XML format) was such a pain to use.

FUNCTIONS

get_lang_name

    my $language = get_lang_name ($lang);

Given a language code like en, convert it into the native name of the language, like "English".

get_lang_trans

     get_lang_trans ($trans, $vars, $lang);

Put the translations from $trans for language $lang into $vars->{trans}.

read_trans

    my $trans = read_trans ('file.txt');

Also get the order:

    my ($trans, $order) = read_trans ('file.txt');

Read a file of translations in Table::Readable format.

trans_to_json_file

    trans_to_json_file ('file.txt', 'file.json');

Convert the translations in file.txt into file.json.

write_trans

     write_trans (\%trans, [qw/en ja es/], "output.txt", \@id_order);

Write the translations stored in %trans for the languages "en", "ja" and "es" in the order given by @id_order to the file output.txt in the Table::Readable format.

FORMAT

The basic format of the translations is the Table::Readable format, with each translated piece of text being identified with the code id then each particular language having its own entry.

Unfortunately the language code for Indonesian is id, so this module may have to be updated to cope with the Indonesian language.

Macros

Macros to insert another translation can be used in the form {{id}} and the translation of id in the language of the entry will be inserted, so if we have

    id: ape
    en: monkey
    ja: さる

    id: monkeyshines
    en: {{ape}}shines
    ja: {{ape}}さわぎ

then the ja entry for the ID "monkeyshines" will be さるさわぎ and the English entry will be "monkeyshines". There is currently no cross-language way of getting macros or non-language way of inserting them.

DEPENDENCIES

JSON::Create

This is used for storing the translations in JSON format.

JSON::Parse

This is only used by the tests.

Table::Readable

This is used as the basic format for storing and editing translations.

AUTHOR

Ben Bullock, <bkb@cpan.org>

COPYRIGHT & LICENCE

This package and associated files are copyright (C) 2021 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.