bugGNU gettext - Bugs: bug #56774, support Rust programming language

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #56774: support Rust programming language

Submitter:  Bruno Haible <haible>
Submitted:  Sun 18 Aug 2019 07:38:25 PM UTC
Votes: 102
 
Category:  Rust Severity:  4 - Important
Item Group:  None Status:  Fix Released
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed

Jump to the original submission

Tue 25 Feb 2025 02:07:24 PM UTC, comment #10: 

The fix is contained in gettext 0.24.

Bruno Haible <haible>
Group administrator
Tue 11 Feb 2025 10:48:44 AM UTC, comment #9: 


> looking at the tests it looks like named variables are not supported. At the same time the docs say that all formats supported by formatx are supported, but formatx supports named variables, as can be seen in the examples


Thanks for the report. I had miunderstood the formatx documentation. Now fixed, through
https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=3cbdb13073fbc9eda5753a66ad4c03822722bf5f

Bruno Haible <haible>
Group administrator
Wed 29 Jan 2025 09:31:16 AM UTC, comment #8: 

Thank you for implementing this.

I didn't test it yet, but looking at the tests it looks like named variables are not supported. At the same time the docs say that all formats supported by formatx are supported, but formatx supports named variables, as can be seen in the examples:


formatx!("x = {}, y = {y}", 10, y = 30).unwrap();


Kévin <zecakeh>
Tue 28 Jan 2025 10:27:15 PM UTC, comment #7: 

Implemented through https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commit;h=e12c0558adef51f37436c562ab5b0dc7d6829804 .

Kévin: I made use of the unit tests in your patches; thanks for that. I couldn't make use of your format-rust.c code, because the Rust format strings documented in https://doc.rust-lang.org/std/fmt/ are only usable as string literals. I chose to not make use of your x-rust.c code, because the Rust language is still evolving and I wanted an approach that is easier to adapt to Rust language changes.

Bruno Haible <haible>
Group administrator
Fri 17 Jan 2025 02:41:41 AM UTC, comment #6: 

Raised again on the bug-gettext mailing list here:
https://lists.gnu.org/archive/html/bug-gettext/2025-01/msg00017.html

Eric Gallager <egallager>
Tue 29 Aug 2023 10:55:13 AM UTC, comment #5: 

Is there any update on this, i.e., what would be the steps required to get the proposed patch merged?

As we (Proxmox) would also like to use gettext in rust based projects, and while we can write our own scanner, or try applying the proposed patch to a downstream build, we'd rather see the already existing effort getting upstreamed.

Thomas <tlmp>
Thu 31 Mar 2022 07:27:52 PM UTC, comment #4: 

Although I sent it a couple of months ago, to make sure that my work is not lost, I'm posting it in the bug tracker so it's attached to the proper bug.

These are patches that add Rust support to gettext. They were deemed too big to be posted in the mailing list so here's a link to them:

<https://gitlab.gnome.org/-/snippets/2934>

(file #53025, file #53026)

Kévin <zecakeh>
Sat 01 Jan 2022 11:51:53 AM UTC, comment #3: 

I would like to work on that feature.

I looked around the code a bit and basically we need "format-rust.c" for msgfmt and "x-rust.c" for xgettext, right?

Here are Rust i18n libraries compatible with gettext:

  • gettext: emulates gettext. It provides gettext, ngettext, pgettext and npgettext methods on a Catalog object with the same API as the corresponding gettext functions. It doesn't support Rust string formatting.
  • gettext-rs: uses gettext. It provides gettext, ngettext, pgettext, npgettext, dcgettext, dcngettext, dgettext, dngettext methods with the same API as the corresponding gettext functions. It provides macros with the same names and the macro invocation operator '!' that allow Rust string formatting while keeping a regular function API. It doesn't support all of Rust string format yet.
  • tr: uses either of the two previous libraries. It provides a single tr! macro that allows Rust string formatting but has its own API to support the same features as gettext, ngettext, pgettext, npgettext. It doesn't support all of Rust string format yet. It provides its own extractor called xtr.


An extractor using keywords for gettext functions names and macro names should work with the two first libraries. A parser for Rust string format should work with all three libraries.

GNOME Rust apps usually use the gettext-rs library.

Kévin <zecakeh>
Wed 29 Dec 2021 10:45:20 AM UTC, comment #2: 

For reference, the gettext-rs crate allows us to use xgettext to translate strings.

If we only use functions, POT generation works well with Rust, detecting it like the C language. We can apply Rust string formatting at runtime by creating other functions around gettext-rs, and use the keyword option to make xgettext detect those new functions.

However we lose compile-time string formatting validation. To solve that, we need to use macros whose name always ends with a !, which makes them incompatible with the keyword option.

Kévin <zecakeh>
Wed 29 Dec 2021 10:26:31 AM UTC, comment #1: 

Also note this discussion about supporting Rust in GNOME i18n.

https://gitlab.gnome.org/GNOME/fractal/-/issues/874

Claude Paroz <claudep>
Sun 18 Aug 2019 07:38:25 PM UTC, original submission:  

Many applications are being written in Rust, such as web browsers (Firefox) and terminal emulators (alacritty).
Gettext should support this language.

Bruno Haible <haible>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by egallager (Posted a comment)
  • -email is unavailable- added by egallager (Voted in favor of this item)
  • -email is unavailable- added by tlmp (Posted a comment)
  • -email is unavailable- added by zanchey (Voted in favor of this item)
  • -email is unavailable- added by zecakeh (Posted a comment)
  • -email is unavailable- added by claudep (Posted a comment)
  • -email is unavailable- added by sophie (Voted in favor of this item)
  • -email is unavailable- added by haible (Submitted the item)
  •  

    There are 102 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-02-25 haible StatusFixed Fix Released
    2025-01-28 haible CategoryOther Rust
        StatusNone Fixed
        Assigned toNone haible
        Open/ClosedOpen Closed
    2025-01-17 egallager Carbon-Copy- Added egallager
    2023-07-16 zanchey Carbon-Copy- Added zanchey
    2022-03-31 zecakeh Attached File- Added 0001-Add-support-for-Rust-format-strings.patch, #53025
        Attached File- Added 0002-xgettext-Add-Rust-support.patch, #53026
    2020-11-03 sophie Carbon-Copy- Added sophie

    Back to the top

    Powered by Savane 3.15-e6e5.
    Corresponding source code