Skip to content

Commit

Permalink
Tag remaining strings as translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
ifl0w committed Sep 29, 2024
1 parent ecc2767 commit 0f2a1d5
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 42 deletions.
25 changes: 12 additions & 13 deletions src/historyMenuElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import St from 'gi://St';

import {gettext as __, ngettext} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';

Expand Down Expand Up @@ -232,7 +233,7 @@ class HistoryElement extends PopupMenu.PopupSubMenuMenuItem {
this.menu.addMenuItem(sourceItem);
}

const imageUrlItem = new PopupMenu.PopupMenuItem('Open Image in Browser');
const imageUrlItem = new PopupMenu.PopupMenuItem(__('Open Image in Browser'));
imageUrlItem.connect('activate', () => {
if (this.historyEntry.source.imageLinkUrl) {
Utils.execCheck(['xdg-open', this.historyEntry.source.imageLinkUrl]).catch(error => {
Expand All @@ -243,19 +244,19 @@ class HistoryElement extends PopupMenu.PopupSubMenuMenuItem {

this.menu.addMenuItem(imageUrlItem);
} else {
this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Unknown Source'));
this.menu.addMenuItem(new PopupMenu.PopupMenuItem(__('Unknown Source')));
}

this.menu.addMenuItem(new HistoryElementSubmenuSeparator());

this._setAsWallpaperItem = new PopupMenu.PopupMenuItem('Set As Wallpaper');
this._setAsWallpaperItem = new PopupMenu.PopupMenuItem(__('Set As Wallpaper'));
this._setAsWallpaperItem.connect('activate', () => {
this.emit('activate', null); // Fixme: not sure what the second parameter should be. null seems to work fine for now.
});

this.menu.addMenuItem(this._setAsWallpaperItem);

const copyToFavoritesLabelText = 'Save for Later';
const copyToFavoritesLabelText = __('Save for Later');
const copyToFavorites = new PopupMenu.PopupMenuItem(copyToFavoritesLabelText);
copyToFavorites.connect('activate', () => {
this._saveImage().catch(error => {
Expand All @@ -266,7 +267,7 @@ class HistoryElement extends PopupMenu.PopupSubMenuMenuItem {
this.menu.connect('open-state-changed', (_, open) => {
if (open && this._checkAlreadySaved()) {
copyToFavorites.sensitive = false;
copyToFavorites.label.set_text('Already Saved!');
copyToFavorites.label.set_text(__('Already Saved!'));
} else {
copyToFavorites.sensitive = true;
copyToFavorites.label.set_text(copyToFavoritesLabelText);
Expand All @@ -278,7 +279,7 @@ class HistoryElement extends PopupMenu.PopupSubMenuMenuItem {

// Static URLs can't block images (yet?)
if (this.historyEntry.adapter?.type !== Utils.SourceType.STATIC_URL) {
const blockImage = new PopupMenu.PopupMenuItem('Add to Blocklist');
const blockImage = new PopupMenu.PopupMenuItem(__('Add to Blocklist'));
blockImage.connect('activate', () => {
this._addToBlocklist();
});
Expand Down Expand Up @@ -502,13 +503,13 @@ class NewWallpaperElement extends PopupMenu.PopupBaseMenuItem {
});

const newWPLabel = new St.Label({
text: 'New Wallpaper',
text: __('New Wallpaper'),
style_class: 'rwg-new-label',
});
container.add_child(newWPLabel);

this._remainingLabel = new St.Label({
text: '1 minute remaining',
text: __('1 minute remaining'),
});
container.add_child(this._remainingLabel);

Expand All @@ -524,10 +525,8 @@ class NewWallpaperElement extends PopupMenu.PopupBaseMenuItem {
const minutes = remainingMinutes % 60;
const hours = Math.floor(remainingMinutes / 60);

let hoursText = hours.toString();
hoursText += hours === 1 ? ' hour' : ' hours';
let minText = minutes.toString();
minText += minutes === 1 ? ' minute' : ' minutes';
const hoursText = ngettext('%d hour', '%d hours', hours).format(hours);
const minText = ngettext('%d minute', '%d minutes', minutes).format(minutes);

if (hours >= 1)
this._remainingLabel.text = `... ${hoursText} and ${minText} remaining.`;
Expand Down Expand Up @@ -643,7 +642,7 @@ class HistorySection extends PopupMenu.PopupMenuSection {

this.removeAll();

const noHistory = new PopupMenu.PopupMenuItem('No Wallpaper History');
const noHistory = new PopupMenu.PopupMenuItem(__('No Wallpaper History'));
noHistory.sensitive = false;
this.addMenuItem(noHistory);
}
Expand Down
9 changes: 5 additions & 4 deletions src/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {notify} from 'resource:///org/gnome/shell/ui/main.js';
import {gettext as __} from 'resource:///org/gnome/shell/extensions/extension.js';

import {HistoryEntry} from './history.js';

Expand All @@ -12,9 +13,9 @@ class Notification {
* @param {HistoryEntry[]} historyEntries The history elements representing the new wallpapers
*/
static newWallpaper(historyEntries: HistoryEntry[]): void {
const infoString = `Source: ${historyEntries.map(h => `${h.source.source ?? 'Unknown Source'}`).join(', ')}`;
const message = `A new wallpaper was set!\n${infoString}`;
notify('New Wallpaper', message);
const infoString = `${__('Source')}: ${historyEntries.map(h => `${h.source.source ?? __('Unknown Source')}`).join(', ')}`;
const message = `${__('A new wallpaper was set!')}\n${infoString}`;
notify(__('New Wallpaper'), message);
}

/**
Expand All @@ -28,7 +29,7 @@ class Notification {
if (error instanceof Error)
errorMessage = error.message;

notify('RandomWallpaperGnome3: Wallpaper Download Failed!', errorMessage);
notify(`RandomWallpaperGnome3: ${__('Wallpaper Download Failed!')}`, errorMessage);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-29 22:11+0200\n"
"POT-Creation-Date: 2024-09-29 23:26+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/historyMenuElements.js:463
#, javascript-format
msgid "%d hour"
msgid_plural "%d hours"
msgstr[0] ""
msgstr[1] ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/historyMenuElements.js:464
#, javascript-format
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] ""
msgstr[1] ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/genericJson.ui:12
msgid "Disclaimer"
Expand All @@ -40,6 +55,7 @@ msgstr ""
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/reddit.ui:12
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/urlSource.ui:12
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:12
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:140
msgid "General"
msgstr ""

Expand Down Expand Up @@ -259,6 +275,11 @@ msgstr ""
msgid "Minimal Image Ratio"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/reddit.ui:96
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:103
msgid "SFW"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/reddit.ui:97
#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:104
msgid "Safe for work"
Expand Down Expand Up @@ -413,10 +434,26 @@ msgstr ""
msgid "Allowed Content Ratings"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:114
msgid "Sketchy"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:124
msgid "NSFW"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:125
msgid "Not safe for work"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:137
msgid "Categories"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:150
msgid "Anime"
msgstr ""

#: /home/wolfgang/Develop/RandomWallpaperGnome3/[email protected]/ui/wallhaven.ui:160
msgid "People"
msgstr ""
12 changes: 6 additions & 6 deletions src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {ExtensionPreferences, gettext as __} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

import * as Settings from './settings.js';
import * as Utils from './utils.js';
Expand Down Expand Up @@ -185,7 +185,7 @@ class RandomWallpaperSettings extends ExtensionPreferences {
const newWallpaperButtonLabel = newWallpaperButton.get_child() as Gtk.Label | null;
const origNewWallpaperText = newWallpaperButtonLabel?.get_label() ?? 'Request New Wallpaper';
newWallpaperButton.connect('activated', () => {
newWallpaperButtonLabel?.set_label('Loading ...');
newWallpaperButtonLabel?.set_label(__('Loading ...'));
newWallpaperButton.set_sensitive(false);

// The backend sets this back to false after fetching the image - listen for that event.
Expand Down Expand Up @@ -218,7 +218,7 @@ class RandomWallpaperSettings extends ExtensionPreferences {
}
builder.get_object('open_about')?.connect('activated', () => {
const about_window = new Adw.AboutWindow({
title: 'About',
title: __('About'),
transient_for: window,
modal: true,
licenseType: Gtk.License.MIT_X11,
Expand Down Expand Up @@ -268,10 +268,10 @@ class RandomWallpaperSettings extends ExtensionPreferences {

// https://stackoverflow.com/a/54487948
this._saveDialog = new Gtk.FileChooserNative({
title: 'Choose a Wallpaper Folder',
title: __('Choose a Wallpaper Folder'),
action: Gtk.FileChooserAction.SELECT_FOLDER,
accept_label: 'Open',
cancel_label: 'Cancel',
accept_label: __('Open'),
cancel_label: __('Cancel'),
transient_for: window,
modal: true,
});
Expand Down
10 changes: 5 additions & 5 deletions src/randomWallpaperMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';

import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import {Extension, gettext as __} from 'resource:///org/gnome/shell/extensions/extension.js';

import * as CustomElements from './historyMenuElements.js';
import * as Settings from './settings.js';
Expand Down Expand Up @@ -74,7 +74,7 @@ class RandomWallpaperMenu {
this._panelMenu.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

// Temporarily pause timer
const pauseTimerItem = new PopupMenu.PopupSwitchMenuItem('Pause Timer', false);
const pauseTimerItem = new PopupMenu.PopupSwitchMenuItem(__('Pause Timer'), false);

pauseTimerItem.connect('toggled', (_, state: boolean) => {
this._backendConnection.setBoolean('pause-timer', state);
Expand All @@ -98,15 +98,15 @@ class RandomWallpaperMenu {
this._panelMenu.menu.addMenuItem(pauseTimerItem);

// clear history button
const clearHistoryItem = new PopupMenu.PopupMenuItem('Clear History');
const clearHistoryItem = new PopupMenu.PopupMenuItem(__('Clear History'));
this._panelMenu.menu.addMenuItem(clearHistoryItem);

// open wallpaper folder button
const openFolder = new PopupMenu.PopupMenuItem('Open Wallpaper Folder');
const openFolder = new PopupMenu.PopupMenuItem(__('Open Wallpaper Folder'));
this._panelMenu.menu.addMenuItem(openFolder);

// settings button
const openSettings = new PopupMenu.PopupMenuItem('Settings');
const openSettings = new PopupMenu.PopupMenuItem(__('Settings'));
this._panelMenu.menu.addMenuItem(openSettings);

// add eventlistener
Expand Down
8 changes: 5 additions & 3 deletions src/ui/localFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Gtk from 'gi://Gtk';

import * as Settings from './../settings.js';

import {gettext as __} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

// FIXME: Generated static class code produces a no-unused-expressions rule error
/* eslint-disable no-unused-expressions */

Expand Down Expand Up @@ -57,10 +59,10 @@ class LocalFolderSettings extends Adw.PreferencesPage {

// https://stackoverflow.com/a/54487948
this._saveDialog = new Gtk.FileChooserNative({
title: 'Choose a Wallpaper Folder',
title: __('Choose a Wallpaper Folder'),
action: Gtk.FileChooserAction.SELECT_FOLDER,
accept_label: 'Open',
cancel_label: 'Cancel',
accept_label: __('Open'),
cancel_label: __('Cancel'),
transient_for: this.get_root() as Gtk.Window ?? undefined,
modal: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/ui/reddit.blp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ template $RedditSettings: Adw.PreferencesPage {
}

Adw.ActionRow {
title: "SFW";
title: _("SFW");
subtitle: _("Safe for work");

Switch allow_sfw {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/sourceConfigModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {UrlSourceSettings} from './urlSource.js';
import {WallhavenSettings} from './wallhaven.js';

// Imports for initializing the translation domain in templates
import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import {ExtensionPreferences, gettext as __} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import Gettext from 'gettext';

// FIXME: Generated static class code produces a no-unused-expressions rule error
Expand Down Expand Up @@ -71,7 +71,7 @@ class SourceConfigModal extends Adw.Window {
*/
constructor(parentWindow: Adw.Window, source?: SourceRow) {
super({
title: source ? 'Edit Source' : 'Add New Source',
title: source ? __('Edit Source') : __('Add New Source'),
transient_for: parentWindow,
modal: true,
defaultHeight: parentWindow.get_height() * 0.9,
Expand Down
12 changes: 6 additions & 6 deletions src/ui/wallhaven.blp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ template $WallhavenSettings: Adw.PreferencesPage {
title: _("Allowed Content Ratings");

Adw.ActionRow {
title: "SFW";
title: _("SFW");
subtitle: _("Safe for work");

Switch allow_sfw {
Expand All @@ -90,15 +90,15 @@ template $WallhavenSettings: Adw.PreferencesPage {
}

Adw.ActionRow {
title: "Sketchy";
title: _("Sketchy");

Switch allow_sketchy {
valign: center;
}
}

Adw.ActionRow {
title: "NSFW";
title: _("NSFW");
subtitle: _("Not safe for work");

Switch allow_nsfw {
Expand All @@ -111,23 +111,23 @@ template $WallhavenSettings: Adw.PreferencesPage {
title: _("Categories");

Adw.ActionRow {
title: "General";
title: _("General");

Switch category_general {
valign: center;
}
}

Adw.ActionRow {
title: "Anime";
title: _("Anime");

Switch category_anime {
valign: center;
}
}

Adw.ActionRow {
title: "People";
title: _("People");

Switch category_people {
valign: center;
Expand Down
Loading

0 comments on commit 0f2a1d5

Please sign in to comment.