* GtkAda and € @ 2021-09-10 17:56 AdaMagica 2021-09-10 18:53 ` Dmitry A. Kazakov 0 siblings, 1 reply; 14+ messages in thread From: AdaMagica @ 2021-09-10 17:56 UTC (permalink / raw) I'm struggling to get the euro sign in a label or on a button in GtkAda. I have the euro sign on my German keyboard (on the E key), but I have no idea how this is encoded. So how do I get this in UTF8? ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-10 17:56 GtkAda and € AdaMagica @ 2021-09-10 18:53 ` Dmitry A. Kazakov 2021-09-11 9:20 ` AdaMagica 0 siblings, 1 reply; 14+ messages in thread From: Dmitry A. Kazakov @ 2021-09-10 18:53 UTC (permalink / raw) On 2021-09-10 19:56, AdaMagica wrote: > I'm struggling to get the euro sign in a label or on a button in GtkAda. > I have the euro sign on my German keyboard (on the E key), but I have no idea how this is encoded. So how do I get this in UTF8? With Strings Edit: Strings_Edit.UTF8.Image (16#20A0#) See: http://www.dmitry-kazakov.de/ada/strings_edit.htm#7 Otherwise, see: https://www.fileformat.info/info/unicode/char/20ac/index.htm It gives the hexadecimal UTF-8 encoding: 0xE2 0x82 0xAC So, in Ada: Character'Val (16#E2#) & Character'Val (16#82#) & Character'Val (16#AC#) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-10 18:53 ` Dmitry A. Kazakov @ 2021-09-11 9:20 ` AdaMagica 2021-09-11 9:57 ` AdaMagica 2021-09-11 10:04 ` Dmitry A. Kazakov 0 siblings, 2 replies; 14+ messages in thread From: AdaMagica @ 2021-09-11 9:20 UTC (permalink / raw) Is there no way to use the character € directly? Imagine, you want to write cyrillc on label of a gui? Would you use hex values or would you write Я говорю по-русски. Christoph ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 9:20 ` AdaMagica @ 2021-09-11 9:57 ` AdaMagica 2021-09-11 10:04 ` Dmitry A. Kazakov 1 sibling, 0 replies; 14+ messages in thread From: AdaMagica @ 2021-09-11 9:57 UTC (permalink / raw) Perhaps use it as Wide_Character? ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 9:20 ` AdaMagica 2021-09-11 9:57 ` AdaMagica @ 2021-09-11 10:04 ` Dmitry A. Kazakov 2021-09-11 11:11 ` Emmanuel Briot 2021-09-11 13:26 ` AdaMagica 1 sibling, 2 replies; 14+ messages in thread From: Dmitry A. Kazakov @ 2021-09-11 10:04 UTC (permalink / raw) On 2021-09-11 11:20, AdaMagica wrote: > Is there no way to use the character € directly? Imagine, you want to write cyrillc on label of a gui? Would you use hex values or would you write > Я говорю по-русски. I would never use Cyrillic in the source code. Anyway, this is a question regarding the encoding of literals in Ada. Ada 2X supports Unicode and GNAT supports Unicode sources. I never tried it but I suppose the following should work: Strings_Edit.UTF8.Handling.To_UTF8 ('€'); Here '€' should be resolved to Wide_Character'('€') and then converted to a UTF-8 encoded String. As for labels, icons etc, I use GTK style properties. I.e. let I have a label with a text on it. Usually this label would be packed in some larger container widget, e.g. Gtk_Grid_Record. I derive a custom widget from Gtk_Grid_Record. Then I call Initialize_Class_Record once to create the new widget "type" (used G_New). There I add style properties like this: Class_Record : aliased Ada_GObject_Class := Uninitialized_Class; ... procedure Initialize ( Widget : not null access My_Widget_Record'Class ) is begin G_New (Widget, Get_Type); -- Get_Type will register class ... function Get_Type return GType is begin if Initialize_Class_Record ( Ancestor => Gtk.Grid.Get_Type, -- Parent class Class_Record => Class_Record'Access, Type_Name => "mywidget" ) then -- Not yet registerd Install_Style_Property ( GLib.Types.Class_Ref (Class_Record.The_Type), Gnew_String ( Name => "label", Nick => "Label", Blurb => "Label text I want to be able to change", Default => "I speak English" ) ); ... end if; return Class_Record.The_Type; end Get_Type; The widget must handle "style-updated" from where it would use Style_Get to get the label text and set it into the label. So, a Russian localization would be a CSS sheet file defining the property "label": --------------------------- mywidget { -mywidget-label: "Я говорю по-русски"; } --------------------------- P.S. Inventors of GTK CSS sheets apparently misspelled the word "sheet", they should have used the letter 'i'! (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 10:04 ` Dmitry A. Kazakov @ 2021-09-11 11:11 ` Emmanuel Briot 2021-09-11 12:47 ` Dmitry A. Kazakov 2021-09-11 13:26 ` AdaMagica 1 sibling, 1 reply; 14+ messages in thread From: Emmanuel Briot @ 2021-09-11 11:11 UTC (permalink / raw) > custom widget from Gtk_Grid_Record. Then I call Initialize_Class_Record > once to create the new widget "type" (used G_New). There I add style > properties like this: I am impressed ! I have never had the courage to actually use those properties in my code... I would use GtkAda.Intl, so that the code would contain use GtkAda.Intl; Button.Set_Label (-"string to translate"); and the translations are given in a separate file. This is also theoretical for me: although we had initially try to maintain such a translation file for GPS (and made sure that all user-visible strings on the string where used with the "-" operator in case we ever wanted to do a translation, it was never done in practice). ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 11:11 ` Emmanuel Briot @ 2021-09-11 12:47 ` Dmitry A. Kazakov 0 siblings, 0 replies; 14+ messages in thread From: Dmitry A. Kazakov @ 2021-09-11 12:47 UTC (permalink / raw) On 2021-09-11 13:11, Emmanuel Briot wrote: > I am impressed ! I have never had the courage to actually use those properties in my code... I used properties because I had custom general-purpose widgets rather than an end application like GPS. A nice thing about GtkAda is that one can use all GTK stuff without any C insertions and it is highly extensible. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 10:04 ` Dmitry A. Kazakov 2021-09-11 11:11 ` Emmanuel Briot @ 2021-09-11 13:26 ` AdaMagica 2021-09-11 13:51 ` AdaMagica 1 sibling, 1 reply; 14+ messages in thread From: AdaMagica @ 2021-09-11 13:26 UTC (permalink / raw) Dmitry A. Kazakov schrieb am Samstag, 11. September 2021 um 12:04:44 UTC+2: > ... > Ada 2X supports Unicode and GNAT supports Unicode sources. > > I never tried it but I suppose the following should work: > > Strings_Edit.UTF8.Handling.To_UTF8 ('€'); > > Here '€' should be resolved to Wide_Character'('€') and then converted > to a UTF-8 encoded String. This does not work. Source files are in Latin_1 per default and € is beyond 255, so GNAT cannot handle '€'. I tried to set the source file's character set to Unicode UTF16 (in GPS, from the file's context menu choose "Properties...") with terrible effects. A real nogo. > As for labels, icons etc, I use GTK style properties. I dare not try this... > P.S. Inventors of GTK CSS sheets apparently misspelled the word "sheet", > they should have used the letter 'i'! (:-)) Nice ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 13:26 ` AdaMagica @ 2021-09-11 13:51 ` AdaMagica 2021-09-11 14:13 ` Dmitry A. Kazakov ` (2 more replies) 0 siblings, 3 replies; 14+ messages in thread From: AdaMagica @ 2021-09-11 13:51 UTC (permalink / raw) Being German, I need umlauts and € together in strings to write them to some labels. Using Character'Val (16#E2#) & Character'Val (16#82#) & Character'Val (16#AC#) complicates things, since umlauts are above 255 and need transformation to UTF8, whereas the euro sequence above is already in UTF8 and must not again be transformed. What a mess! ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 13:51 ` AdaMagica @ 2021-09-11 14:13 ` Dmitry A. Kazakov 2021-09-11 17:46 ` Manuel Gomez 2021-09-13 7:21 ` Vadim Godunko 2 siblings, 0 replies; 14+ messages in thread From: Dmitry A. Kazakov @ 2021-09-11 14:13 UTC (permalink / raw) On 2021-09-11 15:51, AdaMagica wrote: > Being German, I need umlauts and € together in strings to write them to some labels. > Using Character'Val (16#E2#) & Character'Val (16#82#) & Character'Val (16#AC#) > complicates things, since umlauts are above 255 and need transformation to UTF8, > whereas the euro sequence above is already in UTF8 and must not again be transformed. > > What a mess! Huh, the mess here is Latin-1 introduced by Ada 95, no such thing should have been even supported. This happened because in 90s UTF-8 was not yet established, so Ada 95 made Character Latin-1 and added Wide_Character for UCS-2. This was a huge mistake with wide (pun intended) reaching nasty consequences. Since Ada type system is too weak to handle encodings, Strings should simply be UTF-8 and Character an octet with lower 7-bits corresponding to ASCII. Anyway, for anything that is not ASCII I use a named constant. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 13:51 ` AdaMagica 2021-09-11 14:13 ` Dmitry A. Kazakov @ 2021-09-11 17:46 ` Manuel Gomez 2021-09-12 7:04 ` AdaMagica 2021-09-13 7:21 ` Vadim Godunko 2 siblings, 1 reply; 14+ messages in thread From: Manuel Gomez @ 2021-09-11 17:46 UTC (permalink / raw) Am 11/9/21 um 15:51 schrieb AdaMagica: > Being German, I need umlauts and € together in strings to write them to some labels. > Using Character'Val (16#E2#) & Character'Val (16#82#) & Character'Val (16#AC#) > complicates things, since umlauts are above 255 and need transformation to UTF8, > whereas the euro sequence above is already in UTF8 and must not again be transformed. > > What a mess! > When converting to UTF8, can you specify that you are using Latin-9 (ISO-8859-15), instead of Latin-1? Latin-9 is equivalent to Latin-1 plus the Euro sign, instead of the generic currency sign, since Latin-1 predates the Euro. In that case, it would be: Euro_Sign : constant Character := Character'Val (164); This is from Ada.Characters.Latin_9, provided by GNAT (not in the standard). Not sure, buy maybe you could type the Euro sign in the source code with the keyboard, since the representation is the same. Another option is to use ASCII only (with some encoding for umlauts and Euro sign) and then apply localization for the strings that must be "translated" to proper German. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 17:46 ` Manuel Gomez @ 2021-09-12 7:04 ` AdaMagica 2021-09-12 11:44 ` Manuel Gomez 0 siblings, 1 reply; 14+ messages in thread From: AdaMagica @ 2021-09-12 7:04 UTC (permalink / raw) Manuel Gomez schrieb am Samstag, 11. September 2021 um 19:46:52 UTC+2: > When converting to UTF8, can you specify that you are using Latin-9 > (ISO-8859-15), instead of Latin-1? Latin-9 is equivalent to Latin-1 plus > the Euro sign, instead of the generic currency sign, since Latin-1 > predates the Euro. > > In that case, it would be: > > Euro_Sign : constant Character := Character'Val (164); > > This is from Ada.Characters.Latin_9, provided by GNAT (not in the > standard). Not sure, buy maybe you could type the Euro sign in the > source code with the keyboard, since the representation is the same. In Gnat Studio, you can set the encoding (from the file's context menu choose "Properties...") to Latin_9. Then the character 164 is displayed as € in the Ada source file. You can even use the € key on the keyboard. That does not help, however, since Unicode is based on Latin_1, and when this is transformed to UTF8, the currency character appears on the GtkAda GUI. > Another option is to use ASCII only (with some encoding for umlauts and > Euro sign) and then apply localization for the strings that must be > "translated" to proper German. I indeed use Character 164 as a placeholder in the Ada source code. When transforming to UTF8, I search for this character first, transform the head string, insert the Euro sequence and transform the tail string recursively. This works. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-12 7:04 ` AdaMagica @ 2021-09-12 11:44 ` Manuel Gomez 0 siblings, 0 replies; 14+ messages in thread From: Manuel Gomez @ 2021-09-12 11:44 UTC (permalink / raw) Am 12/9/21 um 9:04 schrieb AdaMagica: > In Gnat Studio, you can set the encoding (from the file's context menu > choose "Properties...") to Latin_9. Then the character 164 is displayed as € > in the Ada source file. You can even use the € key on the keyboard. That > does not help, however, since Unicode is based on Latin_1, and when this > is transformed to UTF8, the currency character appears on the GtkAda GUI. I suppose this is because the conversion assumes Latin-1 input, and it is acceptable given that String type should be in that encoding, but with a general string conversion library, like iconv, you can convert between any 8-bit character encoding and UTF-8. Here an Ada binding to iconv (I haven't used it): https://github.com/ytomino/iconv-ada And Matreshka League has several 8-bit character encodings, although it lacks ISO-8859-15. It should be easy to add ISO-8859-15 based on ISO-8859-1: http://forge.ada-ru.org/matreshka/wiki/League/TextCodec But I guess what you are already doing is the easiest approach. It's just one character. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: GtkAda and € 2021-09-11 13:51 ` AdaMagica 2021-09-11 14:13 ` Dmitry A. Kazakov 2021-09-11 17:46 ` Manuel Gomez @ 2021-09-13 7:21 ` Vadim Godunko 2 siblings, 0 replies; 14+ messages in thread From: Vadim Godunko @ 2021-09-13 7:21 UTC (permalink / raw) On Saturday, September 11, 2021 at 4:51:41 PM UTC+3, AdaMagica wrote: > Being German, I need umlauts and € together in strings to write them to some labels. > Using Character'Val (16#E2#) & Character'Val (16#82#) & Character'Val (16#AC#) > complicates things, since umlauts are above 255 and need transformation to UTF8, > whereas the euro sequence above is already in UTF8 and must not again be transformed. > > What a mess! Character encoding in source code, input-output and GUI is know mess. There is Ada 2022 library that provides high level API to process text information, see https://github.com/AdaCore/VSS You can try to use Virtual_String everywhere, and do encoding conversion only to get/pass text from/to Gtk+ or input-output streams. Note, if you want to write characters outside of the ASCII range in the source code you will need to use UTF8 for source files and provide -gnatW8 switch to compiler. It may breaks compilation of the old code sometimes :( ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2021-09-13 7:21 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-09-10 17:56 GtkAda and € AdaMagica 2021-09-10 18:53 ` Dmitry A. Kazakov 2021-09-11 9:20 ` AdaMagica 2021-09-11 9:57 ` AdaMagica 2021-09-11 10:04 ` Dmitry A. Kazakov 2021-09-11 11:11 ` Emmanuel Briot 2021-09-11 12:47 ` Dmitry A. Kazakov 2021-09-11 13:26 ` AdaMagica 2021-09-11 13:51 ` AdaMagica 2021-09-11 14:13 ` Dmitry A. Kazakov 2021-09-11 17:46 ` Manuel Gomez 2021-09-12 7:04 ` AdaMagica 2021-09-12 11:44 ` Manuel Gomez 2021-09-13 7:21 ` Vadim Godunko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox