Skip to content

Commit

Permalink
Add translations support
Browse files Browse the repository at this point in the history
  • Loading branch information
Elia Argentieri committed Oct 25, 2017
1 parent 6357903 commit 8bcd7f7
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Makefile
@@ -1,8 +1,8 @@
INSTALL_PATH = ~/.local/share/gnome-shell/extensions
INSTALL_NAME = nasa_apod@elinvention.ovh
FILES = extension.js icons LICENSE metadata.json prefs.js README.md schemas Settings.ui utils.js theme.css notifications.js
FILES = extension.js icons LICENSE metadata.json prefs.js README.md schemas Settings.ui utils.js theme.css notifications.js locale

.PHONY: install uninstall zip clean
.PHONY: install uninstall zip clean locale

install: schemas/gschemas.compiled
-mkdir -p $(INSTALL_PATH)/$(INSTALL_NAME)
Expand All @@ -23,3 +23,8 @@ schemas/gschemas.compiled: schemas/org.gnome.shell.extensions.nasa-apod.gschema.
clean:
-rm nasa_apod.zip
-rm schemas/gschemas.compiled

locale:
intltool-extract --type=gettext/glade Settings.ui
xgettext -k -k_ -kN_ -o locale/nasa_apod.pot Settings.ui.h extension.js prefs.js --from-code=UTF-8

37 changes: 21 additions & 16 deletions extension.js
Expand Up @@ -15,6 +15,9 @@ const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const Notifications = Me.imports.notifications;

const Gettext = imports.gettext.domain('nasa_apod');
const _ = Gettext.gettext;

const NasaApodURL = "https://api.nasa.gov/planetary/apod";
const IndicatorName = "NasaApodIndicator";
const TIMEOUT_SECONDS = 6 * 3600;
Expand Down Expand Up @@ -50,11 +53,11 @@ const NasaApodIndicator = new Lang.Class({
this.actor.visible = !this._settings.get_boolean('hide');
}));

