From a00d9eec8bdbe623b0d4641f8ccfbb5d35492cb6 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 24 Jan 2020 01:58:43 +0100 Subject: [PATCH] internalization --- app/Controllers/Http/DownloadController.js | 14 +++++--- resources/locales/en/announcement.json | 8 +++++ resources/locales/en/messages.json | 27 +++++++++++++++ resources/locales/fr/announcement.json | 8 +++++ resources/locales/fr/messages.json | 27 +++++++++++++++ resources/views/index.edge | 39 +++++++++++----------- start/app.js | 1 + 7 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 resources/locales/en/announcement.json create mode 100644 resources/locales/en/messages.json create mode 100644 resources/locales/fr/announcement.json create mode 100644 resources/locales/fr/messages.json diff --git a/app/Controllers/Http/DownloadController.js b/app/Controllers/Http/DownloadController.js index 3c194cd..01ab9ef 100644 --- a/app/Controllers/Http/DownloadController.js +++ b/app/Controllers/Http/DownloadController.js @@ -3,14 +3,15 @@ const youtubedl = require('youtube-dl') const fs = require('fs') const ffmpeg = require('fluent-ffmpeg') const { version } = require('../../../package.json'); +const Antl = use('Antl') let viewCounter = 0; let files = []; let day; let month; -let announcementArray = ['Twitter download seems to work fine now!', 'u lookin hot today vro', 'I am not responsible for what you download', 'If you want to support me you can donate through my paypal at the bottom of the page', 'Did you know this website is open source?', 'Did you know this website can download from other website than youtube?', 'You can mouse hover a video to see a preview of it!'] -let announcement let title = `le epic downloader v${version}`; +let announcementArray; +let announcement function formatBytes(bytes, decimals = 2) { // https://stackoverflow.com/a/18650828 @@ -27,16 +28,19 @@ function formatBytes(bytes, decimals = 2) { // https://stackoverflow.com/a/18650 class DownloadController { - async index ({ view, response }) { + async index ({ view, request, locale }) { viewCounter++; + // Coudln't find a cleaner way to make it change with the browser locale + announcementArray = [Antl.forLocale(locale).formatMessage('announcement.1'), Antl.forLocale(locale).formatMessage('announcement.2'), Antl.forLocale(locale).formatMessage('announcement.3'), Antl.forLocale(locale).formatMessage('announcement.4'), Antl.forLocale(locale).formatMessage('announcement.5'), Antl.forLocale(locale).formatMessage('announcement.6')]; // Get random announcement announcement = announcementArray[Math.floor(Math.random() * announcementArray.length)]; + // Get date for some event let today = new Date(); day = today.getDay(); month = today.getMonth(); // If legacy link return - if (response.request.url == '/legacy') return view.render('legacy', { title: title, viewCounter: viewCounter, day: day, month: month, announcement: announcement}); + if (request.url == '/legacy') return view.render('legacy', { title: title, viewCounter: viewCounter, day: day, month: month, announcement: announcement}); files = []; let file = []; @@ -70,7 +74,7 @@ class DownloadController { files.push({ name: f.split('.').slice(0, -1).join('.'), size: formatBytes(fs.statSync(`./public/uploads/${f}`).size), location: `uploads/${f}`, ext: f.split('.').pop(), img: `/asset/music.png` }); } } - return view.render('index', { title: title, viewCounter: viewCounter, file: files, day: day, month: month, announcement: announcement }); + return view.render('index', { title: title, viewCounter: viewCounter, file: files, day: day, month: month, announcement: announcement}); } async download({ view, request, response }) { diff --git a/resources/locales/en/announcement.json b/resources/locales/en/announcement.json new file mode 100644 index 0000000..10830a2 --- /dev/null +++ b/resources/locales/en/announcement.json @@ -0,0 +1,8 @@ +{ + "1": "u lookin hot today vro 😳😳", + "2": "I am not responsible for what you download.", + "3": "If you want to support me you can donate through my paypal at the bottom of the page", + "4": "Did you know this website is open source?", + "5": "Did you know this website can download from other website than youtube?", + "6": "You can mouse hover a video to see a preview of it!" +} \ No newline at end of file diff --git a/resources/locales/en/messages.json b/resources/locales/en/messages.json new file mode 100644 index 0000000..08b7c69 --- /dev/null +++ b/resources/locales/en/messages.json @@ -0,0 +1,27 @@ +{ + "announcement": "Announcement", + "LQ": "Low quality", + "HQ": "High quality", + "altDL": "Alternate download", + "feed": "Hide from feed", + "download": "Download that mf video", + "dlStart": "Download started!", + "errorCopy": "An error has occured while copying the link to your clipboard.", + "successCopy": "Successfully copied link to your clipboard!", + "recentFeed": "Recently downloaded videos", + "recentDownload": "Download", + "recentCopy": "Copy to clipboard", + "recentFormat": "File format", + "recentSize": "File size", + "footer": "I decline any responsabilities for download made using this website.", + "footer2p1": "Credit to", + "footer2p2": "My other projects", + "footer2p3": "Numbers of visits", + "footer2p4": "Contact", + "footer2p5": "on Discord if you have any issues", + "footer3p1": "You can also support me either on", + "footer3p2": "or by tipping", + "footer3p3": "on this website! or using my referal link for", + "footer4": "Legacy version", + "eggXmas": "Happy Christmas!" +} \ No newline at end of file diff --git a/resources/locales/fr/announcement.json b/resources/locales/fr/announcement.json new file mode 100644 index 0000000..ba94a0a --- /dev/null +++ b/resources/locales/fr/announcement.json @@ -0,0 +1,8 @@ +{ + "1": "salut bg 😳😳", + "2": "Je ne suis pas résponsable pour ce que vous télécharger.", + "3": "Si vous voulez me supporter vous pouvez me faire une donation avec paypal en bas de la page.", + "4": "Le saviez-vous? Le site est open source!", + "5": "Le saviez-vous? Vous pouvez télécharger des vidéos sur d'autre site que youtube.", + "6": "Vous pouvez passer la souris sur une vidéo pour en voir un aperçu!" +} \ No newline at end of file diff --git a/resources/locales/fr/messages.json b/resources/locales/fr/messages.json new file mode 100644 index 0000000..00a9dd2 --- /dev/null +++ b/resources/locales/fr/messages.json @@ -0,0 +1,27 @@ +{ + "announcement": "Annoncement", + "LQ": "Basse qualité", + "HQ": "Haute qualité", + "altDL": "Téléchargement alternatif", + "feed": "Masquer du flux", + "download": "Télécharge cette vidéo", + "dlStart": "Téléchargement lancée!", + "errorCopy": "Une erreur est survenue en essayant de copier le lien dans votre presse-papier", + "successCopy": "Lien copié avec succès vers votre presse-papiers!", + "recentFeed": "Vidéos récemment télécharger", + "recentDownload": "Télécharge", + "recentCopy": "Copier au press-papier", + "recentFormat": "Format du fichier", + "recentSize": "Taille du fichier", + "footer": "Je décline toute résponsabilité pour les téléchargement fait avec ce site", + "footer2p1": "Merci à", + "footer2p2": "Mes autres projets", + "footer2p3": "Nombre de visite", + "footer2p4": "Contactée", + "footer2p5": "sur Discord si vous avez des problèmes", + "footer3p1": "Vous pouvez me supporter sur", + "footer3p2": "ou en fesent une donation avec", + "footer3p3": "sur ce site! Ou en utilisent mon lien de parrainage pour", + "footer4": "Legacy version", + "eggXmas": "Joyeu noël!" +} \ No newline at end of file diff --git a/resources/views/index.edge b/resources/views/index.edge index 29fa9a5..4f71fbc 100644 --- a/resources/views/index.edge +++ b/resources/views/index.edge @@ -24,12 +24,12 @@ @if(announcement || (day == '24' || day == '25') && month == '11')
- Announcement + {{ antl.formatMessage('messages.announcement') }}
@if((day == '24' || day == '25') && month == '11') -

Happy Christmas!

+

{{ antl.formatMessage('messages.eggXmas') }}

@endif

{{ announcement }}

@@ -52,22 +52,22 @@
@@ -81,7 +81,7 @@

- +

@@ -133,7 +133,7 @@ @if(file != "") -

Recently downloaded videos

+

{{ antl.formatMessage('messages.recentFeed') }}

@each(file in file) @@ -150,23 +150,23 @@

- Download + {{ antl.formatMessage('messages.recentDownload') }}

- +

- File format + {{ antl.formatMessage('messages.recentFormat') }} {{ file.ext }}
- File size + {{ antl.formatMessage('messages.recentSize') }} {{ file.size }}
@@ -177,12 +177,11 @@
@endif - @if(month == '11') @@ -192,7 +191,7 @@ function submitDownload() { let frm = document.getElementsByName('download-form')[0]; frm.submit(); - document.getElementById('msg').innerHTML = '
Download started!
'; + document.getElementById('msg').innerHTML = '
{{ antl.formatMessage('messages.dlStart') }}
'; setTimeout(() => { fadeout('notif') }, 2000); @@ -212,12 +211,12 @@ navigator.clipboard.writeText(text) .catch(err => { console.error(err); - document.getElementById('msg').innerHTML = '
An error has occured while copying the link to your clipboard.
'; + document.getElementById('msg').innerHTML = '
{{ antl.formatMessage('messages.errorCopy') }}
'; setTimeout(() => { fadeout('notif') }, 2000); }); - document.getElementById('msg').innerHTML = '
Success fully copied link to your clipboard!
'; + document.getElementById('msg').innerHTML = '
{{ antl.formatMessage('messages.successCopy') }}
'; setTimeout(() => { fadeout('notif') }, 2000); diff --git a/start/app.js b/start/app.js index 0f01b56..e3f937c 100644 --- a/start/app.js +++ b/start/app.js @@ -20,6 +20,7 @@ const providers = [ '@adonisjs/session/providers/SessionProvider', '@adonisjs/auth/providers/AuthProvider', '@adonisjs/validator/providers/ValidatorProvider', + '@adonisjs/antl/providers/AntlProvider', ] /*