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

Translating routes #150

Closed
xpepermint opened this issue Apr 3, 2015 · 6 comments
Closed

Translating routes #150

xpepermint opened this issue Apr 3, 2015 · 6 comments

Comments

@xpepermint
Copy link

Please add a function which returns a list of translations for a key (as an array) so we will be able to translate express routes like the example:

var app = express();

function __l(key) {
  var translations = [];
  Object.keys(i18n.getCatalog()).forEach(function(locale) {
    translations.push( i18n.__({phrase: key, locale: locale}) );
  });
  return translations;
}

app.get( __l('/:locale/products/:id?'), function (req, res) {
  req.setLocale( req.params.locale );
  res.render('index');

  // this will match routes
  // /:locale/products/:id?       ... EN
  // /:locale/productos/:id?     ... ES
  // ...
});
@mashpie
Copy link
Owner

mashpie commented Apr 7, 2015

so you'll expect:

var routes = __l('/:locale/products/:id?');

// equals - a)

routes = [
  '/:locale/products/:id?',
  '/:locale/productos/:id?'
];

// or how about - b)

routes = [
  {'en': '/:locale/products/:id?'},
  {'es': '/:locale/productos/:id?'}
];

@xpepermint
Copy link
Author

Let's add the b as a default. If you pass true as the second parameter, you get the a. What do you think?

@xpepermint
Copy link
Author

Even better would be the .inverse() of my proposal :). If you pass true for the second parameter, you get a hash (b) and by default an array is returned (a). What do you think?

@xpepermint
Copy link
Author

@mashpie Which option do you prefer? I would appreciate if you could add this feature into next version. Thanks!

@mashpie
Copy link
Owner

mashpie commented Jan 31, 2016

hmm. liked to catchup with this in next release. Let's see if I manage that

@mashpie
Copy link
Owner

mashpie commented Feb 6, 2016

I think it's best to split:

  • __l() returns a list
  • __h() returns a hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants