Luca's meaningless thoughts   SponsorGitHub SponsorsLiberapayPaypalBuy Me A CoffeePatreonFlattr

Translation of e-mails using Mutt

by Leandro Lucarella on 2012- 09- 24 12:45 (updated on 2012- 10- 02 12:58)
tagged e-mail, en, floss, gmail, google translate, mutt, python, release, script, software, translate - with 0 comment(s)

Update

New translation script here, see the bottom of the post for a description of the changes.

I don't like to trust my important data to big companies like Google. That's why even when I have a GMail, I don't use it as my main account. I'm also a little old fashion for some things, and I like to use Mutt to check my e-mail.

But GMail have a very useful feature, at least it became very useful since I moved to a country which language I don't understand very well yet, that's not available in Mutt: translation.

But that's the good thing about free software and console programs, they are usually easy to hack to get whatever you're missing, so that's what I did.

The immediate solution in my mind was: download some program that uses Google Translate to translate stuff, and pipe messages through it using a macro. Simple, right? No. At least I couldn't find any script to do the translation, because Google Translate API is now paid.

So I tried to look for alternatives, first for some translation program that worked locally, but at least in Ubuntu's repositories I couldn't find anything. Then for online services alternatives, but nothing particularly useful either. So I finally found a guy that, doing some Firebuging, found how to use the free Google translate service. Using that example, I put together a 100 SLOC nice general Python script that you can use to translate stuff, piping them through it. Here is a trivial demonstration of the script (gt, short for Google Translate... Brilliant!):

$ echo hola mundo | gt
hello world
$ echo hallo Welt | gt --to fr
Bonjour tout le monde

And here is the output of gt --help to get a better impression on the script's capabilities:

usage: gt [-h] [--from LANG] [--to LANG] [--input-file FILE]
          [--output-file FILE] [--input-encoding ENC] [--output-encoding ENC]

Translate text using Google Translate.

optional arguments:
  -h, --help            show this help message and exit
  --from LANG, -f LANG  Translate from LANG language (e.g. en, de, es,
                        default: auto)
  --to LANG, -t LANG    Translate to LANG language (e.g. en, de, es, default:
                        en)
  --input-file FILE, -i FILE
                        Get text to translate from FILE instead of stdin
  --output-file FILE, -o FILE
                        Output translated text to FILE instead of stdout
  --input-encoding ENC, -I ENC
                        Use ENC caracter encoding to read the input (default:
                        get from locale)
  --output-encoding ENC, -O ENC
                        Use ENC caracter encoding to write the output
                        (default: get from locale)

You can download the script here, but be warned, I only tested it with Python 3.2. It's almost certain that it won't work with Python < 3.0, and there is a chance it won't work with Python 3.1 either. Please report success or failure, and patches to make it work with older Python versions are always welcome.

Ideally you shouldn't abuse Google's service through this script, if you need to translate massive texts every 50ms just pay for the service. For me it doesn't make any sense to do so, because I'm not using the service differently, when I didn't have the script I just copy&pasted the text to translate to the web. Another drawback of using the script is I couldn't find any way to make it work using HTTPS, so you shouldn't translate sensitive data (you shouldn't do so using the web either, because AFAIK it travels as plain text too).

Anyway, the final step was just to connect Mutt with the script. The solution I found is not ideal, but works most of the time. Just add these macros to your muttrc:

macro index,pager <Esc>t "v/plain\n|gt|less\n" "Translate the first plain text part to English"
macro attach <Esc>t "|gt|less\n" "Translate to English"

