Substitution of chain in a gtkdialog menu [SOLVED]

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
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Substitution of chain in a gtkdialog menu [SOLVED]

#1 Post by Argolance »

Hello,

Code: Select all

Name=Application English name
Name[fr]=Nom français de l'application
Name[de]=...
Name[es]=...
... The script below fetches the value of the variable LANGUE in the configuration file above.
English being the language by default, [en] is not specified but only "Name=" and that's where the shoe pinches...
#! /bin/sh

export test_GUI="<window>
<menubar>
<menu label=\"TEST\">
<menuitem label=\"$(grep '^Name\['$LANGUE\]' /path/config_file | cut -d'=' -f2) ${label="$(grep '^Name=' /path/config_file | cut -d'=' -f2)"}\">
</menuitem>
</menu>
</menubar>
</window>"

gtkdialog --program=test_GUI --center
The label of the menu is displayed in English if the value does not exist in the configuration file or simply because the current language of the user is English.
But on the other hand, both labels (current language and English) are displayed simultaneously when the value exists!
I just want the current language label to be displayed.
How could I solve this?
Hard to explain in English...

Thank you for your attention!
Cordialement.
Last edited by Argolance on Mon 30 Jul 2012, 14:48, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

i am not a fan of these massive code constructs inside gtkdialog .

I would assign the grep 'ed values before launching gtkdialog

like

Code: Select all

label_native=$(grep '^Name\[$LANGUE\]' /path/config_file | cut -d'=' -f2) 
label_default="$(grep '^Name=' /path/config_file | cut -d'=' -f2)"
label_use="$label_default"
if [ "$label_native" ];then
label_use="$label_native"
fi
[ "$label_use" ] || { echo "$0:$LINENO::ERROR, label_use declared but not filled.";exit 100; }
export MAIN_DIALOG="
<window>
<text><label>$label_use</label></text>
</window>
"
gtkdialog3 -p MAIN_DIALOG
I tried to source config.file first to use arrays,
but that must a) eval 'uated and b) needs "Name of Pro'gram" quoted .

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post by Argolance »

Hello,
Thank you for replying.
i am not a fan of these massive code constructs inside gtkdialog
...Yes, as we sometimes say in French, speaking of "heavy" red wine: this is a big one that stains!
As I got a lot of entries inside my menus, I am trying to find another "lighter" solution: directly build correct config files for example should probably be the best!

Cordialement.

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

#4 Post by L18L »

Argolance wrote:...As I got a lot of entries inside my menus, I am trying to find another "lighter" solution: directly build correct config files for example should probably be the best!
Something like

s%"Application English name" %"Nom allemand de l'application"%
s%"bla English" %"bla allemand"%

is implemented in /usr/share/sss/menu_strings/menu_strings.de

I have used it for configuration of jwm menu in langpack_de.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#5 Post by Argolance »

Hello,
Thank you!
I finally chose to "operate" not in "downstream" but in "upstream", simply building adapted configuration files, and now all is working fine.
Very interesting to learn that fixmenus reads raw English template files and generates final target files, then translates them in-place.

Code: Select all

s%"Help"%"Hilfe"%
...
This looks like a simple sed command...

Cordialement.

Post Reply