Skip to content

Commit

Permalink
Update translations.
Browse files Browse the repository at this point in the history
  • Loading branch information
luleyleo committed Nov 15, 2024
1 parent 61321a0 commit daeb9dd
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 221 deletions.
46 changes: 46 additions & 0 deletions gnome/src/i18n.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use gettextrs::{gettext, ngettext};
use std::path::PathBuf;

pub fn setup_gettext() {
let mut text_domain = gettextrs::TextDomain::new(crate::APP_ID);

if cfg!(debug_assertions) {
let assets_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("assets");
text_domain = text_domain.push(assets_dir);
}

if let Err(error) = text_domain.init() {
println!("Failed to setup gettext: {}", error);
};
}

/// Like `gettext`, but replaces named variables with the given dictionary.
///
/// The expected format to replace is `{name}`, where `name` is the first string
/// in the dictionary entry tuple.
pub fn gettext_f(msgid: &str, args: &[(&str, &str)]) -> String {
let s = gettext(msgid);
freplace(s, args)
}

/// Like `ngettext`, but replaces named variables with the given dictionary.
///
/// The expected format to replace is `{name}`, where `name` is the first string
/// in the dictionary entry tuple.
#[allow(unused)]
pub fn ngettext_f(msgid: &str, msgid_plural: &str, n: u32, args: &[(&str, &str)]) -> String {
let s = ngettext(msgid, msgid_plural, n);
freplace(s, args)
}

fn freplace(s: String, args: &[(&str, &str)]) -> String {
let mut s = s;

for (k, v) in args {
s = s.replace(&format!("{{{k}}}"), v);
}

s
}
19 changes: 2 additions & 17 deletions gnome/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
use adw::prelude::*;
use gtk::gio::ApplicationFlags;
use std::path::PathBuf;

mod app;
mod config;
mod i18n;
mod search;
mod ui;

const APP_ID: &str = env!("APP_ID");

fn setup_gettext() {
let mut text_domain = gettextrs::TextDomain::new(APP_ID);

if cfg!(debug_assertions) {
let assets_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("assets");
text_domain = text_domain.push(assets_dir);
}

if let Err(error) = text_domain.init() {
println!("Failed to setup gettext: {}", error);
};
}

