sottwell Reply #1, 6 years, 11 months ago
I have been manually editing all snippets to add a value "&lang=$lang" to all links and link-creating code, such as menu snippets. The $lang variable is determined at the top of every snippet with "$lang = isset($_GET['lang'] ? $_GET['lang'] : $modx->config['site_start'];". The $lang variable is initially determined by the docID of the root folder acting as home page and containing the content pages for that langauge, as selected from a menu generated by a simple list menu snippet using 0 as its base and that does have its links modifed to seed the $lang variable into the system. The language files are also simply named after the same root docID. If it's the initial visit to the site, or for some reason the query string value gets lost, it defaults to the site_start document ID.
This works well, but is really not desireable. It seems to me that I could use a plugin on the DocumentPreRender event to add the value to the query string of all links on the page. If I understand this correctly, I can do something like the "filter words" plugin example in the documentation. I would use a regular expression to find all "<a href=.....> and add the query string value at the end of the text before the final ">".
Am I on the right track here? And can somebody recommend a good site for a crash course on regular expressions? I already tried hacking the core in the rewriteURLs function, and that worked, but it ended up with multiple "lang" fields in the query string, and while the last one was the desired one and it worked, it's sloppy, and besides, I don't want to have to have a hacked core for this to work. This way, all I'd need is one modified simple list menu snippet and the plugin for instant multilanguage support. Snippets written to use the feature would simply include their own "snippet/langs/$lang.php" language file as needed.
This works well, but is really not desireable. It seems to me that I could use a plugin on the DocumentPreRender event to add the value to the query string of all links on the page. If I understand this correctly, I can do something like the "filter words" plugin example in the documentation. I would use a regular expression to find all "<a href=.....> and add the query string value at the end of the text before the final ">".
Am I on the right track here? And can somebody recommend a good site for a crash course on regular expressions? I already tried hacking the core in the rewriteURLs function, and that worked, but it ended up with multiple "lang" fields in the query string, and while the last one was the desired one and it worked, it's sloppy, and besides, I don't want to have to have a hacked core for this to work. This way, all I'd need is one modified simple list menu snippet and the plugin for instant multilanguage support. Snippets written to use the feature would simply include their own "snippet/langs/$lang.php" language file as needed.
) simplified, actually functional version: