From a359e0b5e159ec3655c43d6a2ff6c379a9049850 Mon Sep 17 00:00:00 2001 From: Arne van Iterson Date: Thu, 20 Feb 2020 13:08:13 +0100 Subject: [PATCH] Made it work --- .gitignore | 2 +- README.md | 5 ++ css/styles.css | 33 +++++++++++++ css/styles.css.map | 9 ++++ css/styles.scss | 31 +++++++++++++ index.html | 36 ++++++++++++++ index.js | 85 ++++++++++++++++++++++++++++++++++ package.json | 2 +- views/error.mustache | 22 +++++++++ views/index.mustache | 41 ++++++++++++++++ views/partials/footer.mustache | 4 ++ views/partials/header.mustache | 2 + views/result.mustache | 20 ++++++++ 13 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 css/styles.css create mode 100644 css/styles.css.map create mode 100644 css/styles.scss create mode 100644 index.html create mode 100644 views/error.mustache create mode 100644 views/index.mustache create mode 100644 views/partials/footer.mustache create mode 100644 views/partials/header.mustache create mode 100644 views/result.mustache diff --git a/.gitignore b/.gitignore index 9c67f68..161ebba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /node_modules/ - +/result/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..811c912 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +## Polytranslatia +### Easily make your own language file for the Polytopia by Midjiwan. + +bash```npm install +npm start``` \ No newline at end of file diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..82c9fc9 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,33 @@ +body { + font-family: Arial, Helvetica, sans-serif; + text-align: center; + max-width: 500px; + position: relative; + margin: 0 auto; +} + +body h1 { + font-weight: lighter; + margin-bottom: 0; +} + +body h3 { + margin-top: 0; + font-weight: lighter; +} + +body input { + margin: 5px; +} + +body footer { + position: fixed; + width: 220px; + left: calc(50% - 110px); + bottom: 10px; +} + +body footer a { + color: black; +} +/*# sourceMappingURL=styles.css.map */ \ No newline at end of file diff --git a/css/styles.css.map b/css/styles.css.map new file mode 100644 index 0000000..befd32b --- /dev/null +++ b/css/styles.css.map @@ -0,0 +1,9 @@ +{ + "version": 3, + "mappings": "AAAA,AAAA,IAAI,CAAC;EACD,WAAW,EAAE,4BAA4B;EACzC,UAAU,EAAE,MAAM;EAClB,SAAS,EAAE,KAAK;EAChB,QAAQ,EAAE,QAAQ;EAClB,MAAM,EAAE,MAAM;CAyBjB;;AA9BD,AAOI,IAPA,CAOA,EAAE,CAAC;EACC,WAAW,EAAE,OAAO;EACpB,aAAa,EAAE,CAAC;CACnB;;AAVL,AAYI,IAZA,CAYA,EAAE,CAAC;EACC,UAAU,EAAE,CAAC;EACb,WAAW,EAAE,OAAO;CACvB;;AAfL,AAiBI,IAjBA,CAiBA,KAAK,CAAC;EACF,MAAM,EAAE,GAAG;CACd;;AAnBL,AAqBI,IArBA,CAqBA,MAAM,CAAC;EACH,QAAQ,EAAE,KAAK;EACf,KAAK,EAAE,KAAK;EACZ,IAAI,EAAE,iBAAiB;EACvB,MAAM,EAAE,IAAI;CAIf;;AA7BL,AA0BQ,IA1BJ,CAqBA,MAAM,CAKF,CAAC,CAAC;EACE,KAAK,EAAE,KAAK;CACf", + "sources": [ + "styles.scss" + ], + "names": [], + "file": "styles.css" +} \ No newline at end of file diff --git a/css/styles.scss b/css/styles.scss new file mode 100644 index 0000000..4923f9b --- /dev/null +++ b/css/styles.scss @@ -0,0 +1,31 @@ +body { + font-family: Arial, Helvetica, sans-serif; + text-align: center; + max-width: 500px; + position: relative; + margin: 0 auto; + + h1 { + font-weight: lighter; + margin-bottom: 0; + } + + h3 { + margin-top: 0; + font-weight: lighter; + } + + input { + margin: 5px; + } + + footer { + position: fixed; + width: 220px; + left: calc(50% - 110px); + bottom: 10px; + a { + color: black; + } + } +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..89c9694 --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + + Poliatranslatia + + + + +

