amethyst: add wip i18n support

i18n
Fries 2 years ago committed by fries1234
parent bbc2ac7991
commit 8f9ce37a78

331
Cargo.lock generated

@ -23,6 +23,8 @@ dependencies = [
"directories",
"futures",
"fuzzy-matcher",
"i18n-embed",
"i18n-embed-fl",
"indicatif",
"lazy-regex",
"lazy_static",
@ -32,6 +34,7 @@ dependencies = [
"pacmanconf",
"parking_lot 0.12.1",
"regex",
"rust-embed",
"serde",
"textwrap 0.15.0",
"tokio",
@ -40,6 +43,7 @@ dependencies = [
"tracing-error",
"tracing-subscriber",
"trigram",
"unic-langid",
]
[[package]]
@ -202,6 +206,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "block"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "block-buffer"
version = "0.10.3"
@ -482,6 +492,19 @@ dependencies = [
"typenum",
]
[[package]]
name = "dashmap"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if",
"hashbrown",
"lock_api",
"once_cell",
"parking_lot_core 0.9.3",
]
[[package]]
name = "dialoguer"
version = "0.10.2"
@ -496,9 +519,9 @@ dependencies = [
[[package]]
name = "digest"
version = "0.10.3"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c"
dependencies = [
"block-buffer",
"crypto-common",
@ -564,12 +587,65 @@ dependencies = [
"instant",
]
[[package]]
name = "find-crate"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59a98bbaacea1c0eb6a0876280051b892eb73594fd90cf3b20e9c817029c57d2"
dependencies = [
"toml",
]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "fluent"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61f69378194459db76abd2ce3952b790db103ceb003008d3d50d97c41ff847a7"
dependencies = [
"fluent-bundle",
"unic-langid",
]
[[package]]
name = "fluent-bundle"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e242c601dec9711505f6d5bbff5bedd4b61b2469f2e8bb8e57ee7c9747a87ffd"
dependencies = [
"fluent-langneg",
"fluent-syntax",
"intl-memoizer",
"intl_pluralrules",
"rustc-hash",
"self_cell",
"smallvec",
"unic-langid",
]
[[package]]
name = "fluent-langneg"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94"
dependencies = [
"unic-langid",
]
[[package]]
name = "fluent-syntax"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0abed97648395c902868fee9026de96483933faa54ea3b40d652f7dfe61ca78"
dependencies = [
"thiserror",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -840,6 +916,75 @@ dependencies = [
"tokio-native-tls",
]
[[package]]
name = "i18n-config"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62affcd43abfb51f3cbd8736f9407908dc5b44fc558a9be07460bbfd104d983"
dependencies = [
"log",
"serde",
"serde_derive",
"thiserror",
"toml",
"unic-langid",
]
[[package]]
name = "i18n-embed"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7f21ed76e44de8ac3dfa36bb37ab2e6480be0dc75c612474949be1f3cb2c253"
dependencies = [
"fluent",
"fluent-langneg",
"fluent-syntax",
"i18n-embed-impl",
"intl-memoizer",
"lazy_static",
"locale_config",
"log",
"parking_lot 0.12.1",
"rust-embed",
"thiserror",
"unic-langid",
"walkdir",
]
[[package]]
name = "i18n-embed-fl"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9420a9718ef9d0ab727840a398e25408ea0daff9ba3c681707ba05485face98e"
dependencies = [
"dashmap",
"find-crate",
"fluent",
"fluent-syntax",
"i18n-config",
"i18n-embed",
"lazy_static",
"proc-macro-error",
"proc-macro2",
"quote",
"strsim",
"syn",
"unic-langid",
]
[[package]]
name = "i18n-embed-impl"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0db2330e035808eb064afb67e6743ddce353763af3e0f2bdfc2476e00ce76136"
dependencies = [
"find-crate",
"i18n-config",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "iana-time-zone"
version = "0.1.47"
@ -902,6 +1047,26 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "intl-memoizer"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f"
dependencies = [
"type-map",
"unic-langid",
]
[[package]]
name = "intl_pluralrules"
version = "7.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf"
dependencies = [
"tinystr",
"unic-langid",
]
[[package]]
name = "ipnet"
version = "2.5.0"
@ -975,6 +1140,19 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "locale_config"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d2c35b16f4483f6c26f0e4e9550717a2f6575bcd6f12a53ff0c490a94a6934"
dependencies = [
"lazy_static",
"objc",
"objc-foundation",
"regex",
"winapi",
]
[[package]]
name = "lock_api"
version = "0.4.8"
@ -994,6 +1172,15 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
dependencies = [
"libc",
]
[[package]]
name = "matchers"
version = "0.1.0"
@ -1157,6 +1344,35 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "objc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
dependencies = [
"block",
"objc",
"objc_id",
]
[[package]]
name = "objc_id"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.29.0"
@ -1528,6 +1744,40 @@ dependencies = [
"serde",
]
[[package]]
name = "rust-embed"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e26934cd67a1da1165efe61cba4047cc1b4a526019da609fcce13a1000afb5fa"
dependencies = [
"rust-embed-impl",
"rust-embed-utils",
"walkdir",
]
[[package]]
name = "rust-embed-impl"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35d7b402e273544cc08e0824aa3404333fab8a90ac43589d3d5b72f4b346e12"
dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn",
"walkdir",
]
[[package]]
name = "rust-embed-utils"
version = "7.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1669d81dfabd1b5f8e2856b8bbe146c6192b0ba22162edc738ac0a5de18f054"
dependencies = [
"sha2",
"walkdir",
]
[[package]]
name = "rust-ini"
version = "0.18.0"
@ -1544,12 +1794,27 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.20"
@ -1589,6 +1854,12 @@ dependencies = [
"libc",
]
[[package]]
name = "self_cell"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
[[package]]
name = "serde"
version = "1.0.144"
@ -1643,6 +1914,17 @@ dependencies = [
"digest",
]
[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"
@ -1825,6 +2107,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tinystr"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29738eedb4388d9ea620eeab9384884fc3f06f586a2eddb56bedc5885126c7c1"
[[package]]
name = "tinyvec"
version = "1.6.0"
@ -1999,6 +2287,15 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "type-map"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d3364c5e96cb2ad1603037ab253ddd34d7fb72a58bdddf4b7350760fc69a46"
dependencies = [
"rustc-hash",
]
[[package]]
name = "typenum"
version = "1.15.0"
@ -2011,6 +2308,25 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
[[package]]
name = "unic-langid"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5"
dependencies = [
"unic-langid-impl",
]
[[package]]
name = "unic-langid-impl"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a4a8eeaf0494862c1404c95ec2f4c33a2acff5076f64314b465e3ddae1b934d"
dependencies = [
"serde",
"tinystr",
]
[[package]]
name = "unicode-bidi"
version = "0.3.8"
@ -2077,6 +2393,17 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
"same-file",
"winapi",
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.0"

@ -56,6 +56,10 @@ directories = "4.0.1"
console = "0.15.1"
tracing-error = "0.2.0"
fuzzy-matcher = "0.3.7"
i18n-embed = { version = "0.13.4", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.4"
rust-embed = "6.4.1"
unic-langid = "0.9.0"
[dependencies.config]
version = "0.13.2"

@ -0,0 +1,4 @@
fallback_language = "en-US"
[fluent]
assets_dir = "i18n"

@ -0,0 +1,21 @@
run-as-root = Running Amethyst as root is disallowed as it can lead to system breakage. Instead, Amethyst will prompt you when it needs superuser permissions.
following-packages = The following packages were found in the AUR:
aur-warning =
The AUR is a source of user-submitted packages/scripts and isn't always safe to use.
Please make sure to review the PKGBUILD of anything you download from the AUR before installing it, as some PKGBUILDs may potentially be malicious.
This warning can be toggled in the configuration file.
are-you-sure = Are you sure that you want to continue?
exiting = Exiting
uninstalling-packages = Uninstalling packages: {$packages}
system-upgrade = Performing system upgrade
removing-orphans = Removing orphaned packages
couldnt-find-packages = Couldn't find packages: {$packages} in repos or the AUR
searching-repos = Searching repos for {$query}
searching-aur = Searching AUR for {$query}
no-results = No results found
results = Results:
installed-repo-packages = Installed Repo Packages:
installed-aur-packages = Installed AUR Packages:
installed-packages = Installed Packages:
invalid-shell = Invalid shell, {$shell}
zsh-error = Zsh shell completions are currently unsupported due to a bug in the clap_completion crate

@ -0,0 +1,32 @@
use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DesktopLanguageRequester,
};
use lazy_static::lazy_static;
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "i18n"]
struct Localizations;
fn read() -> FluentLanguageLoader {
let loader: FluentLanguageLoader = fluent_language_loader!();
let req_langs = DesktopLanguageRequester::requested_languages();
i18n_embed::select(&loader, &Localizations, &req_langs).unwrap();
loader
}
lazy_static! {
pub static ref LANG_LOADER: FluentLanguageLoader = read();
}
#[macro_export]
macro_rules! fl {
($message_id:literal) => {{
i18n_embed_fl::fl!($crate::internal::i18n::LANG_LOADER, $message_id)
}};
($message_id:literal, $($args:expr),*) => {{
i18n_embed_fl::fl!($crate::internal::i18n::LANG_LOADER, $message_id, $($args), *)
}};
}

@ -18,6 +18,7 @@ pub mod structs;
#[macro_use]
pub mod utils;
pub mod alpm;
pub mod i18n;
mod sudoloop;
#[macro_export]

@ -31,7 +31,7 @@ use logging::init_logger;
async fn main() {
color_eyre::install().unwrap();
if unsafe { libc::geteuid() } == 0 {
crash!( AppExitCode::RunAsRoot, "Running amethyst as root is disallowed as it can lead to system breakage. Instead, amethyst will prompt you when it needs superuser permissions");
crash!(AppExitCode::RunAsRoot, "{}", fl!("run-as-root"));
}
let args: Args = Args::parse();
@ -64,11 +64,11 @@ async fn main() {
}
Operation::Query(query_args) => cmd_query(query_args).await,
Operation::Upgrade(upgrade_args) => {
tracing::info!("Performing system upgrade");
tracing::info!("{}", fl!("system-upgrade"));
operations::upgrade(upgrade_args, options).await;
}
Operation::Clean => {
tracing::info!("Removing orphaned packages");
tracing::info!("{}", fl!("removing-orphans"));
operations::clean(options).await;
}
Operation::GenComp(gen_args) => cmd_gencomp(&gen_args),
@ -102,8 +102,8 @@ async fn cmd_install(args: InstallArgs, options: Options) {
if !sorted.nf.is_empty() {
crash!(
AppExitCode::PacmanError,
"Couldn't find packages: {} in repos or the AUR",
sorted.nf.join(", ")
"{}",
fl!("couldnt-find-packages", packages = sorted.nf.join(", "))
);
}
if !sorted.repo.is_empty() {
@ -111,14 +111,13 @@ async fn cmd_install(args: InstallArgs, options: Options) {
}
if !sorted.aur.is_empty() {
if Config::read().base.aur_verification_prompt {
tracing::info!("The following packages were found in the AUR: ");
tracing::info!("{}", fl!("following-packages"));
get_logger().print_list(&sorted.aur, " ", 2);
newline!();
tracing::warn!("The AUR is a source of user-submitted packages/scripts and isn't always safe to use.\nPlease make sure to review the PKGBUILD of anything you download from the AUR before installing it, as some PKGBUILDs may potentially be malicious. This warning can be toggled in the configuration file.");
let cont = noconfirm
|| prompt!(default no, "Are you sure that you want to continue?");
tracing::warn!("{}", fl!("aur-warning"));
let cont = noconfirm || prompt!(default no, "{}", fl!("are-you-sure"));
if !cont {
tracing::info!("Exiting");
tracing::info!("{}", fl!("exiting"));
std::process::exit(AppExitCode::PacmanError as i32);
}
}
@ -132,7 +131,13 @@ async fn cmd_install(args: InstallArgs, options: Options) {
#[tracing::instrument(level = "trace")]
async fn cmd_remove(args: RemoveArgs, options: Options) {
let packages = args.packages;
tracing::info!("Uninstalling packages: {}", &packages.join(", "));
tracing::info!(
"{}",
fl!(
"uninstalling-packages",
packages = packages.join(", ").to_string()
)
);
operations::uninstall(packages, options).await;
}
@ -144,20 +149,20 @@ async fn cmd_search(args: InstallArgs, options: Options) {
let mut results = Vec::new();
if args.repo || both {
tracing::info!("Searching repos for {}", &query_string);
tracing::info!("{}", fl!("searching-repos", query = query_string.clone()));
let res = operations::search(&query_string, options).await;
results.extend(res);
}
if args.aur || both {
tracing::info!("Searching AUR for {}", &query_string);
tracing::info!("{}", fl!("searching-aur", query = query_string.clone()));
let res = operations::aur_search(&query_string, args.by, options).await;
results.extend(res);
}
if results.is_empty() {
tracing::info!("No results found");
tracing::info!("{}", fl!("no-results"));
} else {
tracing::info!("Results:");
tracing::info!("{}", fl!("results"));
results.sort_by(|a, b| {
let a_score = a.score(&query_string);
@ -182,7 +187,7 @@ async fn cmd_query(args: QueryArgs) {
let both = !args.aur && !args.repo && args.info.is_none();
if args.repo {
tracing::info!("Installed Repo Packages: ");
tracing::info!("{}", fl!("installed-repo-packages"));
PacmanQueryBuilder::native()
.color(PacmanColor::Always)
.query()
@ -191,7 +196,7 @@ async fn cmd_query(args: QueryArgs) {
}
if args.aur {
tracing::info!("Installed AUR Packages: ");
tracing::info!("{}", fl!("installed-aur-packages"));
PacmanQueryBuilder::foreign()
.color(PacmanColor::Always)
.query()
@ -200,7 +205,7 @@ async fn cmd_query(args: QueryArgs) {
}
if both {
tracing::info!("Installed Packages: ");
tracing::info!("{}", fl!("installed-packages"));
PacmanQueryBuilder::all()
.color(PacmanColor::Always)
.query()
@ -228,14 +233,11 @@ fn cmd_gencomp(args: &GenCompArgs) {
);
} else {
let shell: Shell = Shell::from_str(&args.shell).unwrap_or_else(|e| {
crash!(AppExitCode::Other, "Invalid shell, {}", e);
crash!(AppExitCode::Other, "{}", fl!("invalid-shell", shell = e));
});
if shell == Shell::Zsh {
crash!(
AppExitCode::Other,
"Zsh shell completions are currently unsupported due to a bug in the clap_completion crate"
);
crash!(AppExitCode::Other, "{}", fl!("zsh-error"));
};
shell.generate(

@ -4,6 +4,7 @@ use crate::builder::pacman::PacmanUninstallBuilder;
use crate::builder::rm::RmBuilder;
use crate::crash;
use crate::fl;
use crate::internal::exit_code::AppExitCode;
use crate::internal::utils::get_cache_dir;
@ -34,7 +35,7 @@ pub async fn clean(options: Options) {
let cont = noconfirm || prompt!(default no, "Continue?");
if !cont {
// If user doesn't want to continue, break
tracing::info!("Exiting");
tracing::info!("{}", fl!("exiting"));
std::process::exit(AppExitCode::PacmanError as i32);
}

Loading…
Cancel
Save