Now using Esc t in the index or pager view, you'll see the first plain text part of the message translated from an auto-detected language to English in the default encoding. In the attachments view, Esc t will pipe the current part instead. One thing I don't know how to do (or if it's even possible) is to get the encoding of the part being piped to let gt know. For now I have to make the pipe manually for parts that are not in UTF-8 to call gt with the right encoding options. The results are piped through less for convenience. Of course you can write your own macros to translate to another language other than English or use a different default encoding. For example, to translate to Spanish using ISO-8859-1 encoding, just replace the macro with this one:

macro index,pager <Esc>t "v/plain\n|gt -tes -Iiso-8859-1|less\n" "Translate the first plain text part to Spanish"

Well, that's it! I hope is as useful to you as is being to me ;-)

Update

Since picking the right encoding for the e-mail started to be a real PITA, I decided to improve the script to auto-detect the encoding, or to be more specific, to try several popular encodings.

So, here is the help message for the new version of the script:

usage: gt [-h] [--from LANG] [--to LANG] [--input-file FILE]
          [--output-file FILE] [--input-encoding ENC] [--output-encoding ENC]

Translate text using Google Translate.

optional arguments:
  -h, --help            show this help message and exit
  --from LANG, -f LANG  Translate from LANG language (e.g. en, de, es,
                        default: auto)
  --to LANG, -t LANG    Translate to LANG language (e.g. en, de, es, default:
                        en)
  --input-file FILE, -i FILE
                        Get text to translate from FILE instead of stdin
  --output-file FILE, -o FILE
                        Output translated text to FILE instead of stdout
  --input-encoding ENC, -I ENC
                        Use ENC caracter encoding to read the input, can be a
                        comma separated list of encodings to try, LOCALE being
                        a special value for the user's locale-specified
                        preferred encoding (default: LOCALE,utf-8,iso-8859-15)
  --output-encoding ENC, -O ENC
                        Use ENC caracter encoding to write the output
                        (default: LOCALE)

So now by default your locale's encoding, utf-8 and iso-8859-15 are tried by default (in that order). These are the defaults that makes more sense to me, you can change the default for the ones that makes sense to you by changing the script or by using -I option in your macro definition, for example:

macro index,pager <Esc>t "v/plain\n|gt -IMS-GREEK,IBM-1148,UTF-16BE|less\n"

Weird choice of defaults indeed :P

Release: Status Area Display Blanking Applet 1.0 for Maemo

by Leandro Lucarella on 2012- 08- 05 12:54 (updated on 2012- 08- 05 12:54)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

Finally 1.0 is here, and in Extras-devel! The only important change since last release is a bug fix that prevented display blanking inhibition from properly work in devices configured with a display blanking timeout of less than 30 seconds (thanks cobalt1 for the bug report).

For more information and screenshots, you can visit the website.

You can download this release (binary package and sources) from here:

But now you just might want to simply install it using the application manager.

You can also get the source from the git repository:

https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.9 (beta) for Maemo

by Leandro Lucarella on 2012- 07- 30 22:35 (updated on 2012- 07- 30 22:35)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

Final beta release for the Status Area Display Blanking Applet. Changes since last release:

  • Show a status icon when display blanking is inhibited.
  • Improve package description and add icon for the Application Manager.
  • Add a extended description for display blanking modes.
  • Update translation files.
  • Code cleanup.

Also now the applet have a small home page and upload to Extras is on the way!

This is how this new version looks like:

/proj/sadba/files/0.9/screenshot-1.mini.png /proj/sadba/files/0.9/screenshot-2.mini.png /proj/sadba/files/0.9/screenshot-3.mini.png /proj/sadba/files/0.9/screenshot-4.mini.png /proj/sadba/files/0.9/screenshot-5.mini.png

You can download this 0.9 beta release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.9/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.5 for Maemo

by Leandro Lucarella on 2012- 07- 29 18:55 (updated on 2012- 07- 29 18:55)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

New pre-release for the Status Area Display Blanking Applet. New timed inhibition button that inhibit display blanking for an user-defined amount of time. Also there's been some code cleanup since last release.

/proj/sadba/files/0.5/screenshot-1.mini.png /proj/sadba/files/0.5/screenshot-2.mini.png /proj/sadba/files/0.5/screenshot-3.mini.png /proj/sadba/files/0.5/screenshot-4.mini.png

You can download this 0.5 pre-release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.5/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.4 for Maemo

by Leandro Lucarella on 2012- 07- 27 18:12 (updated on 2012- 07- 27 18:12)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

New pre-release of my first Maemo application: The Status Area Display Blanking Applet. Now you inhibit display blanking without changing the display blanking mode. The GUI is a little rough compared with the previous version but it works. :)

/proj/sadba/files/0.4/screenshot-1.mini.png /proj/sadba/files/0.4/screenshot-2.mini.png

You can download this 0.4 pre-release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.4/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.3 for Maemo

by Leandro Lucarella on 2012- 07- 26 10:51 (updated on 2012- 07- 27 18:13)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

New pre-release of my first Maemo application: The Status Area Display Blanking Applet. Now you can pick whatever blanking mode you want instead of blindly cycling through all available modes, as it was in the previous version.

/proj/sadba/files/0.3/screenshot-1.mini.jpg /proj/sadba/files/0.3/screenshot-2.mini.png

You can download this 0.3 pre-release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.3/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.2 for Maemo

by Leandro Lucarella on 2012- 07- 23 09:56 (updated on 2012- 07- 23 09:56)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

Second pre-release of my first Maemo application: The Status Area Display Blanking Applet. No big changes since the last release just code cleanup and a bugfix or new features (depends on how you see it). Now the applet monitors changes on the current configuration, so if you change the display blanking mode from settings (or by any other means), it will be updated in the applet too.

You can download this 0.2 pre-release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.2/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Please feel free to leave your comments and suggestions here or in the Maemo Talk Thread..

