Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed May 8, 2017
1 parent ed10548 commit 76dc8df
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
14 changes: 7 additions & 7 deletions lib/context.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const pluralize = require('./pluralize.js')

class I18nContext {
constructor (repository, locale, templateData, config) {
constructor (repository, languageCode, templateData, config) {
this.repository = repository
this.currentLocale = locale
this.languageCode = languageCode
this.config = config
this.defaultContext = templateData
}
Expand All @@ -14,13 +14,13 @@ class I18nContext {

locale (localeCode) {
if (!localeCode) {
return this.currentLocale
return this.languageCode
}
this.currentLocale = localeCode
this.languageCode = localeCode
}

t (resourceKey, context) {
let template = this.getResource(`${this.currentLocale}.${resourceKey}`)
let template = this.getResource(`${this.languageCode}.${resourceKey}`)
if (!template) {
if (!this.config.allowMissing) {
throw new Error(`Resource '${resourceKey}' not found`)
Expand All @@ -31,8 +31,8 @@ class I18nContext {
}
}
return template(Object.assign({
__locale: this.currentLocale,
pluralize: pluralize(this.currentLocale)
__locale: this.languageCode,
pluralize: pluralize(this.languageCode)
}, this.defaultContext, context))
}
}
Expand Down
11 changes: 5 additions & 6 deletions lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ class I18n {

middleware () {
return (ctx, next) => {
let locale = this.config.defaultLocale
let languageCode = ctx.from && ctx.from.language_code
? ctx.from.language_code.split('-')[0]
: this.config.defaultLocale
let sessionName = this.config.sessionName
if (ctx[sessionName] && ctx[sessionName].__i18n && ctx[sessionName].__i18n.locale) {
locale = ctx[sessionName].__i18n.locale
languageCode = ctx[sessionName].__i18n.locale
}
ctx.i18n = this.createContext(locale, {
from: ctx.from,
chat: ctx.chat
})
ctx.i18n = this.createContext(languageCode, { from: ctx.from, chat: ctx.chat })
return next().then(() => {
if (ctx[sessionName]) {
ctx[sessionName].__i18n = {
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
"telegraf": "^2.0.0 || ^3.0.0"
},
"devDependencies": {
"ava": "^0.16.0",
"ava": "^0.19.1",
"eslint": "^3.7.0",
"eslint-config-standard": "^6.2.0",
"eslint-plugin-ava": "^3.1.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.1",
"should": "^11.1.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-ava": "^4.2.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-node": "^4.2.2",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"telegraf": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ Telegraf user context props and functions:
app.use((ctx) => {
ctx.i18n.locale() // Get current locale
ctx.i18n.locale(code) // Set current locale
ctx.i18n.t(resourceKey, [context]) // Get resource value (context will be used by Handlebars)
ctx.i18n.t(resourceKey, [context]) // Get resource value (context will be used by template engine)
});
```
3 changes: 1 addition & 2 deletions test/i18n.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require('should')
const test = require('ava')

test('', (t) => {

t.pass()
})

0 comments on commit 76dc8df

Please sign in to comment.