Skip to content

Commit

Permalink
chore: remove global and fix references
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunwarman committed May 24, 2020
1 parent 016de87 commit 0a9e4a4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const { getLanguage } = require('country-language');
const { isEmpty, sortBy, every, isFunction } = require('lodash');
const { stringify } = require('qs');

// expose global
i18n.api = {};

class I18N {
constructor(config = {}) {
this.config = Object.assign(
Expand Down Expand Up @@ -43,7 +40,6 @@ class I18N {
__h: 'th',
__mf: 'tmf'
},
register: i18n.api,
lastLocaleField: 'last_locale',
ignoredRedirectGlobs: [],
redirectIgnoresNonGetMethods: true,
Expand Down Expand Up @@ -96,7 +92,7 @@ class I18N {
const phrase = phrases[key];
if (typeof phrase !== 'string')
throw new Error(`translation key missing: ${key}`);
return i18n.api.t({ phrase, locale }, ...args);
return this.api.t({ phrase, locale }, ...args);
}

translateError(key, locale, ...args) {
Expand All @@ -110,7 +106,7 @@ class I18N {
const { locales, defaultLocale, phrases, cookie } = this.config;

// expose api methods to `ctx.request` and `ctx.state`
i18n.init(ctx.request, ctx.state);
this.init(ctx.request, ctx.state);

// expose a helper function to `ctx.state.l`
// which prefixes a link/path with the locale
Expand Down Expand Up @@ -171,7 +167,7 @@ class I18N {
}

// set the locale properly
i18n.setLocale([ctx.request, ctx.state], locale);
this.setLocale([ctx.request, ctx.state], locale);
ctx.locale = ctx.request.locale;
ctx.set('Content-Language', ctx.locale);

Expand Down

0 comments on commit 0a9e4a4

Please sign in to comment.