Giter Site home page Giter Site logo

Comments (2)

xfra35 avatar xfra35 commented on August 17, 2024

Hey Thibault, glad you like it =)

As for looping through the URLs of the current page translations, you can use the plugin alias function, which is a superset of the framework's own alias function, taking one extra $lang parameter.

In the demo, it is basically achieved like this:

$f3=Base::instance();
$ml=Multilang::instance();
foreach($ml->languages as $lang)
  echo $ml->alias($f3->ALIAS,NULL,$lang);//<-- translated page path

As you can see, the 2nd parameter is null, because the demo routes don't hold any dynamic token.

If you have dynamic tokens, you need to fill in the 2nd parameter. And the way to go depends on your app's architecture:

  • If routes parameters are identical for each language (e.g: /en/area/web and /fr/zone/web share a common language-independant web token), then just use $f3->PARAMS as a 2nd parameter, as it holds the current language parameters.
  • If routes contain a translatable slug but are anyway identified by a numerical index (e.g: /en/blog/8/hey-dude and /fr/blog/8/salut-gros are translations of the same page identified by the token id=8), then you can also use $f3->PARAMS as your app will naturally performs appropriate redirections (/fr/blog/8/hey-dude => /fr/blog/8/salut-gros).
  • If routes contain translatable slugs with no common index, then each controller has to generate its own translated URLs, because only it knows the values of the translated slugs.

Hope it makes sense ^^

from f3-multilang.

thfontaine avatar thfontaine commented on August 17, 2024

Hey Florent,
Thank you for your very clear answer. It works like a charm ! 👍
Your work is very appreciated.

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.