Skip to content

Commit 77a48ca

Browse files
authored
Add support for translations (#469)
* 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.
1 parent 5f774e0 commit 77a48ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2104
-474
lines changed

Cargo.lock

+344-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

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

135137
You can also help by doing different things:
136138
- 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/)

czkawka_core/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ serde = "1.0.130"
5050
bincode = "1.3.3"
5151
serde_json = "1.0.72"
5252

53+
# Language
54+
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
55+
i18n-embed-fl = "0.6"
56+
rust-embed = "6.2.0"
57+
once_cell = "1.8.0"
5358

5459
[features]
5560
default = []

czkawka_core/i18n.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# (Required) The language identifier of the language used in the
2+
# source code for gettext system, and the primary fallback language
3+
# (for which all strings must be present) when using the fluent
4+
# system.
5+
fallback_language = "en"
6+
7+
# Use the fluent localization system.
8+
[fluent]
9+
# (Required) The path to the assets directory.
10+
# The paths inside the assets directory should be structured like so:
11+
# `assets_dir/{language}/{domain}.ftl`
12+
assets_dir = "../i18n"
13+

czkawka_core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ pub mod common_extensions;
1818
pub mod common_items;
1919
pub mod common_messages;
2020
pub mod common_traits;
21+
pub mod localizer;
2122

2223
pub const CZKAWKA_VERSION: &str = env!("CARGO_PKG_VERSION");

czkawka_core/src/localizer.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use i18n_embed::{
2+
fluent::{fluent_language_loader, FluentLanguageLoader},
3+
DefaultLocalizer, LanguageLoader, Localizer,
4+
};
5+
use once_cell::sync::Lazy;
6+
use rust_embed::RustEmbed;
7+
8+
#[derive(RustEmbed)]
9+
#[folder = "../i18n/"]
10+
struct Localizations;
11+
12+
pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
13+
let loader: FluentLanguageLoader = fluent_language_loader!();
14+
15+
loader.load_fallback_language(&Localizations).expect("Error while loading fallback language");
16+
17+
loader
18+
});
19+
20+
#[macro_export]
21+
macro_rules! fl {
22+
($message_id:literal) => {{
23+
i18n_embed_fl::fl!($crate::localizer::LANGUAGE_LOADER, $message_id)
24+
}};
25+
26+
($message_id:literal, $($args:expr),*) => {{
27+
i18n_embed_fl::fl!($crate::localizer::LANGUAGE_LOADER, $message_id, $($args), *)
28+
}};
29+
}
30+
31+
// Get the `Localizer` to be used for localizing this library.
32+
pub fn localizer() -> Box<dyn Localizer> {
33+
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
34+
}

czkawka_core/src/similar_images.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::common_directory::Directories;
2323
use crate::common_items::ExcludedItems;
2424
use crate::common_messages::Messages;
2525
use crate::common_traits::{DebugPrint, PrintResults, SaveResults};
26+
use crate::fl;
2627

2728
// TODO check for better values
2829
pub const SIMILAR_VALUES: [[u32; 6]; 4] = [
@@ -905,35 +906,35 @@ pub fn get_string_from_similarity(similarity: &Similarity, hash_size: u8) -> Str
905906
#[cfg(debug_assertions)]
906907
{
907908
if *h <= SIMILAR_VALUES[index_preset][0] {
908-
format!("Very High {}", *h)
909+
format!("{} {}", fl!("core_similarity_very_high"), *h)
909910
} else if *h <= SIMILAR_VALUES[index_preset][1] {
910-
format!("High {}", *h)
911+
format!("{} {}", fl!("core_similarity_high"), *h)
911912
} else if *h <= SIMILAR_VALUES[index_preset][2] {
912-
format!("Medium {}", *h)
913+
format!("{} {}", fl!("core_similarity_medium"), *h)
913914
} else if *h <= SIMILAR_VALUES[index_preset][3] {
914-
format!("Small {}", *h)
915+
format!("{} {}", fl!("core_similarity_small"), *h)
915916
} else if *h <= SIMILAR_VALUES[index_preset][4] {
916-
format!("Very Small {}", *h)
917+
format!("{} {}", fl!("core_similarity_very_small"), *h)
917918
} else if *h <= SIMILAR_VALUES[index_preset][5] {
918-
format!("Minimal {}", *h)
919+
format!("{} {}", fl!("core_similarity_minimal"), *h)
919920
} else {
920921
panic!();
921922
}
922923
}
923924
#[cfg(not(debug_assertions))]
924925
{
925926
if *h <= SIMILAR_VALUES[index_preset][0] {
926-
format!("Very High")
927+
fl!("core_similarity_very_high")
927928
} else if *h <= SIMILAR_VALUES[index_preset][1] {
928-
format!("High")
929+
fl!("core_similarity_high")
929930
} else if *h <= SIMILAR_VALUES[index_preset][2] {
930-
format!("Medium")
931+
fl!("core_similarity_medium")
931932
} else if *h <= SIMILAR_VALUES[index_preset][3] {
932-
format!("Small")
933+
fl!("core_similarity_small")
933934
} else if *h <= SIMILAR_VALUES[index_preset][4] {
934-
format!("Very Small")
935+
fl!("core_similarity_very_small")
935936
} else if *h <= SIMILAR_VALUES[index_preset][5] {
936-
format!("Minimal")
937+
fl!("core_similarity_minimal")
937938
} else {
938939
panic!();
939940
}

czkawka_gui/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ trash = "1.3.0"
4343
# For moving files(why std::fs doesn't have such features)
4444
fs_extra = "1.2.0"
4545

46+
# Language
47+
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
48+
i18n-embed-fl = "0.6"
49+
rust-embed = "6.2.0"
50+
once_cell = "1.8.0"
51+
4652
[target.'cfg(windows)'.dependencies]
4753
winapi = { version = "0.3.9", features = ["combaseapi", "objbase", "shobjidl_core", "windef", "winerror", "wtypesbase", "winuser"] }
4854

czkawka_gui/i18n.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# (Required) The language identifier of the language used in the
2+
# source code for gettext system, and the primary fallback language
3+
# (for which all strings must be present) when using the fluent
4+
# system.
5+
fallback_language = "en"
6+
7+
# Use the fluent localization system.
8+
[fluent]
9+
# (Required) The path to the assets directory.
10+
# The paths inside the assets directory should be structured like so:
11+
# `assets_dir/{language}/{domain}.ftl`
12+
assets_dir = "../i18n"
13+

0 commit comments

Comments
 (0)