Why use gettext?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Why use gettext?

#1 Post by MochiMoppel »

In puppy scripts I often see statements like

Code: Select all

MSG="$(gettext 'Please wait')"
I would be tempted to simply use

Code: Select all

MSG="Please wait"
I'm sure I'm missing something, but what? Gettext seems to be a very powerful tool for multilanguage text processing, but without any further arguments like in most puppy scripts, does it more than a simple string assignment?

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#2 Post by technosaurus »

It is an external program used to get localized translations of a string.
For ex. if LANG=es, it would return "Hola Mundo" (or something like that for "Hello World")

BTW, There is an alternative method for translation in shell scripts:
http://extra-inter.net/puppy/t12s_DOC/t12s.html
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#3 Post by MochiMoppel »

Thanks for the feedback and the link. I've now tried a language pack and seen gettext in action. I roughly know what is going on.

Still I'm not sure if I should use it. I try to learn from the hundreds of scripts in Puppy. They all apply a more or less consistent programming style and are a fantastic source to explore the possibilities of bash, so I treat them with respect. But sometimes I dare to make changes, and here comes my concern: When I make changes to an existing script that uses all these gettext functions, what is "best practise"? Should I

a) also use gettext, though I don't provide translations? Would this make life easier for someone to add translations later?

b) use simple string assignments as an honest statement that there are no translations available?

c) search (how?) to see, if my text "Please wait" has been translated? If it has, then use gettext, if it hasn't, use the simple way.

Of course all this is irrelevant if I make changes for my own pleasure, but if I ever publish code in the forum, I want it to conform to whatever standards are established.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#4 Post by L18L »

MochiMoppel wrote:...When I make changes to an existing script that uses all these gettext functions, what is "best practise"? Should I

a) also use gettext, though I don't provide translations? Would this make life easier for someone to add translations later
Yes of course.
It is the translator who will provide a translation.

Note; a translations is not added to the script but maybe just added to the *-NLS.pet or the language pack..

Post Reply