Author Topic: HOW-TO: Translating Bash Scripts  (Read 5760 times)

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2839
    • other projects...
HOW-TO: Translating Bash Scripts
« on: June 29, 2009, 03:59:00 PM »
For the translations to be picked up by your system up you need to specify the following two lines at the beginning of the script (here exemplified for the script getopenoffice, replace with your program name:
Code: [Select]
export TEXTDOMAIN=getopenoffice
export TEXTDOMAINDIR="/usr/share/locale"

In order to get the text message show up for translation in bash scripts you just need to add a $-sign in front of the text entries you have, for example:
Code: [Select]
zenity --info --text=$"You chose to exit. \nNo changes were applied to your system."
Once you have inserted the $-sign everywhere in the script you would build the pot-file like this (see also here) :
Code: [Select]
bash --dump-po-strings /usr/bin/update-notifier | xgettext -L PO -o ~/update-notifier.pot -
and then setup for example a French po-file using:
Code: [Select]
msginit -l fr -i ~/update-notifier.pot -o ~/fr.po
Translators can then use poedit to do the translation and build the fr.mo -file to be included in the next update-notifier-rpm.

hope this helps, best regards,
-p.

« Last Edit: January 21, 2010, 03:29:35 PM by pinoc »

Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Re: HOW-TO: Translating Bash Scripts
« Reply #1 on: January 21, 2010, 03:19:48 PM »
Thanks for the nice translations intro :-)

When I packaged apt-sources-update I had to include the variable TEXTDOMAIN in the bash script, otherwise the translations was not picked up.

The apt-sources-update could be a nice reference, also to see where translation files are supposed to be stored in the directory structure - this took me a while to figure out. Eventually take a look at the srpm for apt-sources-update,

cheers,
MBantz

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2839
    • other projects...
