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

NAME

Jenkins::i18n - functions for the jtt CLI

SYNOPSIS

    use Jenkins::i18n qw(remove_unused find_files load_properties load_jelly find_langs);

DESCRIPTION

jtt is a CLI program used to help translating the Jenkins properties file.

This module implements some of the functions used by the CLI.

EXPORT

None by default.

FUNCTIONS

find_missing

Compares the keys available from the source (Jelly and/or Properties files) with the i18n file and updates the statistics based on the missing keys, i.e., the keys that exists in the source but not in the i18n Properties file.

Expects as parameters the following:

  1. a hash reference with all the keys/values from the Jelly/Properties file.

  2. a hash reference with all the keys/values from the i18n Properties file.

  3. a instance of a Jenkins::i18n::Stats class.

  4. a instance of Jenkins::i18n::Warnings class.

merge_data

Merges the translation data from a Jelly file and a Properties file.

Expects as parameters:

  1. A hash reference with all the keys/values from a Jelly file.

  2. A hash reference with all the keys/values from a Properties file.

This methods considers the way Jenkins is translated nowadays, considering different scenarios where the Jelly and Properties have different data.

Returns a hash reference with the keys and values merged.

dump_keys

Prints to STDOUT all keys from a hash, using some formatting to make it easier to read.

Expects as parameter a hash reference.

all_data

Retrieves all translation data from a single given file as reference.

Expects as parameter a complete path to a file.

This file can be a Properties or Jelly file. From that file name, it will be defined the related other files, by convention.

Returns a array reference, where each index is:

  1. A hash reference with all keys/values for the English language.

  2. A hash reference with all the keys/values for the related language.

  3. A hash reference for the keys retrieved from the respective Jelly file.

Any of the return references may point to an empty hash, but at list the first reference must point to a non-empty hash.

remove_unused

Remove unused keys from a properties file.

Each translation in every language depends on the original properties files that are written in English.

This function gets a set of keys and compare with those that are stored in the translation file: anything that exists outside the original set in English is considered deprecated and so removed.

Expects as positional parameters:

  1. file: the complete path to the translation file to be checked.

  2. keys: a Set::Tiny instance of the keys from the original English properties file.

  3. license: a scalar reference with a license to include the header of the translated properties file.

  4. backup: a boolean (0 or 1) if a backup file should be created in the same path of the file parameter. Optional.

Returns the number of keys removed (as an integer).

find_files

Find all Jelly and Java Properties files that could be translated from English, i.e., files that do not have a ISO 639-1 standard language based code as a filename prefix (before the file extension).

Expects as parameters:

  1. The complete path to a directory that might contain such files.

  2. An instance of Set::Tiny with all the languages codes identified. See find_langs.

Returns an Jenkins::i18n::FindResults instance.

find_langs

Finds all ISO 639-1 standard language based codes available in the Jenkins repository based on the filenames sufix (before the file extension) of the translated files.

This is basically the opposite of find_files does.

It expect as parameters the complete path to a directory to search for the files.

Returns a instance of the Set::Tiny class containing all the language codes that were identified.

Find all files Jelly and Java Properties files that could be translated from English, i.e., files that do not have a ISO 639-1 standard language based code as a filename prefix (before the file extension).

load_properties

Loads the content of a Java Properties file into a hash.

Expects as position parameters:

  1. The complete path to a Java Properties file.

  2. True (1) or false (0) if a warn should be printed to STDERR in case the file is missing.

Returns an hash reference with the file content. If the file doesn't exist, returns an empty hash reference.

load_jelly

Fill a hash with key/1 pairs from a .jelly file.

Expects as parameter the path to a Jelly file.

Returns a hash reference.

SEE ALSO

AUTHOR

Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2022 of Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>

This file is part of Jenkins Translation Tool project.

Jenkins Translation Tool 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.

Jenkins Translation Tool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Jenkins Translation Tool. If not, see (http://www.gnu.org/licenses/).

The original translation-tool.pl script was licensed through the MIT License, copyright (c) 2004-, Kohsuke Kawaguchi, Sun Microsystems, Inc., and a number of other of contributors. Translations files generated by the Jenkins Translation Tool CLI are distributed with the same MIT License.