Skip to content

Add new Helper for current language #2

Description

@instance-pro

If you need to get the current path without locale use this Fix

Add to: var options = _.extend({
, 'helper_path_current' : '__c'

Add to: this.middleware = function(req, res, next){
res.locals[self.options['helper_path_current']] = self.pathCurrentHelper(req.path);

Add to: var i18n = function(){
this.pathCurrentHelper = function(path) {
return function(locale) {
var current = path.replace(new RegExp("^(/("+self.options.enabled.join("|")+"))?", "i"), '');
if(locale!=undefined)
locale = locale.replace(///, '');
var langIndex = self.options.enabled.indexOf(locale);
if(langIndex>=0&&self.options.default!=locale)
current = '/' + self.options.enabled[langIndex] + current;
return current;
};
};

You can use __c() you get the current Path without locale.
If you would change current path to a locale use it like __c('de'), __('en')...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions