NAME
Table::Translations - simple translations for templating
SYNOPSIS
use Table::Translations;
VERSION
This documents version 0.00_01 of Table-Translations corresponding to git commit 9b9b0b6002304d6c1e40118afd900c2be5faa9f6 released on Thu Jan 28 23:49:21 2021 +0900.
DESCRIPTION
Very simple translation storage. I made this because TMX 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 in Table::Readable format with each translated piece of text being identified with the code id
then each particular language having its own entry.
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
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.