Browse files

Adding express v2 example

  • Loading branch information...
1 parent fa2c6b4 commit 53013c5848d200364ec28922261808fdb8694c5a @ozten ozten committed Dec 14, 2012
View
12 README.md
@@ -59,25 +59,25 @@ i18n-abide provides ``lib/gettext.js`` and you can do the same in ``.js`` and ``
## Setup Gettext
$ mkdir -p locale/templates/LC_MESSAGES
- $ ./node_modules/.bin/extract-pot --locale locale ./server
+ $ ./node_modules/.bin/extract-pot --locale locale .
If you look in ``locale/templates/LC_MESSAGES/messages.pot`` you will see your strings have been extracted.
Edit this file and make sure ``charset`` is set to ``UTF-8``.
If there are certain files or directories you want to exclude, use `--exclude` one or more times. Example:
- $ extract-pot --locale locale ./server --exclude tests --exclude examples
+ $ extract-pot --locale locale . --exclude tests --exclude examples
Example messages.pot:
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
- #: server/routes.js:81
+ #: ./routes.js:81
msgid "Hey, careful, man, there's a beverage here!"
msgstr ""
- #: server/views/404.ejs:5
+ #: views/404.ejs:5
msgid "This will not stand, ya know, this aggression will not stand, man."
msgstr ""
@@ -115,11 +115,11 @@ Example: ``locale/db_LB/LC_MESSAGES/messages.po``
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
- #: server/routes.js:81
+ #: routes.js:81
msgid "Hey, careful, man, there's a beverage here!"
msgstr "‮Hǝʎ´ ɔɐɹǝɟnʅ´ ɯɐu´ ʇɥǝɹǝ,s ɐ qǝʌǝɹɐƃǝ ɥǝɹǝ¡"
- #: server/views/404.ejs:5
+ #: views/404.ejs:5
msgid "This will not stand, ya know, this aggression will not stand, man."
msgstr "‮⊥ɥıs ʍıʅʅ uoʇ sʇɐup´ ʎɐ ʞuoʍ´ ʇɥıs ɐƃƃɹǝssıou ʍıʅʅ uoʇ sʇɐup´ ɯɐu·"
View
23 bin/extract-pot
@@ -34,11 +34,16 @@ argv._.forEach(function (dir) {
// top of repo is our current working directory
process.chdir(path.dirname(__dirname));
-var jsCmd = './node_modules/.bin/jsxgettext %s --keyword=_ -L JS ' +
+console.log('My Path is ', __dirname);
+var jsxGettextPath = path.join(__dirname, '../node_modules/.bin/jsxgettext');
+
+console.log(jsxGettextPath);
+
+var jsCmd = jsxGettextPath + ' %s --keyword=_ -L JS ' +
'--output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.js\' | grep -v node_modules | grep -v .git';
-var ejsCmd = './node_modules/.bin/jsxgettext %s --keyword=_ -L EJS ' +
+var ejsCmd = jsxGettextPath + ' %s --keyword=_ -L EJS ' +
'--output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.ejs\' | grep -v node_modules | grep -v .git';
@@ -63,22 +68,22 @@ var dashJ = '';
async.forEachSeries(sourceDirs, function (dir) {
exec(util.format(jsCmd, dashJ, localeDir, dir), function (err, stdout, stderr) {
// Join existing pot file
- dashJ = '--join-existing=true';
+ dashJ = ' --join-existing=true ';
- if (err) {
- console.error(err);
+ // We expect an error if no gettext strings are used in client side code
+ if (err && stdout.indexOf('input argument is required') === -1) {
+ console.error(stdout);
+ console.error(stderr);
} else {
exec(util.format(ejsCmd, dashJ, localeDir, dir), function (err, stdout, stderr) {
if (err) {
- console.log(util.format(ejsCmd, dashJ, localeDir, dir));
- console.error(err);
+ console.error(stdout);
+ console.error(stderr);
}
-
});
}
});
}, function (err) {
- console.log('===========');
if (err) {
console.error(err);
}
View
2 bin/po2json.js
@@ -89,7 +89,7 @@ var parse_po = function(data) {
}
// comments
- } else if (/^(#[^~]|#$)/.test(lines[i])) {
+ } else if (/^(#|#$)/.test(lines[i])) {
continue;
// msgctxt
View
43 examples/express2/app.js
@@ -0,0 +1,43 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express'),
+ i18n = require('i18n-abide'),
+ routes = require('./routes');
+
+var app = module.exports = express.createServer();
+
+// Configuration
+
+app.configure(function(){
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'ejs');
+ app.use(i18n.abide({
+ supported_languages: ['en-US', 'de', 'es', 'db-LB', 'it-CH'],
+ default_lang: 'en-US',
+ debug_lang: 'it-CH',
+ locale_directory: 'locale'
+ }));
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ app.use(express.errorHandler());
+});
+
+// Routes
+
+app.get('/', routes.index);
+
+app.listen(3000, function(){
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+});
View
BIN examples/express2/locale/db_LB/LC_MESSAGES/messages.mo
Binary file not shown.
View
22 examples/express2/locale/db_LB/LC_MESSAGES/messages.po
@@ -0,0 +1,22 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-06-24 09:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: /home/ozten/i18n-abide/examples/express2/views/index.ejs:1
+msgid "Hello, world!"
+msgstr "‮Hǝʅʅo´ ʍoɹʅp¡"
View
BIN examples/express2/locale/de/LC_MESSAGES/messages.mo
Binary file not shown.
View
22 examples/express2/locale/de/LC_MESSAGES/messages.po
@@ -0,0 +1,22 @@
+# German translations for express package.
+# Copyright (C) 2012 THE express'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the express package.
+# Austin King <shout@ozten.com>, 2012.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: express 2\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-06-24 09:50+0200\n"
+"PO-Revision-Date: 2012-12-14 10:48-0800\n"
+"Last-Translator: Austin King <shout@ozten.com>\n"
+"Language-Team: German\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: /home/ozten/i18n-abide/examples/express2/views/index.ejs:1
+msgid "Hello, world!"
+msgstr "Hallo Welt"
View
BIN examples/express2/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
View
22 examples/express2/locale/en_US/LC_MESSAGES/messages.po
@@ -0,0 +1,22 @@
+# English translations for express package.
+# Copyright (C) 2012 THE express'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the express package.
+# Austin King <shout@ozten.com>, 2012.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: express 2\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-06-24 09:50+0200\n"
+"PO-Revision-Date: 2012-12-14 10:49-0800\n"
+"Last-Translator: Austin King <shout@ozten.com>\n"
+"Language-Team: English\n"
+"Language: en_US\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: /home/ozten/i18n-abide/examples/express2/views/index.ejs:1
+msgid "Hello, world!"
+msgstr "Hello, world!"
View
BIN examples/express2/locale/es/LC_MESSAGES/messages.mo
Binary file not shown.
View
22 examples/express2/locale/es/LC_MESSAGES/messages.po
@@ -0,0 +1,22 @@
+# Spanish translations for express package.
+# Copyright (C) 2012 THE express'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the express package.
+# Austin King <shout@ozten.com>, 2012.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: express 2\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-06-24 09:50+0200\n"
+"PO-Revision-Date: 2012-12-14 10:49-0800\n"
+"Last-Translator: Austin King <shout@ozten.com>\n"
+"Language-Team: Spanish\n"
+"Language: es\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: /home/ozten/i18n-abide/examples/express2/views/index.ejs:1
+msgid "Hello, world!"
+msgstr "¡Hola mundo!"
View
23 examples/express2/locale/templates/LC_MESSAGES/messages.pot
@@ -0,0 +1,23 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-06-24 09:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: /home/ozten/i18n-abide/examples/express2/views/index.ejs:1
+msgid "Hello, world!"
+msgstr ""
+
View
10 examples/express2/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "application-name",
+ "version": "0.0.1",
+ "private": true,
+ "dependencies": {
+ "express": "2.5.8",
+ "ejs": ">= 0.0.1",
+ "i18n-abide": ">= 0.0.7"
+ }
+}
View
8 examples/express2/public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
View
8 examples/express2/routes/index.js
@@ -0,0 +1,8 @@
+
+/*
+ * GET home page.
+ */
+
+exports.index = function(req, res){
+ res.render('index', { title: 'Express' })
+};
View
1 examples/express2/views/index.ejs
@@ -0,0 +1 @@
+<h1><%= gettext("Hello, world!") %></h1>
View
2 examples/express2/views/index.ejs~
@@ -0,0 +1,2 @@
+<h1><%= title %></h1>
+<p>Welcome to <%= title %></p>
View
10 examples/express2/views/layout.ejs
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="<%= lang %>" dir="<%= lang_dir %>">
+ <head>
+ <title><%= title %></title>
+ <link rel='stylesheet' href='/stylesheets/style.css' />
+ </head>
+ <body>
+ <%- body %>
+ </body>
+</html>
View
10 examples/express2/views/layout.ejs~
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= title %></title>
+ <link rel='stylesheet' href='/stylesheets/style.css' />
+ </head>
+ <body>
+ <%- body %>
+ </body>
+</html>

0 comments on commit 53013c5

Please sign in to comment.