diff --git a/README.md b/README.md index 1eb57f5..539e8a4 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,14 @@ http://yoksel.github.io/url-encoder Demo: https://codepen.io/yoksel/full/WNrLpYW. -## How to add translate +## How to run the project + +1. Run `npm i` to install all dependecies for development +2. Run `npm start` to start the process (will atomatically open up a new browser tab) + + +## How to add a translation 1. Create translation file (use `src/translate/en.json` as example) and place it to `src/translate/` -2. Add new language to section `langs` in all translation files -3. Add item with your language to section `translates` in `gulpfile.js`. -4. Run `npm start` in console (wait until project will be opened in browser) and check all pages: - * Link to new page must appear in all pages - * In the page with new translate new language in list must looks like current (bold and black) -5. Send pull request +2. Run the project locally and check the newly language page for any translation mistakes +3. Send pull request \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 6d3004e..a413bdf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,41 +6,23 @@ const colors = require(`colors/safe`); const del = require(`del`); const mustache = require(`gulp-mustache`); const rename = require(`gulp-rename`); +const getL10n = require(`./src/helpers/getLocalizations.js`).default; const SERVER_ROOT = `build/`; +const TRANSLATES_PATH = `./src/translate/`; -const translates = [ - { - dest: SERVER_ROOT, - url: `./src/translate/en.json` - }, - { - dest: `${SERVER_ROOT}pt`, - url: `./src/translate/pt.json` - }, - { - dest: `${SERVER_ROOT}ru`, - url: `./src/translate/ru.json` - }, - { - dest: `${SERVER_ROOT}zh-cn`, - url: `./src/translate/zh-cn.json` - }, - { - dest: `${SERVER_ROOT}zh-tw`, - url: `./src/translate/zh-tw.json` - }, - { - dest: `${SERVER_ROOT}tr`, - url: `./src/translate/tr.json` - } -]; +const {languages, translates} = getL10n(SERVER_ROOT, TRANSLATES_PATH); // TEMPLATES -const tmplTasks = translates.map(({ dest, url }) => { +const tmplTasks = translates.map(({ dest, content }) => { return (done) => { + // ATTACH RESPECTIVE LANG NAV + const langs = languages.map(lang => ({ + ...lang, + isActive: lang.name === content.langName + })); gulp.src(`./src/index-src.html`) - .pipe(mustache(url)) + .pipe(mustache({...content, langs})) .pipe(rename(`index.html`)) .pipe(gulp.dest(dest)) .pipe(reload({ stream: true })); diff --git a/package.json b/package.json index 3f85721..71a32f8 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,10 @@ "version": "1.0.1", "description": "http://yoksel.github.io/url-encoder", "main": ".eslintrc.js", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, "scripts": { "start": "gulp clean && gulp serve", "build": "gulp clean && gulp build", diff --git a/src/helpers/getLocalizations.js b/src/helpers/getLocalizations.js new file mode 100644 index 0000000..811a8c9 --- /dev/null +++ b/src/helpers/getLocalizations.js @@ -0,0 +1,41 @@ +const fs = require(`fs`); +const path = require(`path`); + +exports.default = (SERVER_ROOT, TRANSLATES_PATH) => { + // GENERATE TRANSLATES + const translateFiles = fs.readdirSync(TRANSLATES_PATH); + const languages = []; + const translates = []; + + translateFiles.forEach(translateFile => { + const fileUrl = TRANSLATES_PATH + translateFile; + const lang = path.basename(fileUrl, `.json`); + const content = JSON.parse(fs.readFileSync(fileUrl, `utf8`)); + const isEnglish = lang === 'en'; + const insertionMethod = isEnglish ? 'unshift' : 'push'; + + const language_data = { + name: content.langName, + code: lang, + }; + + const content_data = { + content: content, + dest: SERVER_ROOT + lang, + path: `..` + } + + if (isEnglish) { + // EN needs a different path and also has to be in first place of array + language_data['code'] = null; + content_data['dest'] = SERVER_ROOT; + content_data['path'] = `.`; + } + + languages[insertionMethod](language_data); + translates[insertionMethod](content_data) + + }); + + return {languages, translates} +}; \ No newline at end of file diff --git a/src/index-src.html b/src/index-src.html index d76d85c..738f1c2 100644 --- a/src/index-src.html +++ b/src/index-src.html @@ -11,7 +11,12 @@
Wir können ein SVG in CSS über Daten-URI verwenden, aber ohne kodierung funktioniert es nur in Webkit-basierten Browsern. Wenn das SVG mit encodeURIComponent()
kodiert wird, funktioniert es überall.
Das SVG muss das Attribut xmlns wie folgt besitzen: xmlns='http: //www.w3.org/2000/svg'
. Falls es nicht vorhanden ist, wird es automatisch hinzugefügt.
Das kodierte SVG kann anschließend als background
, als border-image
oder auch als mask
verwendet werden. (Live-Demo).