Release: Status Area Display Blanking Applet 0.1 for Maemo

by Leandro Lucarella on 2012- 07- 15 20:09 (updated on 2012- 07- 15 20:09)
tagged en, floss, maemo, n900, release, sadba, software, status area display blanking applet - with 0 comment(s)

Hi, I just wanted to announce the pre-release of my first Maemo "application". The Status Area Display Blanking Applet let you easily change the display blanking mode right from the status menu, without having to go through the settings.

This is specially useful if you have a short blanking time when you use applications that you want to look at for a long time without interacting with the phone and don't inhibit display blanking by themselves (for example a web browser, image viewer or some GPS applications).

You can download this 0.1 pre-release (binary package and sources) from here: https://llucax.com.nyud.net/proj/sadba/files/0.1/

You can also get the source from the git repository: https://git.llucax.com/w/software/sadba.git

Here are some screenshots (the application is highlighted so you can spot it more easily :) ):

/proj/sadba/files/0.1/screenshot-1.mini.jpg /proj/sadba/files/0.1/screenshot-2.mini.jpg

Please feel free to leave your comments and suggestions.

I'll upload the package to extras-devel when I have some time to learn the procedure.

Subtítulos para todos (y todas)

by Leandro Lucarella on 2012- 07- 14 18:37 (updated on 2012- 07- 14 18:37)
tagged es, floss, release, software, subdivx, subdivxget, subtitle, subtítulos - with 0 comment(s)

¡Viva Perón, carajo!

Podrido de buscar subtítulos a mano en subdivx.com, que es una paja enorme por la interfaz bastaaante pedorra, decidí, hace mucho tiempo, hacer un pequeño script para hacer el trabajo sucio por mí. Como muchas veces pasa, esa mugre fue creciendo hasta convertirse en algo relativamente decente, así que decidí publicarlo.

Si bien no estoy tan orgulloso de él como para hacer un release serio, subí el código a un repo git que pueden bajar, mejorar y mandar parches.

También pueden bajar el script directamente y usarlo (chmod +x de por medio). Está probado con Python 2.7 y 3.2.

Acá un screenshot del usage, que es la única documentación que existe sobre el script:

Usage: subdivxget [OPTIONS] QUERY [FILTER ...]

