Browse Source

Internationalization

Sven SAULEAU 9 years ago
parent
commit
5c92727101
8 changed files with 40 additions and 13 deletions
  1. 18 6
      app.js
  2. 3 1
      config.js
  3. 6 0
      locales/en.json
  4. 6 0
      locales/fr.json
  5. 1 0
      package.json
  6. 1 1
      views/error.jade
  7. 4 4
      views/index.jade
  8. 1 1
      views/result.jade

+ 18 - 6
app.js

@@ -1,14 +1,26 @@
-var express = require('express');
-var path = require('path');
-var favicon = require('serve-favicon');
-var logger = require('morgan');
-var cookieParser = require('cookie-parser');
-var bodyParser = require('body-parser');
+var express = require('express'),
+    path = require('path'),
+    favicon = require('serve-favicon'),
+    logger = require('morgan'),
+    cookieParser = require('cookie-parser'),
+    bodyParser = require('body-parser'),
+    config = require('./config');
+    i18n = require("i18n");
 
 var routes = require('./routes/index');
 
 var app = express();
 
+i18n.configure({
+    locale: config.locale,
+    defaultLocale: "en",
+    directory: __dirname + '/locales',
+    autoReload: true
+});
+
+// default: using 'accept-language' header to guess language settings
+app.use(i18n.init);
+
 // view engine setup
 app.set('views', path.join(__dirname, 'views'));
 app.set('view engine', 'jade');

+ 3 - 1
config.js

@@ -14,5 +14,7 @@ module.exports = {
   //   --compressed
   slacktoken: process.env.SLACK_TOKEN || 'YOUR-ACCESS-TOKEN',
   // an optional security measure - if it is set, then that token will be required to get invited.
-  inviteToken: process.env.INVITE_TOKEN || null
+  inviteToken: process.env.INVITE_TOKEN || null,
+
+  locale: process.env.LOCALE || "en",
 };

+ 6 - 0
locales/en.json

@@ -0,0 +1,6 @@
+{
+	"HEADER": "Enter your email below to join %s on slack!",
+	"ENTER_EMAIL": "Enter Your Email Address",
+	"ENTER_TOKEN": "Enter the invite token you were given",
+	"TITLE": "Join the %s community on Slack!"
+}

+ 6 - 0
locales/fr.json

@@ -0,0 +1,6 @@
+{
+	"HEADER": "Entrez votre adresse mail pour rejoindre le groupe %s sur slack!",
+	"ENTER_EMAIL": "Entez votre adresse mail",
+	"ENTER_TOKEN": "Entrez votre token d'invitation",
+	"TITLE": "Rejoignez le groupe %s sur Slack!"
+}

+ 1 - 0
package.json

@@ -10,6 +10,7 @@
     "cookie-parser": "^1.4.0",
     "debug": "^2.2.0",
     "express": "^4.13.0",
+    "i18n": "^0.7.0",
     "jade": "^1.11.0",
     "morgan": "^1.6.0",
     "request": "^2.62.0",

+ 1 - 1
views/error.jade

@@ -3,7 +3,7 @@ html
   head
     meta(http-equiv="Content-Type", content="text/html; charset=utf-8")
     meta(name="viewport", content="width=device-width, initial-scale=1")
-    title Join the #{community} community on Slack!
+    title #{__('TITLE', community)}
     link(href="css/style.css", rel="stylesheet", type="text/css")
     link(href="http://fonts.googleapis.com/css?family=Lato:300,400,700,900,700italic|Open+Sans:700italic,400,600,300,700,800", rel="stylesheet", type="text/css")
   body

+ 4 - 4
views/index.jade

@@ -3,7 +3,7 @@ html
   head
     meta(http-equiv="Content-Type", content="text/html; charset=utf-8")
     meta(name="viewport", content="width=device-width, initial-scale=1")
-    title Join the #{community} community on Slack!
+    title #{__('TITLE', community)}
     link(href="css/style.css", rel="stylesheet", type="text/css")
     link(href="http://fonts.googleapis.com/css?family=Lato:300,400,700,900,700italic|Open+Sans:700italic,400,600,300,700,800", rel="stylesheet", type="text/css")
   body
@@ -12,13 +12,13 @@ html
         .header
           h1
             strong #{community}
-          h2 Enter your email below to join #{community} on slack!
+          h2 #{__('HEADER', community)}
         .content
           .information
             form(method="POST", action="/invite")#join-form.form
-              input(type="text", name="email", placeholder="Enter Your Email Address")#slack-email.field
+              input(type="text", name="email", placeholder="#{__('ENTER_EMAIL')}")#slack-email.field
               if tokenRequired
-                input(type="text", name="token", placeholder="Enter the invite token you were given")#slack-token.field
+                input(type="text", name="token", placeholder="#{__('ENTER_TOKEN')}")#slack-token.field
               input(type="submit", value="Join").submit
     script.
       var tokenRequired = #{tokenRequired};

+ 1 - 1
views/result.jade

@@ -3,7 +3,7 @@ html
   head
     meta(http-equiv="Content-Type", content="text/html; charset=utf-8")
     meta(name="viewport", content="width=device-width, initial-scale=1")
-    title Join the #{community} community on Slack!
+    title #{__('TITLE', community)}
     link(href="css/style.css", rel="stylesheet", type="text/css")
     link(href="http://fonts.googleapis.com/css?family=Lato:300,400,700,900,700italic|Open+Sans:700italic,400,600,300,700,800", rel="stylesheet", type="text/css")
   body