Giter Site home page Giter Site logo

Comments (2)

xfra35 avatar xfra35 commented on August 17, 2024 1

That's because you're calling the alias() method with the 2nd parameter not set, which is the same as passing the current route parameters.

You need somehow to pass the localized parameters to the function.

One way of doing it is to create a template filter which localizes the parameter before calling the alias() method.

E.g:

// index.php or bootstrap file or controller hook method
$tpl = Template::instance();
$tpl->filter('url', function($name, $params=NULL, $lang=NULL) use($f3, $ml, $db) {
  $params += $f3->PARAMS;
  // your custom params localization here:
  switch ($name) {
    case 'gamessection':
      // localize the term contained in $params['section'] from $ml->current to $lang
      // e.g:
      $sql = 'SELECT target.slug FROM sections source LEFT JOIN sections target
              ON source.id=target.id WHERE source.slug=?
              AND source.lang=? AND target.lang=?';
      if ($res=$db->exec($sql, [1=>$params['section'], $ml->current, $lang])
        $params['section'] = $res[0]['slug'];
      break;
    // etc.
  }
  // end of custom localization
  return $f3->BASE . $ml->alias($name, $params, $lang);
});
<!-- template file -->
<a title="GamesSite - English" href="{{ @ALIAS, null, 'en' | url }}">English</a>

from f3-multilang.

djadomi avatar djadomi commented on August 17, 2024

Thanks for your detailed answer. I'd left the 2nd parameter as null because I had no way to fill it in correctly as yet. I'll look into making a custom filter as you suggest.

Cheers

from f3-multilang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.