Download subtitles from subdivx.com searching the string QUERY. If FILTERs
are specified, only subtitles that matches all those filters are downloaded.
Filters have the format "X:fitler", where X is a field specification:
t=titulo, d=desc, a=autor, f=formato, c=comentarios, C=cds, F=fecha and
D=downloads. filter is a string that should be found on that field (case
insensitive). If the format specifier is not known (or there isn't one) the
filter string is looked in all the fields.

Options:
  -h, --help       show this help message and exit
  -l, --list-only  Don't download the subtitles, just list them
  -q, --quiet      Don't print progress messages

Ah, sí, me quedó mezcla de inglés y castellano, es que estoy acostumbrado a codear en inglés, pero dado que subdivx AFAIK sólo tiene subtítulos en castellano se complica.

Espero que a alguien le sea útil.

Release: Mutt with NNTP Debian package 1.5.21-5nntp3

by Leandro Lucarella on 2012- 07- 05 19:59 (updated on 2012- 07- 05 19:59)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 0 comment(s)

This is just a quick fix for yesterday's release. Now mutt-nntp depends on mutt >= 1.5.21-5. This should allow having mutt-nntp installed with the standard distribution mutt package for both Debian and Ubuntu (please report any problems).

If you have Ubuntu 12.04 (Precise) and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.21
deb_ver=$ver-5nntp3
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt-nntp_${deb_ver}_*.deb

Now you can enjoy reading your favourite newsgroups and your favourite mailing lists via Gmane with Mutt without leaving the beauty of your packaging system. No need to thank me, I'm glad to be helpful (but if you want to make a donation, just let me know ;).

Note

You should always install the same mutt version as the one the mutt-nntp is based on (i.e. the version number without the nntpX suffix, for example if mutt-nntp version is 1.5.21-5nntp1, your mutt version should be 1.5.21-5 or 1.5.21-5ubuntu2). A newer version will satisfy the dependency too but it is not guaranteed to work (even when it probably will, specially if the upstream version is the same). You could also install the generated/provided mutt package, but that might be problematic when upgrading your distribution.

See the project page for more details.

Release: Mutt with NNTP Debian package 1.5.21-5nntp2

by Leandro Lucarella on 2012- 07- 04 17:24 (updated on 2012- 07- 04 17:24)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 0 comment(s)

A new version of Mutt with NNTP support is available. This version only moves Mutt with NNTP support to a separate package in the hopes of having a smoother interaction with the distribution packages (avoiding automatic updates with less hassle). Now a new mutt-nntp package is generated.

If you have Ubuntu 12.04 (Precise) and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.21
deb_ver=$ver-5nntp2
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt-nntp_${deb_ver}_*.deb

Now you can enjoy reading your favourite newsgroups and your favourite mailing lists via Gmane with Mutt without leaving the beauty of your packaging system. No need to thank me, I'm glad to be helpful (but if you want to make a donation, just let me know ;).

Note

You should always install the same mutt version as the one the mutt-nntp is based on (i.e. the version number without the nntpX suffix, for example if mutt-nntp version is 1.5.21-5nntp1, your mutt version should be 1.5.21-5). I'm not forcing that in the dependencies because in general it shouldn't be a big issue using an older version. You could also install the generated/provided mutt package, but that might be problematic when upgrading your distribution.

See the project page for more details.

Release: Mutt with NNTP Debian package 1.5.21-5nntp1

by Leandro Lucarella on 2011- 05- 24 19:59 (updated on 2011- 05- 24 19:59)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 0 comment(s)

I've updated my Mutt Debian package with the NNTP patch to the latest Debian Mutt package.

This release is to bring just the regular bugfixing round from Debian.

If you have Debian testing/unstable and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.21
deb_ver=$ver-5nntp1
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt_${deb_ver}_*.deb mutt-patched_${deb_ver}_*.deb

See the project page for more details.

Release: Mutt with NNTP Debian package 1.5.21-4nntp1

by Leandro Lucarella on 2011- 04- 13 00:20 (updated on 2011- 04- 13 00:20)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 0 comment(s)

I've updated my Mutt Debian package with the NNTP patch to the latest Debian Mutt package.

If you have downloaded the previous version, you probably noted an extremely annoying bug, which is fixed in this new package, so I'm sure you want to upgrade =)

If you have Debian testing/unstable and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.21
deb_ver=$ver-4nntp1
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt_${deb_ver}_*.deb mutt-patched_${deb_ver}_*.deb

See the project page for more details.

Release: Mutt with NNTP Debian package 1.5.21-2nntp1

by Leandro Lucarella on 2011- 01- 19 17:19 (updated on 2011- 01- 19 17:19)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 0 comment(s)

I've updated my Mutt Debian package with the NNTP patch to the latest Debian Mutt package.

A couple of extra news:

  • I added a new Git repository so you can download the sources via Git.
  • The Debian revision is renamed to NnntpM (instead of the old NlucaM).

If you have Debian testing/unstable and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.21
deb_ver=$ver-2nntp1
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt_${deb_ver}_*.deb mutt-patched_${deb_ver}_*.deb

See the project page for more details.

Bacap

by Leandro Lucarella on 2010- 07- 02 01:02 (updated on 2010- 07- 02 01:02)
tagged bacap, backup, en, floss, release, rsync, software - with 0 comment(s)

I've published my backup script (and named it Bacap, which is how it sounds when you pronounce "backup" in Spanish ;), as it suddenly became used by somebody else and received some patches =)

It has a simple home page for those wanting to see what is it about. I won't be doing formal releases thought, since is such a simple script, that would be overkill (just be thankful it has a git repo and a home page ;).

Release: Mutt with NNTP Debian package 1.5.20-8luca1

by Leandro Lucarella on 2010- 06- 07 02:12 (updated on 2010- 06- 07 02:12)
tagged debian, en, mutt, nntp, package, patch, release, ubuntu, vsevolod volkov - with 2 comment(s)

I've updated my Mutt Debian package with the NNTP patch to the latest Debian Mutt package.

If you have Debian testing/unstable and amd64 or i386 arch, just download and install the provided packages.

For other setups, here are the quick (copy&paste) instructions:

ver=1.5.20
deb_ver=$ver-8luca1
url=https://llucax.com.nyud.net/proj/mutt-nntp-debian/files/latest
wget $url/mutt_$deb_ver.dsc $url/mutt_$deb_ver.diff.gz \
   http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_$ver.orig.tar.gz
sudo apt-get build-dep mutt
dpkg-source -x mutt_$deb_ver.dsc
cd mutt-$ver
dpkg-buildpackage -rfakeroot
# install any missing packages reported by dpkg-buildpackage and try again
cd ..
sudo dpkg -i mutt_${deb_ver}_*.deb mutt-patched_${deb_ver}_*.deb

See the project page for more details.

LLVM 2.6

by Leandro Lucarella on 2009- 10- 24 21:30 (updated on 2009- 10- 24 21:30)
tagged d, en, llvm, release, software - with 0 comment(s)

Just in case you're not that well informed, Chris Lattner has just announced the release of LLVM 2.6. Enjoy!