Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define language directory dynamically #16

Open
ghost opened this issue Sep 2, 2018 · 0 comments
Open

Define language directory dynamically #16

ghost opened this issue Sep 2, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 2, 2018

As asked in #11, then my question is pretty much the same, I use Nunjucks to have multiple themes on the same instance, that be, a frontend theme and a backend theme.

The language files should be a part of the theme directory and not something you store globally outside the theme itself.

As per now, the theme is defined in a middleware and set in a state, and used by all other elements.

app.use( function( ctx, next ) {
  ctx.state.theme = 'default';
  await next();
} );

How would I go about accessing ctx.state.theme when initializing koa-i18n inside the middleware, pseudo example code

app.use( i18n( app, {
  directory: `./themes/${ctx.state.theme}/languages`,
} ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants