jueves, 1 de agosto de 2013

Sobre gettext y traducciones en Puppy-es PARTE 2

Bien ya aprendimos a agregar esas líneas que nos permitiran que el script pueda ser traducido en varios idiomas aquí lo vemos ya completo nuevamente.

==================================================


#!/bin/bash
#Written by PANZERKOPF
#100215 hacked by BK
#101207 hacked by EW
#121019 BK: fixed. internationalized.
#121022 L18L: complete the internationalization.

#101207 EW:
# this is a Xdialog frontend for the xgamma program - setting colour calibration for the screen
# It is using the 3 RGB channels 
# xgamma uses a logharithmic scale for the gamma values (0.1 - darkest, 1.0 - default, 10.0 - brightest) -> Y Values
# The GUI uses a linear scale (going from -100 - darkest, 0.0 - default, +100 - brightest) -> X Values
# The transformation is given by Y=10^(X/100)
# the calculation has to be performed with bc, 
# to use decimal values in the exponent the equation must be rewritten Y = exp ( X/100 * log (10))
# or, setting the precision to 3 decimal points using bc command: Y=$(echo "e( "$X"/100 * l(10))" | bc -l)
# The reverse transformation is XRED=$(echo "scale:0; 100 * l($YRED) / l(10)" | bc -l)

export TEXTDOMAIN=xgamma-gui
export OUTPUT_CHARSET=UTF-8

TITLE="$(gettext 'Monitor Gamma calibration')"
BACKTITLE="$(gettext 'Set value for each colour, or adjust equally if only want to adjust brightness of screen.
The spinboxes are adjustable in the range -100 to +100, where -100 is darkest, 0 is default, and +100 is brightest.')'"

if [ "`which xgamma`" = "" ]; then
 Xdialog --title "${TITLE}" --msgbox "$(gettext 'xgamma not found.')'" 0 0
 exit
fi

#get current settings (for startup)
YGAMMA="$(xgamma 2>&1 | tr -s ' ' | sed -e 's%[^0-9. ]%%g' | tr -s ' ')" #ex:  10.000  1.000  1.000

YRED="$(echo "$YGAMMA" | cut -f 2 -d ' ')"
YGREEN="$(echo "$YGAMMA" | cut -f 3 -d ' ')"
YBLUE="$(echo "$YGAMMA" | cut -f 4 -d ' ')"
inYRED="$YRED"
inYGREEN="$YGREEN"
inYBLUE="$YBLUE"

echo $YGAMMA 
echo $YRED $YGREEN $YBLUE

#transform y-->x values, 3 decimals precision, to get the current values;
XRED=$(echo "scale=3; 100 * l("$YRED") / l(10)" | bc -l)
XRED=$(echo "scale=0; "$XRED"/1" | bc -l) # cut decimals
XGREEN=$(echo "scale=3; 100 * l("$YGREEN") / l(10)" | bc -l)
XGREEN=$(echo "scale=0; "$XGREEN"/1" | bc -l) # cut decimals
XBLUE=$(echo "scale=3; 100 * l("$YBLUE") / l(10)" | bc -l)
XBLUE=$(echo "scale=0; "$XBLUE"/1" | bc -l) # cut decimals

EXCODE="0"
REDLABEL="$(gettext 'Red')'"
GREENLABEL="$(gettext 'Green')'"
BLUELABEL="$(gettext 'Blue')'"

