Fltk how to translate tooltip with gettext-ng?

Hello,
did build a litte program translate works
but not with tooltip.

here a example:

snip from the Code:

play_btn.set_tooltip("Play Morse Code");

de-DE.po

msgid "Play Morse Code"
msgstr "Morse Code abspielen"

msgfmt de-DE.po -o de-DE.mo

What did I wrong ?

Assuming you’re talking about this, you never called into the gettext API to retrieve the appropriate translation. You just set the raw string "Play Morse Code" as tooltip text.

gettext_ng is documented here:

I.e.:

use std::fs::File;
use gettext::Catalog;

fn main() {
    let f = File::open("french.mo").expect("could not open the catalog");
    let catalog = Catalog::parse(f).expect("could not parse the catalog");

    <SNIP>

    play_btn.set_tooltip(catalog.gettext("Play Morse Code"));
}

thank you so much….

but I have more than one translations in my code

variable moved due to use in closure...185 | ...lay_btn.set_tooltip(catalog.gettext("Play Morse Code"));|                        ^^^^^^^ value borrowed here after move


Do I need a catatlog per translation ?I have for example this lines:
        let mut wind = Window::new(100, 100, 400, 300, catalog.gettext("Morse Code Trainer"));       
...

slider.set_tooltip(catalog.gettext("adjust WPM (Words per minute)"));this works with translation

found it, need to move the line with gettext up
then it work

thank you so much!

let mut play_btn = Button::new(120, 250, 100, 40, catalog.gettext("Play"));
play_btn.set_image(Some(image::SvgImage::from_data(PLAYICON).unwrap()));
play_btn.set_align(Align::ImageNextToText);
play_btn.set_tooltip(catalog.gettext("Play Morse Code"));

insted off

play_btn.set_callback(move |_| {
let morse = text_to_morse(&input_c.value());
let wpm = slider.value() as u32;
thread::spawn(move || play_morse(&morse, wpm));
});
play_btn.set_tooltip(catalog.gettext("Play Morse Code"));

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.