Skip to content

Commit

Permalink
added sample for localized routes
Browse files Browse the repository at this point in the history
  • Loading branch information
benmarten committed Dec 14, 2014
1 parent e32c86f commit 28685ff
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 55 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ new.ns.*

# Can also ignore all directories and files in a directory.
node_modules
node_modules/**/*
node_modules/**/*

*.log
11 changes: 11 additions & 0 deletions sample/imprint.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
doctype html
html(lang=i18n.lng())
head
title i18next sample
script(src="http://code.jquery.com/jquery-1.7.min.js", type="text/javascript")
script(src='i18next/i18next.js', type='text/javascript')

body
h1 Localized Route
span= i18n.lng() + '/'
span= t('route.imprint')
10 changes: 10 additions & 0 deletions sample/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ html(lang=i18n.lng())
|  
a#de(href='/?setLng=de-DE') de-DE

h3 you can use also localized routes, e.g.:
a#en(href='/en') /en
br
a#en(href='/en/' + t('route.imprint', { 'lng': 'en' })) /en/imprint
br
br
a#de(href='/de') /de
br
a#de(href='/de/' + t('route.imprint', { 'lng': 'de' })) /de/impressum

h3 go to online editor
a(href='/i18next') webtranslate

Expand Down
28 changes: 14 additions & 14 deletions sample/locales/de-DE/ns.special.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"nav": {
"home": "home de",
"1": "link 1 de",
"2": "link 2 de"
},
"app": {
"name": "i18n",
"insert": "du bist __youAre__",
"child": "__count__ Kind",
"child_plural": "__count__ Kinder",
"friend_context": "Ein Freund",
"friend_context_male": "Ein Freund",
"friend_context_female": "Eine Freundin"
}
"nav": {
"home": "home de",
"1": "link 1 de",
"2": "link 2 de"
},
"app": {
"name": "i18n",
"insert": "du bist __youAre__",
"child": "__count__ Kind",
"child_plural": "__count__ Kinder",
"friend_context": "Ein Freund",
"friend_context_male": "Ein Freund",
"friend_context_female": "Eine Freundin"
}
}
14 changes: 8 additions & 6 deletions sample/locales/de/ns.special.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"app": {
"area": "Area 51",
"district": "District 9 ist spassiger als $t(app.area)"
}
}

"route": {
"imprint": "impressum"
},
"app": {
"area": "Area 51",
"district": "District 9 ist spassiger als $t(app.area)"
}
}
22 changes: 11 additions & 11 deletions sample/locales/dev/ns.common.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"app": {
"company": {
"name": "my company"
}
},
"attr": {
"placeholder": "translated placeholder",
"title": "translated title"
},
"add": "add",
"sprintf": "Hello %s, %s, %s and %s"
"app": {
"company": {
"name": "my company"
}
},
"attr": {
"placeholder": "translated placeholder",
"title": "translated title"
},
"add": "add",
"sprintf": "Hello %s, %s, %s and %s"
}
16 changes: 8 additions & 8 deletions sample/locales/dev/ns.special.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"nav": {
"home": "home",
"1": "link 1",
"2": "link 2"
},
"btn": {
"hoverMe": "hover me!"
}
"nav": {
"home": "home",
"1": "link 1",
"2": "link 2"
},
"btn": {
"hoverMe": "hover me!"
}
}
18 changes: 9 additions & 9 deletions sample/locales/en-US/ns.special.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"app": {
"name": "i18n",
"insert": "you are __youAre__",
"child": "__count__ child",
"child_plural": "__count__ children",
"friend_context": "A friend",
"friend_context_male": "A boyfriend",
"friend_context_female": "A girlfriend"
}
"app": {
"name": "i18n",
"insert": "you are __youAre__",
"child": "__count__ child",
"child_plural": "__count__ children",
"friend_context": "A friend",
"friend_context_male": "A boyfriend",
"friend_context_female": "A girlfriend"
}
}
14 changes: 8 additions & 6 deletions sample/locales/en/ns.special.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"app": {
"area": "Area 51",
"district": "District 9 is more fun than $t(app.area)"
}
}

"route": {
"imprint": "imprint"
},
"app": {
"area": "Area 51",
"district": "District 9 is more fun than $t(app.area)"
}
}
6 changes: 6 additions & 0 deletions sample/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ i18n.init({
saveMissing: true,
debug: true,
sendMissingTo: 'fallback',
preload: ['en', 'de'],
detectLngFromPath: 0
}, function(t) {

Expand All @@ -75,6 +76,11 @@ i18n.init({
res.render('index');
});

i18n.addRoute('/:lng/route.imprint', ['en', 'de'], app, 'get', function(req, res) {
console.log("localized imprint route");
res.render('imprint');
});

});

// Configuration
Expand Down

0 comments on commit 28685ff

Please sign in to comment.