Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide i18n support #776

Open
bilelmoussaoui opened this issue Oct 4, 2022 · 14 comments
Open

Provide i18n support #776

bilelmoussaoui opened this issue Oct 4, 2022 · 14 comments
Labels
enhancement New feature or request glib
Milestone

Comments

@bilelmoussaoui
Copy link
Member

Currently, gtk-rs based application that has to handle translations makes use of gettext-rs crate. It has some disadvantages like it shipping a gettext tarball when building under windows/macos(i think) which makes the vendored tarball of such applications pretty large for nothing when they target linux only.

Those gtk-rs applications also make use of various functions that are copy pasted between those applications, see https://gitlab.gnome.org/World/amberol/-/blob/main/src/i18n.rs for example. As glib itself provides helpers for making an application translatable, it would be nice to provide/expose some helper/wrapper functions.

cc @jf2048

@bilelmoussaoui bilelmoussaoui added enhancement New feature or request glib labels Oct 4, 2022
@sdroege sdroege changed the title Proivde i18n support Provide i18n support Oct 4, 2022
@sdroege sdroege added this to the 0.16.0 milestone Oct 4, 2022
@jf2048
Copy link
Member

jf2048 commented Oct 4, 2022

We should provide some better wrappers for the functions glib provides in glib/ggettext.h, and also maybe a rust version of gi18n.h and gi18n-lib.h.

For issues with gettext-rs I think it would be better to try to upstream another feature flag that does what we want. Everything else about that crate is fine, and it is still needed for some of the other gettext functions and enums anyway.

@sdroege
Copy link
Member

sdroege commented Oct 4, 2022

For issues with gettext-rs I think it would be better to try to upstream another feature flag that does what we want.

What are those issues? Build-time / shipping issues like including a gettext tarball and building the C library are nothing you can cleanly handle via cargo features unfortunately.

@jf2048
Copy link
Member

jf2048 commented Oct 4, 2022

But it already does handle linking to the system library with a feature flag: https://github.com/Koka/gettext-rs/blob/ea91043635cfc44f442379d2b552166b7ec981a5/gettext-sys/build.rs#L88

We just need another flag that skips the compiling and uses a stub.

@jf2048
Copy link
Member

jf2048 commented Oct 4, 2022

BTW, this issue might be related to gettext-rs shipping its own copy: gtk-rs/gtk3-rs#755

@sdroege
Copy link
Member

sdroege commented Oct 4, 2022

cargo feature flags are supposed to be additive, so they don't really work for build configuration. It's something that has to be configured by whoever builds the final application, not by some crate somewhere in the dependency tree. Unfortunately cargo doesn't really have any mechanism for such configurations.

@bilelmoussaoui
Copy link
Member Author

The problem is the version uploaded to crates.io contains the tarball already, so it is not something you can avoid when cargo vendoring.

@jf2048
Copy link
Member

jf2048 commented Oct 4, 2022

Hmm, then that library should probably be forked. Unless we are ok with copying all functions into the glib crate

@sdroege
Copy link
Member

sdroege commented Oct 5, 2022

Why not, it's not a lot of code. Or a separate glib-i18n crate in here that does all this, which might be slightly cleaner because it's not exactly "GLib bindings" anymore :)

We'd need that anyway so it makes use of our NULL-terminated string types or not?

@sdroege
Copy link
Member

sdroege commented Oct 5, 2022

Also in relation to the Rust proxy-libintl implementation we talked about yesterday

@sdroege sdroege modified the milestones: 0.16.0, 0.17.0 Oct 10, 2022
@sdroege sdroege mentioned this issue Oct 10, 2022
Closed
@jf2048
Copy link
Member

jf2048 commented Nov 21, 2022

WIP branch with a glib-i18n package here: jf2048@63131f7

It supports string formatting and has most of the functions from gettext.h, and a rust reimplementation of proxy-libintl

@jf2048
Copy link
Member

jf2048 commented Dec 13, 2022

I guess after playing around with this a bit, I am skeptical compared to a native Rust implementation like gettext which is actually less code than my glib-i18n library. If we use the C functions we always have to scan the strings for the null terminator. But the string lengths are actually in the .mo files, a fast Rust implementation could memory map the file and just return pointers into it. (See justinas/gettext#11)

@sdroege
Copy link
Member

sdroege commented Dec 14, 2022

If that works smoothly and consistent with other (C) applications then sure, why not.

@sdroege sdroege modified the milestones: 0.17.0, 0.18.0 Jan 21, 2023
@sdroege
Copy link
Member

sdroege commented Jan 21, 2023

Let's move this to next milestone then. @jf2048 what's your plans/ideas/status here?

@jf2048
Copy link
Member

jf2048 commented Jan 22, 2023

Benchmark a pure rust implementation versus the glibc gettext and see what we need to do to improve it. It is possible we can end up more performant than C code by doing compile-time string hashing. I am not sure if it makes sense to try to reimplement the hashing algorithm from gettext or go with another one like
const-fnv1a-hash. We cannot avoid .mo files because GtkBuilder uses it, but if needed we can extend it with another file that contains some of our own hashing.

@bilelmoussaoui bilelmoussaoui modified the milestones: 0.18.0, 0.20 May 31, 2024
@sdroege sdroege modified the milestones: 0.20, 0.21 Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request glib
Projects
None yet
Development

No branches or pull requests

3 participants