Files
fish-shell/printf
Daniel Rainer 80033adcf5 Use LocalizableString for gettext
This new wrapper type can be constructed via macros which invoke the
`gettext_extract` proc macro to extract the string literals for PO file
generation.

The type checking enabled by this wrapper should prevent trying to obtain
translations for a string for which none exist.

Because some strings (e.g. for completions) are not defined in Rust, but rather
in fish scripts, the `LocalizableString` type can also be constructed from
non-literals, in which case no extraction happens.
In such cases, it is the programmer's responsibility to only construct the type
for strings which are available for localization.

This approach is a replacement for the `cargo-expand`-based extraction.

When building with the `FISH_GETTEXT_EXTRACTION_FILE` environment variable set,
the `gettext_extract` proc macro will write the messages marked for extraction
to a file in the directory specified by the variable.

Updates to the po files:
- This is the result of running the `update_translations.fish` script using the
  new proc_macro extraction. It finds additional messages compared to the
  `cargo-expand` based approach.
- Messages IDs corresponding to paths are removed. The do not have localizations
  in any language and localizing paths would not make sense. I have not
  investigated how they made it into the po files in the first place.
- Some messages are reordered due to `msguniq` sorting differing from `sort`.

Remove docs about installing `cargo-expand`
These are no longer needed due to the switch to our extraction macro.
2025-06-07 00:10:05 +02:00
..
2025-05-03 22:53:27 +02:00
2025-06-07 00:10:05 +02:00
2025-05-02 22:31:39 +02:00

fish-printf

The printf implementation used in fish-shell, based on musl printf.

crates.io

Licensed under the MIT license.

Usage

Run cargo add fish-printf to add this crate to your Cargo.toml file.

Notes

fish-printf attempts to match the C standard for printf. It supports the following features:

  • Locale-specific formatting (decimal point, thousands separator, etc.)
  • Honors the current rounding mode.
  • Supports the %n modifier for counting characters written.

fish-printf does not support positional arguments, such as printf("%2$d", 1, 2).

Prefixes like l or ll are recognized, but only used for validating the format string. The size of integer values is taken from the argument type.

fish-printf can output to an std::fmt::Write object, or return a string.

For reasons related to fish-shell, fish-printf has a feature "widestring" which uses the widestring crate. This is off by default. If enabled, run cargo add widestring to add the widestring crate.

Examples

use fish_printf::sprintf;

// Create a `String` from a format string.
let s = sprintf!("%0.5g", 123456.0) // 1.2346e+05

// Append to an existing string.
let mut s = String::new();
sprintf!(=> &mut s, "%0.5g", 123456.0) // 1.2346e+05

See the crate documentation for additional examples.