fn main() {
setup_gettext();
i18n::setup_gettext();

let application = adw::Application::builder()
.application_id(APP_ID)
Expand Down
19 changes: 14 additions & 5 deletions gnome/src/ui/search_window/imp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{config::Config, search::SearchModel, ui::ErrorWindow};
use crate::{config::Config, i18n::gettext_f, search::SearchModel, ui::ErrorWindow};
use adw::subclass::prelude::*;
use clapgrep_core::{SearchEngine, SearchFlags, SearchMessage, SearchParameters};
use gettextrs::gettext;
use glib::subclass::InitializingObject;
use gtk::{
gio::{self, Cancellable},
Expand Down Expand Up @@ -126,7 +127,7 @@ impl SearchWindow {
let initial_folder = gio::File::for_path(self.search_path.borrow().as_path());

FileDialog::builder()
.title("Choose Search Path")
.title(gettext("Choose Search Path"))
.initial_folder(&initial_folder)
.modal(true)
.build()
Expand Down Expand Up @@ -250,7 +251,13 @@ impl SearchWindow {
fn update_search_progress(&self) {
let files = self.searched_files.get();
let matches = self.number_of_matches.get();
let message = format!("Searched {files} files and found {matches} matches");
let message = gettext_f(
"Searched {files} files and found {matches} matches",
&[
("files", &files.to_string()),
("matches", &matches.to_string()),
],
);

*self.search_progress_notification.borrow_mut() = message;
self.obj().notify("search_progress_notification");
Expand Down Expand Up @@ -342,8 +349,10 @@ impl ObjectImpl for SearchWindow {

obj.connect_number_of_errors_notify(|obj| {
let errors = obj.number_of_errors();
*obj.imp().search_errors_notification.borrow_mut() =
format!("Encountered {errors} errors during search");
*obj.imp().search_errors_notification.borrow_mut() = gettext_f(
"Encountered {errors} errors during search",
&[("errors", &errors.to_string())],
);
obj.notify("search_errors_notification")
});

Expand Down
10 changes: 7 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@ setup-flatpak-repos:
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
flatpak install --or-update --user --noninteractive flathub org.gnome.Platform//47 org.gnome.Sdk//47 org.freedesktop.Sdk.Extension.rust-stable//24.08

gettext *args:
gettext:
xgettext \
--from-code=UTF-8 \
--add-comments \
--keyword=_ \
--keyword=C_:1c,2 \
--language=C \
--output=po/messages.pot \
--files-from=po/POTFILES \
{{args}}
--files-from=po/POTFILES
xtr \
--omit-header \
--keywords gettext \
--keywords gettext_f \
gnome/src/main.rs >> po/messages.pot
cat po/LINGUAS | while read lang; do \
msgmerge -N -U po/$lang.po po/messages.pot; \
rm -f po/$lang.po~; \
Expand Down
6 changes: 3 additions & 3 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gnome/src/search_window/search_window.blp
gnome/src/error_window/error_window.blp
gnome/src/shortcuts.blp
gnome/src/ui/search_window/search_window.blp
gnome/src/ui/error_window/error_window.blp
gnome/src/ui/shortcuts/shortcuts.blp
97 changes: 58 additions & 39 deletions po/cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-02 14:53+0200\n"
"POT-Creation-Date: 2024-11-15 11:57+0100\n"
"PO-Revision-Date: 2024-09-26 23:16+0200\n"
"Last-Translator: Amerey <[email protected]>\n"
"Language-Team: \n"
Expand All @@ -18,114 +18,133 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.4\n"

#: gnome/src/search_window/search_window.blp:5
#: gnome/src/ui/search_window/search_window.blp:5
msgid "Clapgrep"
msgstr "Clapgrep"

#: gnome/src/search_window/search_window.blp:9
#: gnome/src/ui/search_window/search_window.blp:18
msgid "Search Settings"
msgstr "Nastavení vyhledávání"

#: gnome/src/search_window/search_window.blp:28
#: gnome/src/ui/search_window/search_window.blp:41
msgid "Search Pattern"
msgstr "Vzor vyhledávání"

#: gnome/src/search_window/search_window.blp:33 gnome/src/shortcuts.blp:28
#: gnome/src/ui/search_window/search_window.blp:47
#: gnome/src/ui/shortcuts/shortcuts.blp:28
msgid "Start Search"
msgstr "Spustit vyhledávání"

#: gnome/src/search_window/search_window.blp:41
#: gnome/src/ui/search_window/search_window.blp:55
msgid "Search Path"
msgstr "Cesta vyhledávání"

#: gnome/src/search_window/search_window.blp:59
#: gnome/src/ui/search_window/search_window.blp:73
msgid "Search Options"
msgstr "Možnosti vyhledávání"

#: gnome/src/search_window/search_window.blp:62
#: gnome/src/ui/search_window/search_window.blp:76
msgid "Case Sensitive"
msgstr "Rozlišovat malá a velká písmena"

#: gnome/src/search_window/search_window.blp:67
#: gnome/src/ui/search_window/search_window.blp:81
msgid "Disable Regex"
msgstr "Zakázat Regex"

#: gnome/src/search_window/search_window.blp:72
#: gnome/src/ui/search_window/search_window.blp:86
msgid "Include Hidden"
msgstr "Zahrnout skryté"

#: gnome/src/search_window/search_window.blp:77
#: gnome/src/ui/search_window/search_window.blp:91
msgid "Include Ignored"
msgstr "Zahrnout ignorované"

#: gnome/src/search_window/search_window.blp:83
#: gnome/src/ui/search_window/search_window.blp:97
msgid "Extra File Formats"
msgstr "Extra formáty souborů"

#: gnome/src/search_window/search_window.blp:86
#: gnome/src/ui/search_window/search_window.blp:100
msgid "PDF files"
msgstr "PDF soubory"

#: gnome/src/search_window/search_window.blp:91
#: gnome/src/ui/search_window/search_window.blp:105
msgid "Office files"
msgstr "Soubory Office"

#: gnome/src/search_window/search_window.blp:97
msgid "Current Search"
msgstr "Aktuální vyhledávání"
#: gnome/src/ui/search_window/search_window.blp:116
msgid "Search Results"
msgstr "Výsledky vyhledávání"

#: gnome/src/ui/search_window/search_window.blp:136
msgid "No Search Yet"
msgstr ""

#: gnome/src/search_window/search_window.blp:102
msgid "Searched Files"
msgstr "Hledané soubory"
#: gnome/src/ui/search_window/search_window.blp:137
msgid "Try to start a search"
msgstr ""

#: gnome/src/search_window/search_window.blp:111
msgid "Number of Matches"
msgstr "Počet shod"
#: gnome/src/ui/search_window/search_window.blp:146
msgid "No Results"
msgstr ""

#: gnome/src/search_window/search_window.blp:120
msgid "Errors Encountered"
msgstr "Zjištěné chyby"
#: gnome/src/ui/search_window/search_window.blp:152
msgid ""
"You might want to try changing your search pattern, activating document "
"search, or changing to a different directory"
msgstr ""

#: gnome/src/search_window/search_window.blp:133
#: gnome/src/ui/search_window/search_window.blp:182
msgid "Cancel Search"
msgstr "Zrušit vyhledávání"

#: gnome/src/search_window/search_window.blp:148
msgid "Search Results"
msgstr "Výsledky vyhledávání"
#: gnome/src/ui/search_window/search_window.blp:201
msgid "Show Errors"
msgstr ""

#: gnome/src/search_window/search_window.blp:238
#: gnome/src/ui/search_window/search_window.blp:284
msgid "Keyboard Shortcuts"
msgstr "Klávesové zkratky"

#: gnome/src/search_window/search_window.blp:243
#: gnome/src/ui/search_window/search_window.blp:289
msgid "About Clapgrep"
msgstr "O Clapgrep"

#: gnome/src/error_window/error_window.blp:7
#: gnome/src/ui/error_window/error_window.blp:7
msgid "Search Errors"
msgstr "Chyby vyhledávání"

#: gnome/src/shortcuts.blp:5
#: gnome/src/ui/shortcuts/shortcuts.blp:5
msgid "Clapgrep Shortcuts"
msgstr "Zkratky Clapgrep"

#: gnome/src/shortcuts.blp:9
#: gnome/src/ui/shortcuts/shortcuts.blp:9
msgid "General"
msgstr "Obecné"

#: gnome/src/shortcuts.blp:12
#: gnome/src/ui/shortcuts/shortcuts.blp:12
msgid "Quit"
msgstr "Konec"

#: gnome/src/shortcuts.blp:18
#: gnome/src/ui/shortcuts/shortcuts.blp:18
msgid "Shortcuts"
msgstr "Zkratky"

#: gnome/src/shortcuts.blp:25
#: gnome/src/ui/shortcuts/shortcuts.blp:25
msgid "Control Search"
msgstr "Ovládání vyhledávání"

#: gnome/src/shortcuts.blp:34
#: gnome/src/ui/shortcuts/shortcuts.blp:34
msgid "Stop Search"
msgstr "Zastavit vyhledávání"

#~ msgid "Current Search"
#~ msgstr "Aktuální vyhledávání"

#~ msgid "Searched Files"
#~ msgstr "Hledané soubory"

#~ msgid "Number of Matches"
#~ msgstr "Počet shod"

#~ msgid "Errors Encountered"
#~ msgstr "Zjištěné chyby"
Loading

0 comments on commit daeb9dd

Please sign in to comment.