From 31af36e57eb48b60f108ca5e550c153aa9ec35ba Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Mon, 28 Nov 2022 23:43:24 +0100 Subject: [PATCH 1/6] Don't hardcode locales --- locales/index.js | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/locales/index.js b/locales/index.js index 92cd9b467c..3be17d471e 100644 --- a/locales/index.js +++ b/locales/index.js @@ -13,33 +13,14 @@ const merge = (...args) => args.reduce((a, c) => ({ .reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {}) }), {}); -const languages = [ - 'ar-SA', - 'cs-CZ', - 'da-DK', - 'de-DE', - 'en-US', - 'es-ES', - 'fr-FR', - 'id-ID', - 'it-IT', - 'ja-JP', - 'ja-KS', - 'kab-KAB', - 'kn-IN', - 'ko-KR', - 'nl-NL', - 'no-NO', - 'pl-PL', - 'pt-PT', - 'ru-RU', - 'sk-SK', - 'ug-CN', - 'uk-UA', - 'vi-VN', - 'zh-CN', - 'zh-TW', -]; +languages = [] + +fs.readdirSync(__dirname).forEach((file) => { + if (file.includes('.yml')){ + file = file.slice(0, file.indexOf('.')) + languages.push(file) + } +}) const primaries = { 'en': 'US', From 7e3c34495e1e4dde7fdbc6f09bfd4f007f808da1 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Tue, 29 Nov 2022 01:05:16 +0100 Subject: [PATCH 2/6] Add custom locales --- .gitignore | 1 + locales/index.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a4e0313996..fcab9e323e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ api-docs.json ormconfig.json /custom packages/backend/assets/instance.css +/locales/custom # blender backups *.blend1 diff --git a/locales/index.js b/locales/index.js index 3be17d471e..94643a76ee 100644 --- a/locales/index.js +++ b/locales/index.js @@ -4,6 +4,8 @@ const fs = require('fs'); const yaml = require('js-yaml'); +let languages = [] +let languages_custom = [] const merge = (...args) => args.reduce((a, c) => ({ ...a, @@ -13,12 +15,18 @@ const merge = (...args) => args.reduce((a, c) => ({ .reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {}) }), {}); -languages = [] fs.readdirSync(__dirname).forEach((file) => { if (file.includes('.yml')){ file = file.slice(0, file.indexOf('.')) - languages.push(file) + languages.push(file); + } +}) + +fs.readdirSync(__dirname + '/custom').forEach((file) => { + if (file.includes('.yml')){ + file = file.slice(0, file.indexOf('.')) + languages_custom.push(file); } }) @@ -32,6 +40,8 @@ const primaries = { const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), ''); const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, 'utf-8'))) || {}, a), {}); +const locales_custom = languages_custom.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/custom/${c}.yml`, 'utf-8'))) || {}, a), {}); +Object.assign(locales, locales_custom) module.exports = Object.entries(locales) .reduce((a, [k ,v]) => (a[k] = (() => { From 43961da9236cc81a82ef078fec5cd69e13927963 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Tue, 29 Nov 2022 01:15:07 +0100 Subject: [PATCH 3/6] docs: custom locales --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9bf4083470..a62a56d668 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ psql postgres -c "create database calckey with encoding = 'UTF8';" - To add custom CSS for all users, edit `./custom/instance.css`. - To add static assets (such as images for the splash screen), place them in the `./custom/` directory. They'll then be avaliable on `https://yourinstance.tld/static-assets/filename.ext`. +- To add custom locales, create a directory `/locales/custom/` and place custom locale files in there. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. - To update custom assets without rebuilding, just run `yarn run gulp`. ## 🧑‍🔬 Configuring a new instance From efbce8e28727f45bce53199c0fce8215784c32ca Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Tue, 29 Nov 2022 22:27:08 +0100 Subject: [PATCH 4/6] Docs: Add info for custom locale naming --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a62a56d668..a9d1397b37 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ psql postgres -c "create database calckey with encoding = 'UTF8';" - To add custom CSS for all users, edit `./custom/instance.css`. - To add static assets (such as images for the splash screen), place them in the `./custom/` directory. They'll then be avaliable on `https://yourinstance.tld/static-assets/filename.ext`. -- To add custom locales, create a directory `/locales/custom/` and place custom locale files in there. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. +- To add custom locales, create a directory `/locales/custom/` and place custom locale files in there. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. Also make sure that the first part of the filename matches the locale you're basing it on. (Example: `en-FOO.yml`) - To update custom assets without rebuilding, just run `yarn run gulp`. ## 🧑‍🔬 Configuring a new instance From 439d0628626b2ca129990c37e958c316a731bdb3 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Tue, 29 Nov 2022 23:08:37 +0100 Subject: [PATCH 5/6] Rework `custom` behaviour --- .gitignore | 1 - custom/{ => assets}/instance.css | 0 custom/locales/.gitkeep | 0 gulpfile.js | 2 +- locales/index.js | 4 ++-- 5 files changed, 3 insertions(+), 4 deletions(-) rename custom/{ => assets}/instance.css (100%) create mode 100644 custom/locales/.gitkeep diff --git a/.gitignore b/.gitignore index fcab9e323e..a4e0313996 100644 --- a/.gitignore +++ b/.gitignore @@ -52,7 +52,6 @@ api-docs.json ormconfig.json /custom packages/backend/assets/instance.css -/locales/custom # blender backups *.blend1 diff --git a/custom/instance.css b/custom/assets/instance.css similarity index 100% rename from custom/instance.css rename to custom/assets/instance.css diff --git a/custom/locales/.gitkeep b/custom/locales/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gulpfile.js b/gulpfile.js index 86f860e568..89a6acb839 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,7 +16,7 @@ gulp.task('copy:backend:views', () => ); gulp.task('copy:backend:custom', () => - gulp.src('./custom/*').pipe(gulp.dest('./packages/backend/assets/')) + gulp.src('./custom/assets/*').pipe(gulp.dest('./packages/backend/assets/')) ); gulp.task('copy:client:fonts', () => diff --git a/locales/index.js b/locales/index.js index 94643a76ee..7399bb5a18 100644 --- a/locales/index.js +++ b/locales/index.js @@ -23,7 +23,7 @@ fs.readdirSync(__dirname).forEach((file) => { } }) -fs.readdirSync(__dirname + '/custom').forEach((file) => { +fs.readdirSync(__dirname + '/../custom/locales').forEach((file) => { if (file.includes('.yml')){ file = file.slice(0, file.indexOf('.')) languages_custom.push(file); @@ -40,7 +40,7 @@ const primaries = { const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), ''); const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, 'utf-8'))) || {}, a), {}); -const locales_custom = languages_custom.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/custom/${c}.yml`, 'utf-8'))) || {}, a), {}); +const locales_custom = languages_custom.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/../custom/locales/${c}.yml`, 'utf-8'))) || {}, a), {}); Object.assign(locales, locales_custom) module.exports = Object.entries(locales) From 20dc59c342d5ee22746a5f9c67a561ce1a8f3373 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Wed, 30 Nov 2022 19:51:12 +0100 Subject: [PATCH 6/6] docs: reflect last change in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a9d1397b37..5c4037a2ce 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,9 @@ psql postgres -c "create database calckey with encoding = 'UTF8';" ## 💅 Customize -- To add custom CSS for all users, edit `./custom/instance.css`. -- To add static assets (such as images for the splash screen), place them in the `./custom/` directory. They'll then be avaliable on `https://yourinstance.tld/static-assets/filename.ext`. -- To add custom locales, create a directory `/locales/custom/` and place custom locale files in there. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. Also make sure that the first part of the filename matches the locale you're basing it on. (Example: `en-FOO.yml`) +- To add custom CSS for all users, edit `./custom/assets/instance.css`. +- To add static assets (such as images for the splash screen), place them in the `./custom/assets/` directory. They'll then be avaliable on `https://yourinstance.tld/static-assets/filename.ext`. +- To add custom locales, place them in the `./custom/locales/` directory. If you name your custom locale the same as an existing locale, it will overwrite it. If you give it a unique name, it will be added to the list. Also make sure that the first part of the filename matches the locale you're basing it on. (Example: `en-FOO.yml`) - To update custom assets without rebuilding, just run `yarn run gulp`. ## 🧑‍🔬 Configuring a new instance