fltk-rs / fl2rust

A fluid (fltk ui designer) file to Rust transpiler
MIT License
52 stars 3 forks source link

Is localization possible? #2

Closed 1sra3l closed 3 years ago

1sra3l commented 3 years ago

As you probably know you can use localization for the label of widgets in C++. The output looks great, everything retains their "C++" Name: field! This is just fantastic work! I don't know the best localization methods in rust yet, nor much about how to do it. I know the label would need to be some sort of mutable string, that can be set from a LANG.po file if that ${LANG/_*}.po file exists. But I have only used C++ and shell for this type of thing. This is what the fld file has:

i18n_type 1
i18n_include <libintl.h>
i18n_function gettext

OR

i18n_type 2
i18n_include <nl_types.h>
i18n_set 1

It may be better to do it from the rust fluid, perhaps?

MoAlyousef commented 3 years ago

It should be possible. FLUID just wraps the text ina gettext macro, which can be replaced with a Rust based macro from one of the i18n crates, which I also haven’t worked with so I don’t have any preferences. I’ll take a look thru some of them.

1sra3l commented 3 years ago

Oh good idea! Thank you for looking, I have not used any of the i18n crates, so I am sure whatever you find will work. Thank you for looking into this. It is so exciting to quickly build UI for Rust apps, having translations will make it even better!

MoAlyousef commented 3 years ago

I've published version 0.4.4. If you enable internalization in FLUID, it should prepend all labels with the tr! macro from the tr crate. tr uses gettext-rs (C Wrapper) or gettext (rust reimplementation) and only requires initialization in the main.rs file:

#[macro_use]
extern crate tr;

fn main() {
    tr_init!("some path");
    // rest of the code
}

gettext-rs has build issues with window msvc, so to use the rust reimplementation, you would need to disable gettext-rs since it's the default for tr:

[dependencies]
tr = { version = "*", default-features=false, features=["gettext"] }

tr has its own ecosystem built on it with tools to extract strings and others to embed translation files with cargo etc.

1sra3l commented 3 years ago

I suppose I should have closed this already, sorry for the delay