Poliatranslatia

+

Easily make your own language file for the Polytopia by Midjiwan.

+
+
+
+

+ +
+
+ + +
+ + + + + + \ No newline at end of file diff --git a/index.js b/index.js index e69de29..8915479 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,85 @@ +const express = require('express') +const app = express() +const axios = require('axios').default; +const fs = require('fs'); +var mustacheExpress = require('mustache-express'); + +const port = 7659; +const apiKey = "trnsl.1.1.20200219T163804Z.dd385eb08e22b0a9.628dfdf2e50cf9faa61898cb7195740bb3ac3b86"; + +// Register '.mustache' extension with The Mustache Express +app.engine('mustache', mustacheExpress()); + +app.set('view engine', 'mustache'); +app.set('views', __dirname + '/views'); + +app.use(express.urlencoded()); + +app.get('/', function(req, res) { + axios.get('https://translate.yandex.net/api/v1.5/tr.json/getLangs', { + params: { + key: apiKey + } + }) + .then(function (response) { + res.render('index', response.data) + }) + .catch(function (error) { + data = { + error: error + }; + res.render('error', data) + }) +}); + +app.get('/css/:file', function(req, res) { + res.sendFile(__dirname + '/./css/' + req.params.file); +}); + +app.get('/result/:file', function(req, res) { + res.sendFile(__dirname + '/./result/' + req.params.file); +}); + +app.post('/', function(req, res) { + var filename = "/result/" + Math.floor(Date.now() / 1000) + ".json"; + axios.get(req.body.sourceUrl) + .then(function (response) { + var json = response.data; + var result = {}; + let promises = []; + for (var key in json) { + if (json.hasOwnProperty(key)) { + promises.push( + axios.get('https://translate.yandex.net/api/v1.5/tr.json/translate', { + params: { + key: apiKey, + lang: req.body.target, + text: json[key], + target: key + } + }) + .then(function (response) { + targetKey = response.request.path.match("(target=)(.+)")[2]; + result[targetKey] = response.data.text[0] + }) + ); + } + } + + Promise.all(promises).then(function () { + fs.writeFile(__dirname + filename, JSON.stringify(result)); + var data = { + 'link': filename + } + res.render('result', data); + }); + }) + .catch(function (error) { + data = { + error: error + }; + res.render('error', data) + }) +}); + +app.listen(port, () => console.log(`App listening on port ${port}`)) \ No newline at end of file diff --git a/package.json b/package.json index 61a6d3e..9103d0c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Translate Polytopia language files to any language you want!", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "nodemon index.js" }, "author": "McArn", "license": "ISC" diff --git a/views/error.mustache b/views/error.mustache new file mode 100644 index 0000000..6059b62 --- /dev/null +++ b/views/error.mustache @@ -0,0 +1,22 @@ + + + + + + Poliatranslatia + + + + + + {{> partials/header}} + +

Something went wrong

+ + {{error}} + + + {{> partials/footer}} + + + \ No newline at end of file diff --git a/views/index.mustache b/views/index.mustache new file mode 100644 index 0000000..2356d62 --- /dev/null +++ b/views/index.mustache @@ -0,0 +1,41 @@ + + + + + + Poliatranslatia + + + + + + {{> partials/header}} + +
+
+
+

+ +
+

For example:
From en_US default to dutch, use en_nl.

+ +

+ + +
+ + + + {{> partials/footer}} + + + \ No newline at end of file diff --git a/views/partials/footer.mustache b/views/partials/footer.mustache new file mode 100644 index 0000000..cc60b15 --- /dev/null +++ b/views/partials/footer.mustache @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/views/partials/header.mustache b/views/partials/header.mustache new file mode 100644 index 0000000..172e235 --- /dev/null +++ b/views/partials/header.mustache @@ -0,0 +1,2 @@ +

Poliatranslatia

+

Easily make your own language file for the Polytopia by Midjiwan.

\ No newline at end of file diff --git a/views/result.mustache b/views/result.mustache new file mode 100644 index 0000000..4fea7f1 --- /dev/null +++ b/views/result.mustache @@ -0,0 +1,20 @@ + + + + + + Poliatranslatia + + + + + + {{> partials/header}} + +

Enter the following link into Polytopia to start using your custom language file. You can also share it with your friends!

+ {{link}} + + {{> partials/footer}} + + + \ No newline at end of file