Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 90 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"i18n-embed/examples/library-fluent",
"i18n-embed/examples/desktop-bin",
"i18n-embed-fl/examples/web-server",
"i18n-embed/examples/custom-config-path",
]

[workspace.dependencies]
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ fn example(file: String) {

### Minimal Configuration

You will need to create an `i18n.toml` configuration in the root directory of your crate. A minimal configuration for a binary crate to be localized to Spanish and Japanese using the `gettext` system would be:
You will need to create an `i18n.toml` configuration. By default this is in the root directory of your crate, but it can be [configured](#configuration) to use another location.

A minimal configuration for a binary crate to be localized to Spanish and Japanese using the `gettext` system would be:

```toml
# (Required) The language identifier of the language used in the
Expand Down Expand Up @@ -248,6 +250,15 @@ use_fuzzy = false
assets_dir = "i18n"
```

Available configuration options for `Cargo.toml`:

```toml
[package.metadata.cargo-i18n]
# (Optional) The path to the i18n configuration file used by cargo-i18n and i18n-embed.
# The path is relative to the crate root.
config-path = "i18n.toml"
```

## System Requirements

### Gettext Requirements
Expand Down
32 changes: 23 additions & 9 deletions i18n-build/src/gettext_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::error::{PathError, PathType};
use crate::util;
use i18n_config::{Crate, GettextConfig, I18nConfigError};
use i18n_config::{Crate, GettextConfig, I18nCargoMetadata, I18nConfigError};

use std::ffi::OsStr;
use std::fs::{create_dir_all, File};
Expand Down Expand Up @@ -407,11 +407,13 @@ pub fn run(crt: &Crate) -> Result<()> {
.subcrates
.iter()
.map(|subcrate_path| {
Crate::from(
subcrate_path.clone(),
Some(crt),
crt.config_file_path.clone(),
)
let subcrate_config_path =
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behaviour from using the parent's custom config path to using the child's custom config path, then falling back to the basic i18n.toml. I'm not sure in what cases the old behaviour would have applied, so I'd appreciate your input on whether this is the best way to go about this change.

I18nCargoMetadata::from_cargo_manifest(subcrate_path.join("Cargo.toml"))
.ok()
.and_then(|m| m.config_path)
.map(PathBuf::from)
.unwrap_or(PathBuf::from("i18n.toml"));
Crate::from(subcrate_path.clone(), Some(crt), subcrate_config_path)
})
.collect();

Expand All @@ -432,9 +434,21 @@ pub fn run(crt: &Crate) -> Result<()> {
};

let src_dir = crt.path.join("src");
let pot_dir = config_crate.path.join(gettext_config.pot_dir());
let po_dir = config_crate.path.join(gettext_config.po_dir());
let mo_dir = config_crate.path.join(gettext_config.mo_dir());
let pot_dir = config_crate
.config_file_path
.parent()
.unwrap_or(&config_crate.path)
.join(gettext_config.pot_dir());
let po_dir = config_crate
.config_file_path
.parent()
.unwrap_or(&config_crate.path)
.join(gettext_config.po_dir());
let mo_dir = config_crate
.config_file_path
.parent()
.unwrap_or(&config_crate.path)
.join(gettext_config.mo_dir());

// perform string extraction if required
if do_xtr {
Expand Down
2 changes: 1 addition & 1 deletion i18n-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ maintenance = { status = "actively-developed" }

[dependencies]
log = { workspace = true }
basic-toml = "0.1"
serde = { workspace = true, features = ["derive"] }
serde_derive = { workspace = true }
thiserror = { workspace = true }
toml = "0.9.4"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switches from basic_toml to toml as the former is unmaintained, but if you don't want this change I can certainly revert it

unic-langid = { workspace = true, features = ["serde"] }
Loading