Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
  1. What should an application developed under a Linux System like Ubuntu do so as to automatically detect the system language? There are applications, like Liferea that automatically change their language to match the system's, without altering any preference of the program itself: enter image description here Should this be the "default" behavior for all the programs?

  2. Should there be an option on the program so as to let the user choose the language nonetheless?

  3. Are all these translations coming along with the program itself? What if the user has set a system language not available in the translations of the program?

  4. Is this Ubuntu or most-linux-distros specific?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

I know that application development with Quickly and Launchpad support Translations to do this. I'm no expert so check out these links in addition to my answer:

http://www.gnu.org/software/gettext/

https://help.launchpad.net/Translations

My application imports the gettext module which then allows me to mark strings that will be displayed to the user in the program. When my program is submitted to Launchpad via Quickly, Launchpad is set up to automatically scan through the source code and generate special translation template files for the marked strings. Kind Launchpad users (or the developer), can then use the template to generate translations for each string and language they'd like. These translation files can then be sync'd to your source branch and merged before release. On runtime the gettext module then replaces marked strings with the appropriate translation based on your system locale.

To summarize, here's a list of the process:

  • import gettext into your program
  • Mark strings that need to be translated
  • Setup translations in Launchpad
  • Translate templates and sync to source

Here's the header of my program where I import gettext through locale (note that Quickly adds all this for me! locale and bindtextdomain are added because it's being put in /opt/extras.ubuntu.com I think):

import locale
from locale import gettext as _
locale.bindtextdomain('drawers', '/opt/extras.ubuntu.com/drawers/share/locale')
locale.textdomain('drawers')

Now I just mark text to be translated with _("text to be translated") throughout my program.

share|improve this answer
add comment

In the future, even if they are related, I'd suggest opening separate questions for each. In any case, I'll have a go at answering them:

What should an application developed under a Linux System like Ubuntu do so as to automatically detect the system language?

You simply need to initialize gettext in your app. Gettext is the standard internationalization and localization technology Ubuntu and the big majority of other other Linux-based distros use (if we consider Android a distro,then it'd be the only exception).

In the most basic case, and using Python

import gettext
from gettext import gettext as _
locale.bindtextdomain('yourapp', '/usr/share/locale')
locale.textdomain('yourapp')

Notes:

  • In Python, in order to support /opt installation you'll need to use the locale library instead of gettext (for most practical purposes they're equivalent)
  • There are gettext bindings for almost any programming language, not only Python.

Should this be the "default" behavior for all the programs?

Yes.

Should there be an option on the program so as to let the user choose the language nonetheless?

No. If you want to have such an option, you're on your own and will have to implement it yourself. The convention is that there is only one per-user language and you change that only in one place, affecting all apps in the system.

Are all these translations coming along with the program itself?

Yes, they are shipped along with the app as binary .mo files, one for each language translated.

What if the user has set a system language not available in the translations of the program?

Then the default for gettext is to use English as a fallback.

Is this Ubuntu or most-linux-distros specific?

This is the standard behaviour for Linux distros.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.