Blame Automation/Modules/Locale/Modules/File/file.sh

Alain Reguera Delgado 786ac0
#!/bin/bash
Alain Reguera Delgado 5f643d
######################################################################
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
#   file.sh -- This module standardize localization of files inside
Alain Reguera Delgado 5f643d
#   the repository.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
#   Written by:
Alain Reguera Delgado 5f643d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado bb076b
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 5f643d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado bb076b
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado bb076b
# your option) any later version.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 5f643d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 5f643d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 5f643d
# General Public License for more details.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 5f643d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 5f643d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
######################################################################
Alain Reguera Delgado bd3978
Alain Reguera Delgado bd3978
function file {
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define absolute path to argument passed in the command-line.
Alain Reguera Delgado 786ac0
    local FILE=$(tcar_checkRepoDirSource "${1}")
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Verify argument passed in the command-line does exist and is a
Alain Reguera Delgado 5f643d
    # regular file.
Alain Reguera Delgado bd3978
    tcar_checkFiles -ef ${FILE}
Alain Reguera Delgado bd3978
Alain Reguera Delgado 5f643d
    # Define file name.
Alain Reguera Delgado 786ac0
    local FILE_NAME="$(basename ${FILE})"
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define file extension.
Alain Reguera Delgado 786ac0
    local FILE_EXTENSION=$(echo ${FILE} | sed -r 's/.+\.([[:alnum:]]+)$/\1/')
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define absolute path to directory holding the files to process.
Alain Reguera Delgado 786ac0
    local DIRECTORY=$(dirname ${FILE})
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define list of files to process.
Alain Reguera Delgado 2eb4e7
    local RENDER_FROM=$(locale_getFilesList)
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define absolute path to directory holding language-specific
Alain Reguera Delgado 5f643d
    # content.
Alain Reguera Delgado 786ac0
    local LOCALE_FROM=${DIRECTORY}/Locales
Alain Reguera Delgado 2eb4e7
    if [[ ! -d ${LOCALE_FROM} ]];then
Alain Reguera Delgado 2eb4e7
        mkdir ${LOCALE_FROM}
Alain Reguera Delgado 2eb4e7
    fi
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define absolute path to portable and machine objects.
Alain Reguera Delgado 786ac0
    local POT_FILE=${LOCALE_FROM}/${FILE_NAME}.pot
Alain Reguera Delgado 786ac0
    local PO_FILE=${LOCALE_FROM}/${TCAR_SCRIPT_LANG_LC}/${FILE_NAME}.po
Alain Reguera Delgado 786ac0
    local MO_FILE=${LOCALE_FROM}/${TCAR_SCRIPT_LANG_LC}/LC_MESSAGES/${FILE_NAME}.mo
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 5f643d
    # Define the rendition type you want to perform.
Alain Reguera Delgado 5f643d
    local RENDER_TYPE=${FILE_EXTENSION}
Alain Reguera Delgado 5f643d
Alain Reguera Delgado 5f643d
    # Define the translation file you want to use.
Alain Reguera Delgado 5f643d
    local -a TRANSLATIONS
Alain Reguera Delgado 5f643d
    TRANSLATIONS[0]=${PO_FILE}
Alain Reguera Delgado 5f643d
Alain Reguera Delgado 5f643d
    # Define translation file. This is from which translatable strings
Alain Reguera Delgado 5f643d
    # will be retrieved.
Alain Reguera Delgado 5f643d
    local -a SOURCES
Alain Reguera Delgado 5f643d
    for SOURCE in ${RENDER_FROM};do
Alain Reguera Delgado 5f643d
        SOURCES[((++${#SOURCES[*]}))]=${SOURCE}
Alain Reguera Delgado 5f643d
    done
Alain Reguera Delgado 5f643d
Alain Reguera Delgado 5f643d
    # Process configuration variables through locale's actions module.
Alain Reguera Delgado 06ab0f
    tcar_setModuleEnvironment -m "actions" -t "sib-module"
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 786ac0
}