From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!3s634R+rSk3f11Qz2WJrTw.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Glade but more flexible Date: Sun, 30 Jan 2022 14:59:22 +0100 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="13854"; posting-host="3s634R+rSk3f11Qz2WJrTw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63425 List-Id: On 2022-01-30 14:20, ldries46 wrote: > I like the way Glade can be used for designing a gtk GUI. But There is a > problem I cannot do what I like to do. The best way to illustrate that > is when I want to design a multi language program. I than need the > string variables in some kind of array. For instance Language_Open(lan) > instead of Language_Open where: > Language_Open(English) := To_Unbounded_String("Open"); > Language_Open(Deutsch) := To_Unbounded_String("Offnen"); > etc, > where lan := (English, Deutsch, ...); > > This can be reached if Glade can also produce an Ada program output > where you can edit output simply or when a program Glade2Ada would be > created which translates the Glade Output to Ada, where you can edit the > Ada program accordingly. > The latest version can also be transfered to other language, so Glade2C, > Glade2python etc. > > The question is is something like that available or is it an idea to > create such a thing for the people who created Glad [ Necessary litany: never ever use Glade ] Regarding localization I am using widget style properties for the purpose: 1. All application widgets are derived, usually from grid or dialog etc. 2. All widgets define a new class: Initialize_Class_Record 3. All texts (and other parameters) of a widget are style properties from the class: Install_Style_Property ( Class_Ref (... the widget's type ...), Gnew_String ( Name => "hello-label", Nick => "hello", Blurb => "The label 'hello'", Default => "Hello" ) ); 4. Provide Style_Updated to handle style-updated: procedure Style_Updated ( Widget : access My_Custom_Widget ) is begin Widget.Hello_Label.Set_Text ( Style_Get (Widget, "hello-label") ); ... From there you set all texts of the widget and all other properties. E.g. the label text is set from the value of the "hello-label". 5. Connect to Style_Updated Connect ( Widget, "style-updated", To_Marshaller (Style_Updated'Access) ); 6. Call to Style_Updated at the end of Initialize (called from Gtk_New) 7. Upon application start load a CSS file from some predefined location, e.g. from user directory: Load_CSS_File This is basically all. If you want to change a text, e.g. from English to German, you simply edit the CSS file. MyCustomWidget { -MyCustomWidget-hello-label: "Hallo"; You can reload CSS any time, the widgets will get the "style-updated" event and Style_Updated will change the texts. No texts in the application code, except for the English default fallback, of course. BTW, in GTK it is possible to walk down the widget tree and generate a CSS template with all style properties of. I add this to command-line arguments. So adding a new language you will not miss a text (a poor man's safety you would get in Ada for free if an enumeration type were used for the texts). The GTK CSS overview is here: https://docs.gtk.org/gtk3/css-overview.html -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de