Skip to content

Define language directory dynamically #16

@ghost

Description

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`,
} ) );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions