Skip to content

Commit

Permalink
Implement l10n from tar (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamRodri authored Dec 24, 2024
1 parent df9c5cc commit 6fe912f
Show file tree
Hide file tree
Showing 25 changed files with 812 additions and 408 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Add `L10N.load_tar` to support embedded localization resources.
* Changed `ByteLength` to display unit symbols.
* Ignore not found error on `cargo zng l10n` cleanup.

Expand Down
8 changes: 8 additions & 0 deletions crates/zng-ext-l10n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ repository = "https://github.com/zng-ui/zng"
categories = ["gui"]
keywords = ["gui", "ui", "user-interface", "zng"]

[features]
# Support for loading localization resources from TAR and Tarball.
tar = ["dep:flate2", "dep:tar"]
default = ["tar"]

[dependencies]
zng-ext-l10n-proc-macros = { path = "../zng-ext-l10n-proc-macros", version = "0.2.9" }

Expand All @@ -36,3 +41,6 @@ once_cell = "1.19"
dunce = "1.0"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }

flate2 = { version = "1.0", optional = true }
tar = { version = "0.4", optional = true }
9 changes: 9 additions & 0 deletions crates/zng-ext-l10n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ This crate is part of the [`zng`](https://github.com/zng-ui/zng?tab=readme-ov-fi


<!--do doc --readme features-->
## Cargo Features

This crate provides 1 feature flag, enabled by default.
#### `"tar"`
Support for loading localization resources from TAR and Tarball.

*Enabled by default.*

<!--do doc --readme #SECTION-END-->


13 changes: 13 additions & 0 deletions crates/zng-ext-l10n/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ impl L10N {
self.load(L10nDir::open(dir))
}

/// Load localization resources from a `.tar` or `.tar.gz` container.
///
/// The expected container layout is `root_dir/{lang}/{file}.ftl` app files and `root_dir/{lang}/deps/{pkg-name}/{pkg-version}/{file}.ftl`
/// for dependencies, same as [`load_dir`], `root_dir` can have any name.
///
/// The data can be embedded using [`include_bytes!`] or loaded into a `Vec<u8>` and must be in the `.tar` or `.tar.gz` format.
///
/// [`load_dir`]: L10N::load_dir
#[cfg(feature = "tar")]
pub fn load_tar(&self, data: impl Into<L10nTarData>) {
self.load(L10nTar::load(data))
}

/// Available localization files.
///
/// The value maps lang to one or more files, the files can be from the project `dir/{lang}/{file}.ftl` or from dependencies
Expand Down
Loading

0 comments on commit 6fe912f

Please sign in to comment.