APPLIEDFLAG='no'
while [ "${EXCODE}" = "0" ]; do

 XDGOUT=`Xdialog  --wrap --left --backtitle "${BACKTITLE}" --title "${TITLE}" --stdout --buttons-style "text" --icon "/usr/share/images/xgamma-gui.xpm" --ok-label "$(gettext 'Apply')" --cancel-label "$(gettext 'Exit')" \
--3spinsbox "" 356x0 "-100" "100" "$XRED" "${REDLABEL}" "-100" "100" "$XGREEN" "${GREENLABEL}" "-100" "100" "$XBLUE" "${BLUELABEL}"`

 # get exit code
 EXCODE=${?}

 XGAMMA=$XDGOUT
 # substitute >space< for >/<, otherways there are problems to parse the string properly
 XGAMMA=$(echo $XGAMMA| sed 's:/: :g')

 [ "${EXCODE}" != "0" ] && break

 APPLIEDFLAG='yes'
  
 # cut in pieces (parse) and assign
 set -- ${XGAMMA// / }
 XRED=$1
 XGREEN=$2
 XBLUE=$3

 # make transformation x-->y 
 YRED=$(echo "scale=3; e( "$XRED"/100 * l(10))" | bc -l)
 YGREEN=$(echo "scale=3; e( "$XGREEN"/100 * l(10))" | bc -l)
 YBLUE=$(echo "scale=3; e( "$XBLUE"/100 * l(10))" | bc -l)

 #apply gamma values 
 xgamma -rgamma ${YRED} -ggamma ${YGREEN} -bgamma ${YBLUE}

done

# if default values we dont need xgamma at startup, so remove the file. This saves time in .xinitrc
if [ "$XGAMMA" = "0 0 0" ]; then
rm -f $HOME/.xgamma-gamma
exit
fi
if [ "$inYRED" = "$YRED" ];then
 if [ "$inYGREEN" = "$YGREEN" ];then
  if [ "$inYBLUE" = "$YBLUE" ];then
   exit
  fi
 fi
fi
[ "$APPLIEDFLAG" = "no" ] && exit

# else ask if we want to save the current values and create a startup calibration file
Xdialog --yesno "$(gettext 'Save current configuration?')'" 0 0
if [ ${?} -eq 0 ]; then
  echo -n "xgamma -rgamma $YRED -ggamma $YGREEN -bgamma $YBLUE"' &' > $HOME/.xgamma-gamma
  #...xgamma is executed in /root/.xinitrc
  echo "Saved"  
fi

###END###

===========================================================


HERRAMIENTAS DE TRADUCCION

Y aqui esta nuestro script alojado en la ruta /usr/sbin

ahora bien que necesitamos para traducirlo pues las versiones recientes de Puppylinux traen una herramienta de traduccion que se llama momanager

Momanger es una interface gráfica escrita por Barry Kauler padre de Puppylinux y es muy facil de usar por cualquier usuario que quiera crear traducciones de aplicaciones en un idioma distinto del ingles en Puppy.

Podes encontrar la aplicacion en el menu--herrmientas o menu--utilities

Para que Momanager funcione es necesario tener instalados los devx.

Los devx son un conjunto de herramientas para compilar con soporte para C, C++, Vala entre otros. 

Poedit (antes poEdit) es un editor libre, abierto y multiplataforma de catálogos de Gettext usado en el proceso de localización.
Está construido con wxWidgets y licenciado bajo los términos de la licencia MIT.
Para usar poedit necesitas descargar la aplicacion

OK ya tenemos dos alternativas de traduccion Momanager y Poedit pero antes un poco mas de teoria.
Archivos .pot .po .mo
Gettext utiliza diferentes tipos de ficheros:
  • Pot – Los archivos .pot son plantillas donde estarán todas las cadenas de texto traducibles extraídas desde un fichero de código fuente. Donde habrá un identificador (msgid) y un texto (msgstr) vacío.
  • Po – Un archivo de PO se compone de muchas entradas, manteniendo la relación entre una cadena no traducida original y su traducción correspondiente. Todas las entradas en un archivo PO generalmente pertenecen a un solo proyecto, y todas las traducciones se expresan en un único idioma de destino.
  • Mo – Finalmente los ficheros Po son compilados para generar un archivo binario, llamado o con extensión .mo, que permite una lectura más rápida de los textos. Ahora ya se puede distribuir nuestro fichero, según la configuración de idioma del programa, este seleccionará de forma adecuada el fichero .mo (si existe).
Bien ordenemos nuevamente las ideas:
- Tenemos el script 
- guardamos un respaldo del script original por seguridad
- colocamos nuestra reseña de que vamos a editarlo
- agregamos gettext 
- lo colocamos en su respectiva ruta /usr/sbin por ejemplo
- instalamos los devx en nuestro sistema
- instalamos el pet de poedit por si deseamos utilizarlo en el futuro.

Ahora ya estamos listos para correr Momanager y luego de llenar algun registro, la interface hara un escaneo general del todo nuestro sistema ordenando todos los archivos eso incluye scripts, binarios, archivos .desktop, archivos xml, etc. 

Continuaremos explicándolo en la 3 parte de este tutorial.

Fuentes


http://www.poedit.net/

No hay comentarios:

Publicar un comentario