Permalink
Browse files

First draft of the 'linguac' helper for dynamic data.

  • Loading branch information...
1 parent 11499a0 commit eff41e6a637299e6071662e33a70dd8630494e25 @akoenig committed Feb 16, 2012
View
@@ -37,17 +37,22 @@ app.configure(function(){
});
app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
- app.use(express.errorHandler());
+ app.use(express.errorHandler());
});
// Routes
-app.get('/', function(req, res){
- res.render('index');
+app.get('/', function(req, res) {
+ res.render('index', {
+ person: {
+ name: 'Thomas',
+ age: Math.round(Math.random()*100)
+ }
+ });
});
app.listen(3000);
View
@@ -8,6 +8,7 @@
"index": {
"headline": "Hallo.",
"subheadline": "Dies ist eine kleine App, welche die Funktionsweise von lingua demonstrieren soll.",
- "licence": "MIT-Lizenz"
+ "licence": "MIT-Lizenz",
+ "person": "Hallo {name}. Du bist {age} Jahre alt."
}
}
View
@@ -8,6 +8,7 @@
"index": {
"headline": "Hello.",
"subheadline": "This is a little app which should demonstrate the functionality of lingua.",
- "licence": "MIT licence"
+ "licence": "MIT licence",
+ "person": "Hey {name}. You are {age} years old."
}
}
View
@@ -3,7 +3,7 @@
, "version": "0.0.2"
, "private": true
, "dependencies": {
- "express": "2.4.6"
+ "express": "2.5.8"
, "jqtpl": ">= 1.0.0"
}
}
@@ -57,6 +57,10 @@ article h2 {
line-height:1.3em
}
+article p {
+ margin-top:50px;
+}
+
footer {
bottom:10px;
position:absolute;
View
@@ -12,4 +12,6 @@
<h2>${lingua.index.subheadline}</h2>
</hgroup>
</header>
+
+ <p>${linguac(lingua.index.person, person)}</p>
</article>
View
@@ -111,6 +111,31 @@ module.exports = function(app, options) {
});
//
+ // DOCME
+ //
+ app.locals({
+ linguac: function(i18n, data) {
+ var compile = function(resource, data) {
+ if (typeof data === 'object') {
+ for(var param in data) {
+ resource = resource.replace(new RegExp('{'+param+'}','g'), data[param]);
+ }
+ } else {
+ resource = resource.replace(/\{(\w*)\}/g, data);
+ }
+
+ return resource;
+ };
+
+ if (data) {
+ i18n = compile(i18n, data);
+ }
+
+ return i18n;
+ }
+ });
+
+ //
// summary:
// The middleware function.
//
View
@@ -1,7 +1,7 @@
{
"name": "lingua",
"description": "A i18n middleware for the Express.js framework.",
- "version": "0.2.1",
+ "version": "0.3.0",
"repository": {
"type": "git",
"url": "git://github.com/akoenig/express-lingua.git"

0 comments on commit eff41e6

Please sign in to comment.