Permalink
Browse files

Update example app

  • Loading branch information...
1 parent 2571ffb commit 2dc417ad9ac0a9b4ac21ed738b1196e461498340 @ricardobeat committed Feb 17, 2013
Showing with 82 additions and 136 deletions.
  1. +0 −54 example/app.coffee
  2. +56 −69 example/app.js
  3. +10 −0 example/lang/en-UK.json
  4. +6 −5 example/lang/pt.json
  5. +6 −4 example/package.json
  6. +4 −4 example/views/index.html
View
@@ -1,54 +0,0 @@
-http = require 'http'
-express = require 'express'
-hbs = require 'hbs'
-i18n = require '../'
-
-# Application settings
-# ---------------------
-
-app = express()
-server = http.createServer(app)
-
-hbs.registerHelper "equals", (a, b, options) ->
- return if a == b then options.fn(@) else options.inverse(@)
-
-hbs.registerHelper "_", i18n.translate
-
-app.configure ->
- app.set 'root', __dirname
- app.set 'view engine', 'html'
- app.engine 'html', hbs.__express
-
- app.use express.cookieParser()
- app.use express.cookieSession secret: 'trolololol'
- app.use i18n({ debug: true })
- app.locals i18n.locals
- app.use app.router
- app.use express.static "#{__dirname}/public"
-
-app.configure 'development', ->
- app.use i18n.updateStrings
- app.use express.errorHandler
- dumpExceptions: true
- showStack: true
-
-# Default pages
-# --------------
-
-# Home
-app.get '/', (req, res) ->
- res.render 'index'
-
-app.get '/clear', (req, res) ->
- req.session = null
- res.redirect '/'
-
-# Switch languages
-# -----------------
-
-app.get '/lang/:lang', (req, res) ->
- i18n.setLanguage req.session, req.params.lang
- res.redirect req.headers.referer || '/'
-
-server.listen 4567
-console.log "Server listening @ 4567"
View
@@ -1,69 +1,56 @@
-// Generated by CoffeeScript 1.4.0
-(function() {
- var app, express, hbs, http, i18n, server;
-
- http = require('http');
-
- express = require('express');
-
- hbs = require('hbs');
-
- i18n = require('../i18n');
-
- app = express();
-
- server = http.createServer(app);
-
- hbs.registerHelper("equals", function(a, b, options) {
- if (a === b) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
-
- hbs.registerHelper("_", i18n.translate);
-
- app.configure(function() {
- app.set('root', __dirname);
- app.set('view engine', 'html');
- app.engine('html', hbs.__express);
- app.use(express.cookieParser());
- app.use(express.cookieSession({
- secret: 'trolololol'
- }));
- app.use(i18n({
- debug: true
- }));
- app.locals(i18n.locals);
- app.use(app.router);
- return app.use(express["static"]("" + __dirname + "/public"));
- });
-
- app.configure('development', function() {
- app.use(i18n.updateStrings);
- return app.use(express.errorHandler({
- dumpExceptions: true,
- showStack: true
- }));
- });
-
- app.get('/', function(req, res) {
- return res.render('index');
- });
-
- app.get('/clear', function(req, res) {
- req.session = null;
- return res.redirect('/');
- });
-
- app.get('/lang/:lang', function(req, res) {
- i18n.setLanguage(req.session, req.params.lang);
- return res.redirect(req.headers.referer || '/');
- });
-
- server.listen(4567);
-
- console.log("Server listening @ 4567");
-
-}).call(this);
+var http = require('http')
+ , express = require('express')
+ , hbs = require('hbs')
+ , i18n = require('../')
+
+// Application settings
+// ---------------------
+
+var app = express()
+ , server = http.createServer(app)
+
+hbs.registerHelper("equals", function (a, b, options) {
+ return a == b ? options.fn(this) : options.inverse(this)
+})
+
+// Register handlebar translation method
+hbs.registerHelper("_", i18n.translate)
+
+app.configure(function(){
+ app.set('root', __dirname)
+ app.set('view engine', 'html')
+ app.engine('html', hbs.__express)
+
+ app.use(express.cookieParser())
+ app.use(express.cookieSession({ secret: 'trolololol' }))
+
+ app.use(i18n({ debug: true }))
+ app.locals(i18n.locals)
+
+ app.use(app.router)
+ app.use(express.static(__dirname + "/public"))
+})
+
+app.configure('development', function(){
+ app.use(i18n.updateStrings)
+ app.use(express.errorHandler({
+ dumpExceptions: true
+ , showStack: true
+ }))
+})
+
+// Routes
+// -------
+
+app.get('/', function (req, res) {
+ res.render('index')
+})
+
+// Set language
+app.get('/lang/:lang', function (req, res) {
+ i18n.setLanguage(req.session, req.params.lang)
+ res.redirect(req.headers.referer || '/')
+})
+
+server.listen(4567)
+console.log("Server listening @ 4567")
View
@@ -0,0 +1,10 @@
+{
+ "cookie": "biscuit",
+ "bacon": "bacon",
+ "and": "&",
+ "coffee": "tea",
+ "%s glasses": "%s cups",
+ "%s glass": "%s cup",
+ "no glasses": "no cups",
+ "of water": ""
+}
View
@@ -1,9 +1,10 @@
{
- "%s cup": "%s xícara",
- "%s cups": "%s xícaras",
- "no cups": "nenhuma xícara",
"cookie": "biscoito",
"bacon": "bacon",
- "tea": "chá",
- "and": "e"
+ "coffee": "café",
+ "and": "e",
+ "%s glass": "%s xícara",
+ "%s glasses": "%s xícaras",
+ "no glasses": "nenhuma xícara",
+ "of water": "de água"
}
View
@@ -1,11 +1,13 @@
{
- "name": "polyglot",
- "version": "0.2.0",
+ "name": "polyglot-example",
+ "private": true,
+ "version": "0.0.0",
"author": "Ricardo Tomasi <ricardobeat@gmail.com>",
"engines": {
- "node": ">v0.4.5"
+ "node": "~v0.8"
},
"dependencies": {
- "express": ""
+ "express": "",
+ "hbs": ""
}
}
View
@@ -23,11 +23,11 @@ <h1 id="logo">polyglot test</h1>
<section id="main">
<section id="content">
<h2>{{_ "cookie" }}</h2>
- <p>{{_ "bacon" }} {{_ "and" }} {{_ "tea" }}</p>
+ <p>{{_ "bacon" }} {{_ "and" }} {{_ "coffee" }}</p>
<ul></ul>
- <li>{{_ 3 "%s cup" "%s cups" }}</li>
- <li>{{_ 1 "no cups" "%s cup" "%s cups" }}</li>
- <li>{{_ 0 "no cups" "%s cup" "%s cups" }}</li>
+ <li>{{_ 3 "%s glass" "%s glasses" }} {{_ "of water" }}</li>
+ <li>{{_ 1 "no glasses" "%s glass" "%s glasses" }} {{_ "of water" }}</li>
+ <li>{{_ 0 "no glasses" "%s glass" "%s glasses" }} {{_ "of water" }}</li>
</section>
</section>

0 comments on commit 2dc417a

Please sign in to comment.