Comments (2)
Well I think it works, indeed.
If you use subdomains you can manage it in Cortex using host()
method in route definition and inside query, access the subdomain set in the $matches
array.
This is not documented in Cortex docs, because it is a Symphony routing component feature (see point 5 here).
If you use subdirectory you can use a route variable for it.
Example for subdomains:
Brain\Routes::add( '/{page}' )
->host( '{lang}.example.com' )
->defaults( [ 'lang' => 'en' ] )
->query( function( $matches ) {
// $matches['lang'] contain the language, e.g. "en", "it", "es" and so on
return [
'post_type' => 'page',
'name' => $matches['page'],
];
});
Example for directories:
Brain\Routes::add( '{lang}/{page}' )
->defaults( [ 'lang' => 'en' ] )
->query( function( $matches ) {
// $matches['lang'] contain the language, e.g. "en", "it", "es" and so on
return [
'post_type' => 'page',
'name' => $matches['page'],
];
});
WPML _should_ set automatically the language and properly show result.
Consider that, internally, a route like that is very similar to a WordPress "standard" rewrite rule and, if I'm not wrong, WPML works with custom rewrite rules.
However it isn't tested, and I can't test it at the moment.
If you can, I would be happy to know if it works and help you to find a solution if not.
Consider that a route group will not work, because as you can read in docs:
Properties set in the group are merged with route properties when the route matched: it makes no sense put in the group properties that act on route matching process (like requirements, defaults…) because when the group is merged matching already happen.
and once host and directory act on route matching, you can use them in route groups.
However, consider that you can create your own route class extendind the default in a way that the language is automatically set to all routes.
from cortex.
Hi @meszarosrob once I get no response in a long time, I'm going to close this issue. If you still have some issues feel free to re-open it. Thanks.
from cortex.
Related Issues (20)
- Overriding `template_include` hook HOT 6
- Sage 9 Integration HOT 6
- Simple example not fired. HOT 1
- About template HOT 2
- [Question] Is there any way to give Cortext routes a higher priority over WP routes? HOT 5
- Preserving variables? HOT 1
- [Question] could you describe how to do a paginated route? HOT 1
- [feature request] Closures as a value for the `template` setting HOT 4
- Render specific post/page/tax archive HOT 1
- How to add body classes depending on a Cortex route - the right way. HOT 2
- Current status for this project? HOT 4
- AJAX requests handling - how to set up CORS? HOT 3
- Routes "players" and "players/" are treated as same url HOT 2
- Handle 404 error HOT 2
- Abandoned packages and Parse error | PHP 8.0.11 HOT 1
- post__in not working HOT 1
- Wordpress 6 Changing on do_parse_request HOT 1
- Issue with wordpress v6 HOT 4
- get_post() does not work
- PHP dependency conflict: "psr/http-message" now requires PHP 7.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cortex.