• =?UTF-8?B?R3RrQWRhIGFuZCDigqw=?=

    From AdaMagica@21:1/5 to All on Fri Sep 10 10:56:19 2021
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to AdaMagica on Fri Sep 10 20:53:07 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to All on Sat Sep 11 02:20:32 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to AdaMagica on Sat Sep 11 12:04:40 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to All on Sat Sep 11 02:57:51 2021
    Perhaps use it as Wide_Character?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Emmanuel Briot@21:1/5 to All on Sat Sep 11 04:11:35 2021
    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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Emmanuel Briot on Sat Sep 11 14:47:53 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to Dmitry A. Kazakov on Sat Sep 11 06:26:29 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to All on Sat Sep 11 06:51:40 2021
    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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to AdaMagica on Sat Sep 11 16:13:07 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Manuel Gomez@21:1/5 to All on Sat Sep 11 19:46:46 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From AdaMagica@21:1/5 to Manuel Gomez on Sun Sep 12 00:04:47 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Manuel Gomez@21:1/5 to All on Sun Sep 12 13:44:54 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vadim Godunko@21:1/5 to AdaMagica on Mon Sep 13 00:21:05 2021
    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 :(

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)