Re: HOW-TO: Translating Bash Scripts
« Reply #2 on: January 21, 2010, 03:25:46 PM »
Hi MBantz,
yes, you are correct and I should have added this in the original post (will do). For the translations to be picked up you need to specify the following two lines at the beginning of the script (here exemplified for the script getopenoffice, replace with your program name:
Code: [Select]
export TEXTDOMAIN=getopenoffice
export TEXTDOMAINDIR="/usr/share/locale"
regards,
-p.

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #3 on: January 22, 2010, 02:38:14 PM »
I translate this HOW-TO in german, see here...
Übersetzen von BASH-Scripte

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #4 on: August 08, 2010, 10:13:48 AM »
Hi pinoc,
to your HOW-TO i make some considerations...
Why i should open a terminal, when i can click on a bash script with right mouse click?

So i created a little script, that will generate the pot file, and *-de.po. But now i can need help...
How can i use the default locale of the system?

Here the script
Code: [Select]
#!/bin/bash
#
# Build for PCLinuxOS 2010
# By Leiche (kellerleicheorig at aol.com)
# Licence GPL
# Generate pot, and *-language.po files, to translate bash scripts
# Aug Sun 08 2010
#
Encoding=UTF-8
#
usage ()
{
echo "No File"
exit 1 #exit script
}
#
if [ $# -eq 0 ];
then
usage
fi
#
SCRIPT="$1"
#
SAVE=$(zenity --file-selection --title "Bash-Script-Translator-Generator" --save)
bash --dump-po-strings "$SCRIPT" | xgettext -L PO -o $SAVE.pot -
xterm -e "msginit -l de -i $SAVE.pot -o $SAVE-de.po"
exit

Thanks for efforts...

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2839
    • other projects...
Re: HOW-TO: Translating Bash Scripts
« Reply #5 on: August 08, 2010, 03:37:40 PM »
Hi Leiche,
you could get the current system language this way:
Code: [Select]
cat /etc/sysconfig/i18n |grep LC_CTYPE |cut -c 10-14on the default system you would then get "en_US" or in a German localized system "de_DE".
hope this helps,  ;)
-p.

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #6 on: August 09, 2010, 12:52:26 PM »
Hi pinoc,
add it, but i get now us_US as output.
Seamless it should de_DE, so what's wrong on my system?

Script
Code: [Select]
#!/bin/bash
#
# Build for PCLinuxOS 2010
# By Leiche (kellerleicheorig at aol.com)
# Licence GPL
# Generate pot, and *-language.po files, to translate bash scripts
# Aug Sun 08 2010
#
Encoding=UTF-8
#
usage ()
{
echo "No File"
exit 1 #exit script
}
#
if [ $# -eq 0 ];
then
usage
fi
#
SCRIPT="$1"
#
SAVE=$(zenity --file-selection --title "Bash-Script-Translator-Generator" --save)
LOCALE=$(cat /etc/sysconfig/i18n |grep LC_CTYPE |cut -c 10-14)
bash --dump-po-strings "$SCRIPT" | xgettext -L PO -o $SAVE.pot -
xterm -e "msginit -l $LOCALE -i $SAVE.pot -o $SAVE-$LOCALE.po"
exit

Thanks for efforts...

EDIT:
After i reinstall addlocale, and execute it, i get two results...

Code: [Select]
cat /etc/sysconfig/i18n |grep LC_CTYPE |cut -c 10-14
en_US
de_DE

Need a little more help, i think...
« Last Edit: August 09, 2010, 01:56:20 PM by Leiche »

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2839
    • other projects...
Re: HOW-TO: Translating Bash Scripts
« Reply #7 on: August 10, 2010, 02:59:05 AM »
Hi Leiche,
you should not have two entries, please open the file /etc/sysconfig/i18n and have a look at the LC_CTYPE line or choose something else if needed. This file defines the system locale.
regards,
-p.

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #8 on: August 10, 2010, 10:25:25 AM »
Hi pinoc,
thanks for your answer, see here my output from i18n

Code: [Select]
[leiche@leiche 1] ~ > cat /etc/sysconfig/i18n
LC_TELEPHONE=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LANGUAGE=en_US.UTF-8:en_US:en
LC_MONETARY=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
SYSFONT=lat0-16
LC_MEASUREMENT=en_US.UTF-8
LC_TIME=en_US.UTF-8
LANG=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_CTYPE=de_DE.UTF-8
LANGUAGE=de_DE.UTF-8:de:en_US:en
LC_MONETARY=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_COLLATE=de_DE.UTF-8
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_NUMERIC=de_DE.UTF-8
SYSFONT=lat0-16
GP_LANGUAGE=de
LC_MEASUREMENT=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LANG=de_DE.UTF-8
LC_ALL=
LC_IDENTIFICATION=de_DE.UTF-8
LC_MESSAGES=de_DE.UTF-8
GDM_LANG=de_DE.UTF-8

Must i change the locale for the root account, too?

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2839
    • other projects...
Re: HOW-TO: Translating Bash Scripts
« Reply #9 on: August 10, 2010, 10:44:59 AM »
if you get more entries for LC_CTYPE then the last one will override previous settings and will be valid for the system, to get it use:
Code: [Select]
cat /etc/sysconfig/i18n |grep LC_CTYPE |tail -1 |cut -c 10-14
regards,
-p.

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #10 on: August 10, 2010, 10:52:58 AM »
that's works, but will it work for other users, too?

Latest script...

Code: [Select]
#!/bin/bash
#
# Build for PCLinuxOS 2010
# By Leiche (kellerleicheorig at aol.com)
# Licence GPL
# Generate pot, and *-language.po files, to translate bash scripts
# Aug Sun 08 2010
#
Encoding=UTF-8
#
usage ()
{
echo "No File"
exit 1 #exit script
}
#
if [ $# -eq 0 ];
then
usage
fi
#
SCRIPT="$1"
#
SAVE=$(zenity --file-selection --title "Bash-Script-Translator-Generator" --save)
if [ "$SAVE" = "" ];then
exit
else
LOCALE=$(cat /etc/sysconfig/i18n |grep LC_CTYPE |tail -1 |cut -c 10-14)
bash --dump-po-strings "$SCRIPT" | xgettext -L PO -o $SAVE.pot -
xterm -e "msginit -l $LOCALE -i $SAVE.pot -o $SAVE-$LOCALE.po"
fi
exit

Thanks for efforts...
« Last Edit: August 10, 2010, 11:13:21 AM by Leiche »

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3729
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: HOW-TO: Translating Bash Scripts
« Reply #11 on: August 22, 2010, 09:03:20 AM »
Is anybody working with the script?
Would you like a package for it?
Or should it delete?
Thanks for efforts...

Offline rubentje1991

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2110
  • Rubenus Parvus MCMXCI
Re: HOW-TO: Translating Bash Scripts
« Reply #12 on: October 21, 2010, 05:47:18 AM »
In the past I translated manually some scripts (on an off-line computer, which I didn't kept up-to-date)
=> never submitted it to the Dutch section.....

If you think it's a handy-to-use package, it would be marvelous to have it in the repo's
=> maybe I can start to translate some in-house scripts (mylivecd etc.)

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: HOW-TO: Translating Bash Scripts
« Reply #13 on: October 21, 2010, 07:23:22 AM »
Is anybody working with the script?
Would you like a package for it?
Or should it delete?
Thanks for efforts...


I'm not sure how I missed this post back in August, but...

I think this would make a good addition to the pkgutils package; potential translators could download an srpm, right click to unpack, right-click to generate .po files, etc, do the translating, increment the mkrel / changelog, and repackage.  

To make it even more intuitive, perhaps we could modify the script to use zenity so that the translator could right click the spec, select translate, and the script would do the dirty work..   ..grep the spec Sources for .pot files, and maybe even search inside compressed source tars..  if found offer to create a .po file for the user's default locale (..or other locale),  use sed to update the spec file to include the newly created .po file as an additional source, and then increment the mkrel number.   Who knows, maybe we could even use zenity (..or gtkdialog) to allow them to create a translation for the spec / package descriptions and insert it into the spec with out the translator having to understand the packaging process..   when finished they could just right click, and "build all" or "build SRPM".

...just an idea..  ;)

« Last Edit: October 21, 2010, 07:35:04 AM by travisn000 »

Offline rubentje1991

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2110
  • Rubenus Parvus MCMXCI
Re: HOW-TO: Translating Bash Scripts
« Reply #14 on: October 22, 2010, 12:29:10 AM »
That would be very nice (it's now a little bit difficult to make a translation - and I think you don't need to be a packager to be a translator, so how more simple, how faster and more attractive to translate  ;D)

I hope some (or all  :D) of your ideas will be implemented....