Skip to content

Commit

Permalink
Add support for translations (#469)
Browse files Browse the repository at this point in the history
* Reformat code with idea tool

* Pierwsza działająca wersja tłumaczeń

* Działa? I dobrze, bo ma działać

* Ćma szła i się potkła

* Ściął śmiałek źółty rząd pąków.
  • Loading branch information
qarmin committed Dec 11, 2021
1 parent 5f774e0 commit 77a48ca
Show file tree
Hide file tree
Showing 44 changed files with 2,104 additions and 474 deletions.
354 changes: 344 additions & 10 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -11,6 +11,7 @@
- CLI frontend - for easy automation
- GUI frontend - uses modern GTK 3 and looks similar to FSlint
- No spying - Czkawka does not have access to the Internet, nor does it collect any user information or statistics
- Multilingual - app support multiple languages
- Multiple tools to use:
- Duplicates - Finds duplicates based on file name, size or hash
- Empty Folders - Finds empty folders with the help of an advanced algorithm
Expand Down Expand Up @@ -131,6 +132,7 @@ You can help by creating:
- Pull Requests - implementing a new feature yourself or fixing bugs.
If the change is bigger, then it's a good idea to open a new issue to discuss changes.
- Documentation - There is an [instruction](instructions/Instruction.md) which you can improve.
- Translations - Instruction how to translate files is available [here](instructions/Translations.md)

You can also help by doing different things:
- Creating text articles - [LinuxUprising](https://www.linuxuprising.com/2021/03/find-and-remove-duplicate-files-similar.html) or [Ubunlog](https://ubunlog.com/en/czkawka-finds-and-removes-empty-and-broken-duplicate-files/)
Expand Down
5 changes: 5 additions & 0 deletions czkawka_core/Cargo.toml
Expand Up @@ -50,6 +50,11 @@ serde = "1.0.130"
bincode = "1.3.3"
serde_json = "1.0.72"

# Language
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6"
rust-embed = "6.2.0"
once_cell = "1.8.0"

[features]
default = []
Expand Down
13 changes: 13 additions & 0 deletions czkawka_core/i18n.toml
@@ -0,0 +1,13 @@
# (Required) The language identifier of the language used in the
# source code for gettext system, and the primary fallback language
# (for which all strings must be present) when using the fluent
# system.
fallback_language = "en"

# Use the fluent localization system.
[fluent]
# (Required) The path to the assets directory.
# The paths inside the assets directory should be structured like so:
# `assets_dir/{language}/{domain}.ftl`
assets_dir = "../i18n"

1 change: 1 addition & 0 deletions czkawka_core/src/lib.rs
Expand Up @@ -18,5 +18,6 @@ pub mod common_extensions;
pub mod common_items;
pub mod common_messages;
pub mod common_traits;
pub mod localizer;

pub const CZKAWKA_VERSION: &str = env!("CARGO_PKG_VERSION");
34 changes: 34 additions & 0 deletions czkawka_core/src/localizer.rs
@@ -0,0 +1,34 @@
use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DefaultLocalizer, LanguageLoader, Localizer,
};
use once_cell::sync::Lazy;
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "../i18n/"]
struct Localizations;

pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
let loader: FluentLanguageLoader = fluent_language_loader!();

loader.load_fallback_language(&Localizations).expect("Error while loading fallback language");

loader
});

#[macro_export]
macro_rules! fl {
($message_id:literal) => {{
i18n_embed_fl::fl!($crate::localizer::LANGUAGE_LOADER, $message_id)
}};

($message_id:literal, $($args:expr),*) => {{
i18n_embed_fl::fl!($crate::localizer::LANGUAGE_LOADER, $message_id, $($args), *)
}};
}

// Get the `Localizer` to be used for localizing this library.
pub fn localizer() -> Box<dyn Localizer> {
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
}
25 changes: 13 additions & 12 deletions czkawka_core/src/similar_images.rs
Expand Up @@ -23,6 +23,7 @@ use crate::common_directory::Directories;
use crate::common_items::ExcludedItems;
use crate::common_messages::Messages;
use crate::common_traits::{DebugPrint, PrintResults, SaveResults};
use crate::fl;

// TODO check for better values
pub const SIMILAR_VALUES: [[u32; 6]; 4] = [
Expand Down Expand Up @@ -905,35 +906,35 @@ pub fn get_string_from_similarity(similarity: &Similarity, hash_size: u8) -> Str
#[cfg(debug_assertions)]
{
if *h <= SIMILAR_VALUES[index_preset][0] {
format!("Very High {}", *h)
format!("{} {}", fl!("core_similarity_very_high"), *h)
} else if *h <= SIMILAR_VALUES[index_preset][1] {
format!("High {}", *h)
format!("{} {}", fl!("core_similarity_high"), *h)
} else if *h <= SIMILAR_VALUES[index_preset][2] {
format!("Medium {}", *h)
format!("{} {}", fl!("core_similarity_medium"), *h)
} else if *h <= SIMILAR_VALUES[index_preset][3] {
format!("Small {}", *h)
format!("{} {}", fl!("core_similarity_small"), *h)
} else if *h <= SIMILAR_VALUES[index_preset][4] {
format!("Very Small {}", *h)
format!("{} {}", fl!("core_similarity_very_small"), *h)
} else if *h <= SIMILAR_VALUES[index_preset][5] {
format!("Minimal {}", *h)
format!("{} {}", fl!("core_similarity_minimal"), *h)
} else {
panic!();
}
}
#[cfg(not(debug_assertions))]
{
if *h <= SIMILAR_VALUES[index_preset][0] {
format!("Very High")
fl!("core_similarity_very_high")
} else if *h <= SIMILAR_VALUES[index_preset][1] {
format!("High")
fl!("core_similarity_high")
} else if *h <= SIMILAR_VALUES[index_preset][2] {
format!("Medium")
fl!("core_similarity_medium")
} else if *h <= SIMILAR_VALUES[index_preset][3] {
format!("Small")
fl!("core_similarity_small")
} else if *h <= SIMILAR_VALUES[index_preset][4] {
format!("Very Small")
fl!("core_similarity_very_small")
} else if *h <= SIMILAR_VALUES[index_preset][5] {
format!("Minimal")
fl!("core_similarity_minimal")
} else {
panic!();
}
Expand Down
6 changes: 6 additions & 0 deletions czkawka_gui/Cargo.toml
Expand Up @@ -43,6 +43,12 @@ trash = "1.3.0"
# For moving files(why std::fs doesn't have such features)
fs_extra = "1.2.0"

# Language
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6"
rust-embed = "6.2.0"
once_cell = "1.8.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["combaseapi", "objbase", "shobjidl_core", "windef", "winerror", "wtypesbase", "winuser"] }

Expand Down
13 changes: 13 additions & 0 deletions czkawka_gui/i18n.toml
@@ -0,0 +1,13 @@
# (Required) The language identifier of the language used in the
# source code for gettext system, and the primary fallback language
# (for which all strings must be present) when using the fluent
# system.
fallback_language = "en"

# Use the fluent localization system.
[fluent]
# (Required) The path to the assets directory.
# The paths inside the assets directory should be structured like so:
# `assets_dir/{language}/{domain}.ftl`
assets_dir = "../i18n"

0 comments on commit 77a48ca

Please sign in to comment.