Browse Source

Added translation to the backend.

KrisVos130 7 years ago
parent
commit
e5f78e646e
4 changed files with 555 additions and 58 deletions
  1. 7 0
      backend/index.js
  2. 42 0
      backend/logic/i18n.js
  3. 504 58
      backend/package-lock.json
  4. 2 0
      backend/package.json

+ 7 - 0
backend/index.js

@@ -21,6 +21,7 @@ const notifications = require('./logic/notifications');
 const punishments = require('./logic/punishments');
 const punishments = require('./logic/punishments');
 const logger = require('./logic/logger');
 const logger = require('./logic/logger');
 const tasks = require('./logic/tasks');
 const tasks = require('./logic/tasks');
+const i18n = require('./logic/i18n');
 const config = require('config');
 const config = require('config');
 
 
 let currentComponent;
 let currentComponent;
@@ -104,6 +105,12 @@ function errorCb(message, err, component) {
 
 
 async.waterfall([
 async.waterfall([
 
 
+	// setup our translation
+	(next) => {
+		currentComponent = 'Translation';
+		i18n.init(next);
+	},
+
 	// setup our Redis cache
 	// setup our Redis cache
 	(next) => {
 	(next) => {
 		currentComponent = 'Cache';
 		currentComponent = 'Cache';

+ 42 - 0
backend/logic/i18n.js

@@ -0,0 +1,42 @@
+'use strict';
+
+const async = require("async");
+const i18next = require("i18next");
+const Backend = require("i18next-sync-fs-backend");
+const rootDir = __dirname.substr(0, __dirname.lastIndexOf("backend"));
+
+let initialized = false;
+let lockdown = false;
+
+let i18n;
+
+module.exports = {
+	init: function(cb) {
+		i18n = i18next
+			.use(Backend)
+			.init({
+				lng: "en",
+				debug: true,
+				fallbackLng: "en",
+				referenceLng: "en",
+				backend: {
+					loadPath: rootDir + "/locales/{{lng}}/{{ns}}.json",
+				},
+				ns: ["backend"],
+				defaultNS: "backend",
+				keySeparator: false, // we use content as keys
+				interpolation: {
+					escapeValue: false, // not needed for react!!
+					formatSeparator: ",",
+				},
+			});
+
+		initialized = true;
+		if (lockdown) return this._lockdown();
+		cb();
+	},
+	i18n,
+	_lockdown: function() {
+		lockdown = true;
+	}
+};

File diff suppressed because it is too large
+ 504 - 58
backend/package-lock.json


+ 2 - 0
backend/package.json

@@ -21,6 +21,8 @@
     "discord.js": "^11.0.0",
     "discord.js": "^11.0.0",
     "express": "^4.14.0",
     "express": "^4.14.0",
     "express-session": "^1.14.0",
     "express-session": "^1.14.0",
+    "i18next": "^8.4.3",
+    "i18next-sync-fs-backend": "^1.0.0",
     "mailgun-js": "^0.8.0",
     "mailgun-js": "^0.8.0",
     "moment": "^2.15.2",
     "moment": "^2.15.2",
     "mongoose": "^4.9.0",
     "mongoose": "^4.9.0",

Some files were not shown because too many files changed in this diff