Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- DOCDIR="./doc/"
- FILESTOTRANSLATE="doc/en_US.ISO8859-1"
- DATAFILE="./translation-status.csv"
- LANGPARAM="$1"
- # commands
- AWK="/usr/bin/awk"
- BASENAME="/usr/bin/basename"
- CUT="/usr/bin/cut"
- FIND="/usr/bin/find"
- PRINTF="/usr/bin/printf"
- SVN="/usr/bin/svnlite"
- WC="/usr/bin/wc"
- SED="/usr/bin/sed"
- SORT="/usr/bin/sort"
- GREP="/usr/bin/grep"
- FIND_EN_DOC=`${FIND} ${DOCDIR} -name "??_*" -type d -depth 1 -print | ${SORT} | ${GREP} -v en_US`
- check_docdir() {
- if [ ! -d "${DOCDIR}" ]; then
- DOCDIR="doc/"
- if [ ! -d "${DOCDIR}" ]; then
- echo "** document directory not found, please edit and set DOCDIR"
- echo "** value to document checkout directory, like ~/doc"
- exit 1
- fi
- fi
- }
- check_lang_param() {
- if [ "${LANGPARAM}" ]; then
- # parameter was given, assume it is a single language directory
- case "${LANGPARAM}" in ??_??*) ;;
- # did not match the language code pattern
- *) echo "** parameter does not look like a language directory name,"
- echo "** expecting xx_YY*, like es_ES.ISO8859-1"
- exit 1 ;;
- esac
- LANGDIR=`${FIND} ${DOCDIR} -depth 1 -name "${LANGPARAM}".*`
- LANGS=`${BASENAME} ${LANGDIR}`
- else
- LANGS=${FIND_EN_DOC}
- fi
- }
- create_datafile() {
- echo "writing CSV data to ${DATAFILE}"
- ${PRINTF} > "${DATAFILE}" "langcode,pubtype,docname,status,needs updating\r\n"
- }
- print_title() {
- echo "FreeBSD document translations"
- echo
- }
- print_header() {
- # title
- ${PRINTF} " %-29s %-12s %-12s\n" document status needs_updating
- ${PRINTF} " %-27s %-12s %-12s\n" "-------------------------" "--------------" "--------------------------"
- }
- print_data() {
- langcode="$1"
- pubtype="$2"
- name="$3"
- status="$4"
- updating="$5"
- ${PRINTF} " %-29s %-12s %-12s\n" ${name} ${status} ${updating}
- ${PRINTF} >> "${DATAFILE}" "%s,%s,%s,%s,%s\r\n" ${langcode} ${pubtype} ${name} ${status} ${updating}
- }
- # Obtains the last modified date for a given file.
- get_file_date(){
- filename=$1
- filedate=""
- if [ -e "${filename}" ]; then
- filestat=`${SVN} stat ${filename} 2>&1 | ${CUT} -w -f1`
- if [ "${filestat}" != "?" -a "${filename}" != "svn:" ]; then
- if [ "${filestat}" = "A" ]; then
- # file has been added but not yet committed, no dates available
- filedate="*"
- else
- filedate=`${SVN} log -l 1 ${filename} | ${AWK} 'NR==2 { print $5 }'| ${SED} 's/\-//g'`
- fi
- fi
- fi
- }
- # Get the status of a given publication.
- get_doc_status(){
- pubtype=$1
- langcode=$2
- currdir=${PWD}
- cd ${FILESTOTRANSLATE}/${pubtype}/
- echo
- echo "**************" ${pubtype}
- echo
- doclist=`ls -d */ | sort`
- echo
- cd ${currdir}
- langdir=${DOCDIR}${langcode}
- print_header
- for doc in ${doclist}; do
- documents_total=$((${documents_total}+1))
- originalfile=${FILESTOTRANSLATE}/${pubtype}/${doc}
- get_file_date ${originalfile}
- originaldate=${filedate}
- translationdir=${langdir}/${pubtype}/${doc}
- dirbasename=`${BASENAME} "${translationdir}"`
- if [ -d "${translationdir}" ]; then
- documents_translated=$((${documents_translated}+1))
- status="translated"
- pofile="${translationdir}/${langcode}.po"
- altfile="${translationdir}/Makefile"
- if [ -e "${pofile}" ]; then
- get_file_date ${pofile}
- else
- if [ -e "${altfile}" ]; then
- get_file_date ${altfile}
- fi
- fi
- lastdate=${filedate}
- if [ "${lastdate}" == "*" ]; then
- # The file has been added to SVN but it hasn't been commited.
- updating="N/A"
- status="NOT_IN_SVN"
- else
- # The file is on SVN.
- if [ -d "${translationdir}" ]; then
- if [ ${originaldate} -gt ${lastdate} ]; then
- updating="YES"
- else
- updating="NO"
- fi
- fi
- fi
- else
- # The file has not been translated.
- status="untranslated"
- updating="N/A"
- fi
- print_data ${langcode} ${pubtype} ${dirbasename} ${status} ${updating}
- done
- }
- main() {
- documents_translated=0
- documents_total=0
- print_title
- check_docdir
- check_lang_param
- create_datafile
- echo
- for lang in ${LANGS}; do
- langcode=`${BASENAME} ${lang}`
- langcode_header=`${PRINTF} "%-.5s" ${langcode}`
- echo "-----------------------------" ${langcode_header} "-----------------------------"
- echo
- echo
- get_doc_status articles ${langcode}
- get_doc_status books ${langcode}
- get_doc_status captions ${langcode}
- get_doc_status htdocs ${langcode}
- get_doc_status slides ${langcode}
- echo
- echo "================================="
- echo "Statistics"
- echo
- echo
- echo " Total documents to translate: "${documents_total}
- echo " Documents translated: "${documents_translated}
- percentage=$(( 100* documents_translated/ documents_total ))
- echo " "${percentage}" % translated"
- echo "==================================="
- documents_translated=0
- documents_total=0
- done
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement