From d33d9f932ad79d36b1a72978a0531af005e69b3a Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Thu, 3 Nov 2022 12:48:12 +0100 Subject: [PATCH] French l10n of app --- app.py | 38 ++++++++++------ locales/en/LC_MESSAGES/template.mo | Bin 0 -> 334 bytes locales/en/LC_MESSAGES/template.pot | 66 ++++++++++++++++++++++++++++ locales/fr/LC_MESSAGES/template.mo | Bin 0 -> 1180 bytes locales/fr/LC_MESSAGES/template.pot | 64 +++++++++++++++++++++++++++ locales/gen_mo.sh | 5 +++ locales/messages.pot | 17 +++++++ locales/template.pot | 57 ++++++++++++++++++++++++ static/script.js | 4 +- templates/main.html | 6 +-- 10 files changed, 239 insertions(+), 18 deletions(-) create mode 100644 locales/en/LC_MESSAGES/template.mo create mode 100644 locales/en/LC_MESSAGES/template.pot create mode 100644 locales/fr/LC_MESSAGES/template.mo create mode 100644 locales/fr/LC_MESSAGES/template.pot create mode 100755 locales/gen_mo.sh create mode 100644 locales/messages.pot create mode 100644 locales/template.pot diff --git a/app.py b/app.py index 8ff259c..9cd60a7 100755 --- a/app.py +++ b/app.py @@ -6,9 +6,20 @@ import http.client, ssl import xml.etree.ElementTree as ET from flask import Flask, render_template, request, make_response, jsonify from waitress import serve +import gettext app = Flask(__name__) +# ~ _ = gettext.gettext + +LOCALE = os.getenv('LANG', 'en') + +_ = gettext.translation('template', localedir='locales', languages=[LOCALE]).gettext + +queue_msgs = [ _("No items"), + _("No files queued."), + ] + # Load config defaults, then look for other config files app.config.from_file("defaults.toml", load=toml.load) config_locations = ["./", "~/.", "~/.config/"] @@ -16,7 +27,7 @@ for location in config_locations: # Optional config files, ~ is expanded to $HOME on *nix, %USERPROFILE% on windows # ~ app.config.from_file("videopi.toml", load=toml.load, silent=True) if app.config.from_file(os.path.expanduser( location + "pilpil-server.toml"), load=toml.load, silent=True): - print("Found configuration file in " + os.path.expanduser( location )) + print( _("Found configuration file in {}").format( os.path.expanduser(location) ) ) # ~ app.config.from_file(os.path.expanduser("~/.config/videopi.toml"), load=toml.load, silent=True) ### @@ -99,11 +110,11 @@ def isup(host_l, port): s.settimeout(3.0) s.connect((host_l, port)) if DEBUG: - print( "Port " + str(port) + " reachable") + print( _("Port {} reachable").format(str(port)) ) return 1 except (socket.error, socket.timeout) as e: if DEBUG: - print("Error on connection to " + host_l + ":" + str(port) + ": %s" % e) + print( _("Error on connection to {} : {} : {} ").format(host_l, str(port), e) ) return 0 finally: s.close() @@ -117,7 +128,7 @@ def checkHosts(host_l): else: hostup.append(lhost) if DEBUG: - print( str(len(hostup)) + " of " + hosts_number + " hosts found.") + print( _("{} of {} hosts found.").format(str(len(hostup)), hosts_number)) return hostup, hostdown # File utilities @@ -163,7 +174,7 @@ def syncMediaFolder(media_folder_local, media_folder_remote, hostl, sync_facilit transfer_ok = 0 for media in media_list: transfer_ok += httpUpload(media, hostl, trailing_slash) - return str(transfer_ok) + " files uploaded." + return _("{} files uploaded.").format(str(transfer_ok)) # Check sync utility exists elif which(sync_facility): @@ -246,10 +257,10 @@ def sendCommand(host, arg0, arg1, arg2): resp = conn.getresponse() data = resp.read() except http.client.HTTPException: - print("Connection to " + host + " timed out") - return "Connection to " + host + " timed out" + print( _("Connection to {} timed out").format(host) ) + return _("Connection to {} timed out").format(host) except: - return "Error while connecting to " + host + ":" + str(portl) + return _("Error while connecting to {}:{}").format(host, str(portl)) finally: conn.close() # Parse response @@ -325,16 +336,17 @@ def sendCommand(host, arg0, arg1, arg2): } return playlist_overview -status_message = "Idle" +status_message = _("Idle") @app.route("/") def main(): global hosts - status_message = "Searching network for live hosts..." + status_message = _("Searching network for live hosts...") # ~ hosts_available, hosts_unavailable = checkHosts(hosts) templateData = { 'hosts' : hosts, - 'status_message' : status_message + 'status_message' : status_message, + 'queue_msgs' : queue_msgs } return render_template('main.html', **templateData) @@ -367,14 +379,14 @@ def sync(host): def action(host, arg0, arg1, arg2): status_message = "Idle" if (arg0 not in cmd_player) and (arg0 not in cmd_server): - status_message = "

Wrong command

" + status_message = "

{}

".format(_("Wrong command")) elif host == "all": resp = [] for hostl in hosts_available: resp.append( sendCommand(hostl, arg0, arg1, arg2) ) status_message = resp elif host not in hosts_available: - status_message = "

Host is not reachable

" + status_message = "

{}

".format("Host is not reachable") else: status_message = sendCommand(host, arg0, arg1, arg2) if DEBUG: diff --git a/locales/en/LC_MESSAGES/template.mo b/locales/en/LC_MESSAGES/template.mo new file mode 100644 index 0000000000000000000000000000000000000000..9f2e039f71ba6c7dad3f1903b0947d20e58ba4cc GIT binary patch literal 334 zcmYL^y-vh15QGmwl@d`>xS#_Eu0RUrIGwrpLWJ|9{G0@xNtO_FIFVxzc@SQYXJOND zBYoOpM!U1W$45Ui)B$peoFRwE1v1G)PSCu;Ic5Hpn(iGcOT(IO!3=Gu8AMIM3JPDrBD4{+l4+)FH^XDWMj#PuCg;9FgDcc!FHl>s#=8+%^ z5%Ey2xbJ5o&zBh0&8KRB7N9;DkvtB{>EuGn)vk3r(=44RjKsdw+`V$vowlIy#@J&C z3*Yv#->FvLlIl&F0qk8_Y^b--ODpv%Uclu literal 0 HcmV?d00001 diff --git a/locales/en/LC_MESSAGES/template.pot b/locales/en/LC_MESSAGES/template.pot new file mode 100644 index 0000000..7df0eee --- /dev/null +++ b/locales/en/LC_MESSAGES/template.pot @@ -0,0 +1,66 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2022-11-01 19:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + +#: app.py:19 +msgid "No file" +msgstr "" + +#: app.py:20 +msgid "No files queued." +msgstr "" + +#: app.py:22 +msgid "Found configuration file in {}" +msgstr "" + +#: app.py:105 +msgid "Port {} reachable" +msgstr "" + +#: app.py:109 +msgid "Error on connection to {} : {} : {} " +msgstr "" + +#: app.py:123 +msgid "{} of {} hosts found." +msgstr "" + +#: app.py:169 +msgid "{} files uploaded." +msgstr "" + +#: app.py:252 app.py:253 +msgid "Connection to {} timed out" +msgstr "" + +#: app.py:255 +msgid "Error while connecting to {}:{}" +msgstr "" + +#: app.py:331 +msgid "Idle" +msgstr "" + +#: app.py:336 +msgid "Searching network for live hosts..." +msgstr "" + +#: app.py:373 +msgid "Wrong command" +msgstr "" + + + diff --git a/locales/fr/LC_MESSAGES/template.mo b/locales/fr/LC_MESSAGES/template.mo new file mode 100644 index 0000000000000000000000000000000000000000..172571df5c12fbc82071f6e67245c7a05ddec94f GIT binary patch literal 1180 zcmZvbJ8u**6on0h*YXfVP=F9v0t6DwKnf%@Jj9Sp!is%Fn+Jl<%-r1_n6(Gn6IdY% zB>n&eB@%5q8cG_r=O-X~Xz4k35{QDZbm!CB*XLZ@cfU2Ofov+|o@H@yJQ#*y22B*Q};Cb*E)^32T zySPh;%U}tz-+S;P_yyb#{s0eyzrYjV6wF!gGLwZ=*;r2pnboLGN0 zlb#Rrg8t^|!G>1!@|Bo3mCksjpARalYNI|U=NclSnH3~DM)K4jI{B=kin35F8td80 zl1hi_F;bRD*>sr0L6d)O>{HoCjYYmja%h})VHk=B)?hs~qmj~?z;+gQvMLLsGM2@Z z>9cOV1qvt;X4X8xO$5y>SS9OlBavK;XYa=giCj&3OU-VlvDgiIw3hQ?FsD34@?jG9 zf_68Ui{-s;)NWpS)a@jVmU2E=wo1D~d1E6vztU>SPTWr9&7>VSTX*8Qxn8ogbQ`I9 zP^ke0%cMq;Y{i|06}G(DYTYUF(AdH4M!VTgwu+hwuQu>(o-{nhC5rI$!e1#1mFpW4 z7iAs!TPw@+!S$^?uBA^lNOWp4++QTGKhAw)fi&S&C=2e6BUz3I7&a?kkC>% z8hRuxaval1$7dpGC+m(>#Z5K4(N5gA{CB8`yJ*wW!DP*hkzDr{D#zL%sm-#n^c$=G BM0x-K literal 0 HcmV?d00001 diff --git a/locales/fr/LC_MESSAGES/template.pot b/locales/fr/LC_MESSAGES/template.pot new file mode 100644 index 0000000..800658d --- /dev/null +++ b/locales/fr/LC_MESSAGES/template.pot @@ -0,0 +1,64 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2022-11-01 19:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + +#: app.py:19 +msgid "No file" +msgstr "Aucun fichier." + +#: app.py:20 +msgid "No files queued." +msgstr "Aucun fichier en attente." + +#: app.py:22 +msgid "Found configuration file in {}" +msgstr "Fichier de configuration trouvé dans {}" + +#: app.py:105 +msgid "Port {} reachable" +msgstr "Port {} accessible" + +#: app.py:109 +msgid "Error on connection to {} : {} : {} " +msgstr "Erreur lors de la connexion à {} : {} : {} " + +#: app.py:123 +msgid "{} of {} hosts found." +msgstr "{} de {} clients trouvés." + +#: app.py:169 +msgid "{} files uploaded." +msgstr "{} fichiers envoyés." + +#: app.py:252 app.py:253 +msgid "Connection to {} timed out" +msgstr "Temps d'attente dépassé : {} " + +#: app.py:255 +msgid "Error while connecting to {}:{}" +msgstr "Erreur pendant la connexion à {}:{}" + +#: app.py:331 +msgid "Idle" +msgstr "Innocupé" + +#: app.py:336 +msgid "Searching network for live hosts..." +msgstr "Recherche des clients sur le réseau..." + +#: app.py:373 +msgid "Wrong command" +msgstr "Commande inconnue" + diff --git a/locales/gen_mo.sh b/locales/gen_mo.sh new file mode 100755 index 0000000..b20995d --- /dev/null +++ b/locales/gen_mo.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# +for locale in */LC_MESSAGES/template.pot; do + /usr/bin/msgfmt -o ${locale%.*}.mo $locale +done diff --git a/locales/messages.pot b/locales/messages.pot new file mode 100644 index 0000000..c1a34dd --- /dev/null +++ b/locales/messages.pot @@ -0,0 +1,17 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2022-11-02 18:58+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + diff --git a/locales/template.pot b/locales/template.pot new file mode 100644 index 0000000..c3434b2 --- /dev/null +++ b/locales/template.pot @@ -0,0 +1,57 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2022-11-01 19:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +#: app.py:22 +msgid "Found configuration file in {}" +msgstr "" + +#: app.py:105 +msgid "Port {} reachable" +msgstr "" + +#: app.py:109 +msgid "Error on connection to {} : {} : {} " +msgstr "" + +#: app.py:123 +msgid "{} of {} hosts found." +msgstr "" + +#: app.py:169 +msgid "{} files uploaded." +msgstr "" + +#: app.py:252 app.py:253 +msgid "Connection to {} timed out" +msgstr "" + +#: app.py:255 +msgid "Error while connecting to {}:{}" +msgstr "" + +#: app.py:331 +msgid "Idle" +msgstr "" + +#: app.py:336 +msgid "Searching network for live hosts..." +msgstr "" + +#: app.py:373 +msgid "Wrong command" +msgstr "" + diff --git a/static/script.js b/static/script.js index f9d8d42..ec27d63 100644 --- a/static/script.js +++ b/static/script.js @@ -263,7 +263,7 @@ function parseResult(command, infos_array) { scanInterval = 10000; document.getElementById("status_all").innerHTML = "Scan intarvel set to " + scanInterval; } - document.getElementById("status_all").innerHTML = host_up.length + " client(s) found."; + document.getElementById("status_all").innerHTML = host_up.length + " client(s)."; break; case "/browse": var html_table = "" + @@ -278,7 +278,7 @@ function parseResult(command, infos_array) { "" ; } html_table += "
"; - document.getElementById("filelist").innerHTML += html_table; + document.getElementById("filelist").innerHTML = html_table; break; case "/all/rssi": var signal_color = 40; diff --git a/templates/main.html b/templates/main.html index 056789b..42a2479 100644 --- a/templates/main.html +++ b/templates/main.html @@ -13,9 +13,9 @@
-

Videopi commander

+

Pilpil-server

{{status_message}}

-

No files.

+

{{queue_msgs[0]}}

@@ -56,7 +56,7 @@

Repeat

-

No files queued.

+

{{queue_msgs[1]}}