Friday, May 3, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 800  / 2 Years ago, sun, july 10, 2022, 12:12:36

  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?



More From » application-development

 Answers
6

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.


[#35102] Sunday, July 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ligdesig

Total Points: 164
Total Questions: 106
Total Answers: 114

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;