this.refreshStatusItem = new PopupMenu.PopupMenuItem("No refresh scheduled");
this.showItem = new PopupMenu.PopupMenuItem("Show description");
this.wallpaperItem = new PopupMenu.PopupMenuItem("Set wallpaper");
this.refreshItem = new PopupMenu.PopupMenuItem("Refresh");
this.settingsItem = new PopupMenu.PopupMenuItem("Settings");
this.refreshStatusItem = new PopupMenu.PopupMenuItem(_("No refresh scheduled"));
this.showItem = new PopupMenu.PopupMenuItem(_("Show description"));
this.wallpaperItem = new PopupMenu.PopupMenuItem(_("Set wallpaper"));
this.refreshItem = new PopupMenu.PopupMenuItem(_("Refresh"));
this.settingsItem = new PopupMenu.PopupMenuItem(_("Settings"));
this.menu.addMenuItem(this.refreshStatusItem);
this.menu.addMenuItem(this.showItem);
this.menu.addMenuItem(this.wallpaperItem);
Expand Down Expand Up @@ -117,12 +120,12 @@ const NasaApodIndicator = new Lang.Class({
if (this._timeout)
Mainloop.source_remove(this._timeout);
if (seconds < 0) {
this.refreshStatusItem.label.set_text('No refresh scheduled');
this.refreshStatusItem.label.set_text(_('No refresh scheduled'));
} else {
this._timeout = Mainloop.timeout_add_seconds(seconds, Lang.bind(this, this._refresh));
let timezone = GLib.TimeZone.new_local();
let localTime = GLib.DateTime.new_now(timezone).add_seconds(seconds).format('%R');
this.refreshStatusItem.label.set_text('Next refresh: ' + localTime);
this.refreshStatusItem.label.set_text(_('Next refresh: {0}').replace("{0}", localTime));
Utils.log('Next check in ' + seconds + ' seconds @ local time ' + localTime);
}
},
Expand All @@ -142,7 +145,7 @@ const NasaApodIndicator = new Lang.Class({
if (this._updatePending)
return;
this._updatePending = true;
this.refreshStatusItem.label.set_text('Pending refresh');
this.refreshStatusItem.label.set_text(_('Pending refresh'));

let apiKey = this._settings.get_string('api-key');

Expand Down Expand Up @@ -173,17 +176,17 @@ const NasaApodIndicator = new Lang.Class({
if (this._settings.get_boolean('notify'))
this._showDescription();
else
Notifications.notifyError("Error downloading image", err);
Notifications.notifyError(_("Error downloading image"), err);
this._refreshDone();
}
} else if (message.status_code == 403) {
this._refreshDone(-1);
Notifications.notifyError("Invalid NASA API key (error 403)", "Check that your key is correct or use the default key.");
Notifications.notifyError(_("Invalid NASA API key (error 403)"), _("Check that your key is correct or use the default key."));
} else if (message.status_code == 429) {
Notifications.notifyError("Over rate limit (error 429)", "Get your API key at https://api.nasa.gov/ to have 1000 requests per hour just for you.");
Notifications.notifyError(_("Over rate limit (error 429)"), _("Get your API key at https://api.nasa.gov/ to have 1000 requests per hour just for you."));
this._refreshDone(RETRY_RATE_LIMIT_SECONDS);
} else {
Notifications.notifyError("Network error", message.status_code);
Notifications.notifyError(_("Network error"), message.status_code);
this._refreshDone();
}
}));
Expand Down Expand Up @@ -213,8 +216,8 @@ const NasaApodIndicator = new Lang.Class({

return url;
} else {
this.title = "Media type " + parsed['media_type'] + " not supported.";
this.explanation = "No picture for today 😞. Please visit NASA APOD website.";
this.title = _("Media type {0} not supported.").replace("{0}", parsed['media_type']);
this.explanation = _("No picture for today 😞. Please visit NASA APOD website.");
this.filename = "";
this.copyright = "";
let error = new Error(this.title);
Expand Down Expand Up @@ -265,7 +268,7 @@ const NasaApodIndicator = new Lang.Class({
if(total_size) {
let fraction = bytes_so_far / total_size;
let percent = Math.floor(fraction * 100);
this.refreshStatusItem.label.set_text("Download " + percent + "% done");
this.refreshStatusItem.label.set_text(_("Download {0} done").replace("{0}", percent + '%'));
}
fstream.write(chunk.get_data(), null, chunk.length);
}));
Expand All @@ -281,7 +284,7 @@ const NasaApodIndicator = new Lang.Class({
if (this._settings.get_boolean('notify'))
this._showDescription();
} else {
Notifications.notifyError("Couldn't fetch image from " + url);
Notifications.notifyError(_("Couldn't fetch image from {0}").replace("{0}", url));
file.delete(null);
}
}));
Expand All @@ -298,6 +301,7 @@ const NasaApodIndicator = new Lang.Class({
function init(extensionMeta) {
let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(extensionMeta.path + "/icons");
Utils.initTranslations("nasa_apod");
}

function enable() {
Expand All @@ -309,3 +313,4 @@ function disable() {
nasaApodIndicator.stop();
nasaApodIndicator.destroy();
}

Binary file added locale/it/LC_MESSAGES/nasa_apod.mo
Binary file not shown.
204 changes: 204 additions & 0 deletions locale/it/LC_MESSAGES/nasa_apod.po
@@ -0,0 +1,204 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-10-25 23:51+0200\n"
"PO-Revision-Date: 2017-10-25 23:51+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: it_IT\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.4\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: Settings.ui.h:1
msgid "label"
msgstr ""

#: Settings.ui.h:2
msgid "Hide the indicator"
msgstr "Nascondi l'indicatore"

#: Settings.ui.h:3
msgid "Send a notification with explanation when a new image is downloaded."
msgstr ""
"Invia una notifica con la spiegazione quando viene scaricata una nuova "
"immagine."

#: Settings.ui.h:4
msgid "Notifications"
msgstr "Notifiche"

#: Settings.ui.h:5
msgid "Use transient notifications (auto dismiss)"
msgstr "Usa notifiche transitorie (auto cancellazione)"

#: Settings.ui.h:6
msgid "Set background image:"
msgstr "Imposta l'immagine di sfondo:"

#: Settings.ui.h:7
msgid "None"
msgstr "Nessuna"

#: Settings.ui.h:8
msgid "Centered"
msgstr "Centrata"

#: Settings.ui.h:9
msgid "Scaled"
msgstr "Scalata"

#: Settings.ui.h:10
msgid "Spanned"
msgstr ""

#: Settings.ui.h:11
msgid "Stretched"
msgstr ""

#: Settings.ui.h:12
msgid "Wallpaper"
msgstr ""

#: Settings.ui.h:13
msgid "Zoom"
msgstr "Ingrandita"

#: Settings.ui.h:14
msgid "Set lock screen image:"
msgstr "Imposta l'immagine del blocco schermo:"

#: Settings.ui.h:15
msgid "Download folder:"
msgstr "Cartella di download:"

#: Settings.ui.h:16
msgid "NASA APOD pictures folder"
msgstr "Cartella delle immagini di NASA APOD"

#: Settings.ui.h:17
msgid "Custom NASA APOD API key:"
msgstr "Chiave API di NASA APOD personale:"

#: Settings.ui.h:18 extension.js:60
msgid "Settings"
msgstr "Impostazioni"

#: Settings.ui.h:19
msgid "Cache"
msgstr ""

#: Settings.ui.h:20
msgid "version: "
msgstr "versione: "

#: Settings.ui.h:21
msgid "Change your wallpaper daily to the NASA's astronomy picture of the day"
msgstr ""
"Cambia il tuo sfondo quotidianamente all'immagine astronomica del giorno "
"della NASA"

#: Settings.ui.h:22
msgid ""
"Maintained by:\n"
"Elia Argentieri (<a href=\"mailto:elia.argentieri@openmailbox.org\">elia."
"argentieri@openmailbox.org</a>)"
msgstr ""
"Mantenuta da:\n"
"Elia Argentieri (<a href=\"mailto:elia.argentieri@openmailbox.org\">elia."
"argentieri@openmailbox.org</a>)"

#: Settings.ui.h:24
msgid "Extension's GitHub Webpage"
msgstr "Pagina GitHub dell'estensione"

#: Settings.ui.h:25
msgid "Changelog"
msgstr "Registro dei Cambiamenti"

#: Settings.ui.h:26
msgid ""
"<span size=\"small\">This program comes with ABSOLUTELY NO WARRANTY.\n"
"See the <a href=\"https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"
"\">GNU General Public License, version 3 or later</a> for details.</span>"
msgstr ""

#: Settings.ui.h:28
msgid "About"
msgstr "Informazioni"

#: extension.js:56 extension.js:123
msgid "No refresh scheduled"
msgstr "Aggiornamento non stabilito"

#: extension.js:57
msgid "Show description"
msgstr "Mostra descrizione"

#: extension.js:58
msgid "Set wallpaper"
msgstr "Imposta sfondo"

#: extension.js:59
msgid "Refresh"
msgstr "Aggiorna"

#: extension.js:128
msgid "Next refresh: {0}"
msgstr "Prossimo aggiornamento: {0}"

#: extension.js:148
msgid "Pending refresh"
msgstr "Aggiornamento in corso"

#: extension.js:179
msgid "Error downloading image"
msgstr "Errore scaricamento immagine"

#: extension.js:184
msgid "Invalid NASA API key (error 403)"
msgstr "Chiave API NASA non valida (errore 403)"

#: extension.js:184
msgid "Check that your key is correct or use the default key."
msgstr "Controlla che la tua chiave sia corretta oppure usa quella di default."

#: extension.js:186
msgid "Over rate limit (error 429)"
msgstr "Superato il limite di richieste (errore 429)"

#: extension.js:186
msgid ""
"Get your API key at https://api.nasa.gov/ to have 1000 requests per hour "
"just for you."
msgstr ""
"Ottieni la tua chiave API dal sito https://api.nasa.gov/ per avere 1000 "
"richieste per ora solo per te."

#: extension.js:189
msgid "Network error"
msgstr "Errore di rete"

#: extension.js:219
msgid "Media type {0} not supported."
msgstr "Tipo multimediale {0} non supportato."

#: extension.js:220
msgid "No picture for today 😞. Please visit NASA APOD website."
msgstr "Oggi niente immagine 😞. Visita il sito web di NASA APOD."

#: extension.js:271
msgid "Download {0} done"
msgstr "Scaricamento {0} completato"

#: extension.js:287
msgid "Couldn't fetch image from {0}"
msgstr "Impossibile scaricare immagine da {0}"

0 comments on commit 8bcd7f7

Please sign in to comment.