Browse Source

Merge pull request #23 from xtuc/master

Internationalization
JeongHoon Byun (aka Outsider) 9 years ago
parent
commit
7b75d923f7
9 changed files with 42 additions and 14 deletions
  1. 1 1
      README.md
  2. 19 6
      app.js
  3. 3 1
      config.js
  4. 6 0
      locales/en.json
  5. 6 0
      locales/fr.json
  6. 1 0
      package.json
  7. 1 1
      views/error.jade
  8. 4 4
      views/index.jade
  9. 1 1
      views/result.jade

+ 1 - 1
README.md

@@ -20,7 +20,7 @@ fill out `config.js` as your infomation.
   **You should generate the token in admin user, not owner.**
   If you generate the token in owner user, `missing_scope` error will be occurred.
 * `inviteToken`: an optional security measure - if it is set, then that token will be required to get invited.
-  Intended to be provided in person or on a whiteboard or something.
+* `locale`: application language (currently `en` and `fr` available).
 
   You can test your token via curl:
 

+ 19 - 6
app.js

@@ -1,14 +1,27 @@
-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({
+    defaultLocale: "en",
+    directory: __dirname + '/locales',
+    autoReload: true
+});
+
+i18n.setLocale(config.locale);
+
+// 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