<![CDATA[ Switching between contexts - My Forums]]> https://forums.modx.com/thread/?thread=28848 <![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155142
Now I can focus on finding the best way of mapping the URLs between languages smiley]]>
LaurentGom Aug 12, 2009, 10:06 AM https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155142
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155141 opengeek Aug 12, 2009, 12:57 AM https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155141 <![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155140
I wrote a plugin that changes the cultureKey according to the current locale, but now I can’t find the OnInitCulture event in the list of system events.]]>
LaurentGom Aug 11, 2009, 01:34 PM https://forums.modx.com/thread/28848/switching-between-contexts?page=2#dis-post-155140
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155139 http://modxcms.com/forums/index.php/topic,37812.msg228284.html#msg228284]]> opengeek Aug 11, 2009, 12:43 PM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155139 <![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155138
setlocale(LC_ALL, ...)

which seems to work fine (if I display the current locale it is "french" under www.mysite.com/fr).

However it doesn’t change anything for MODx: lexicons are still in english and $modx->countryKey is "en".
What am I missing?]]>
LaurentGom Aug 11, 2009, 11:13 AM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155138
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155137 Quote from: LaurentGom at Aug 10, 2009, 05:44 PM

If I don’t use contexts then how do I associate a language/locale to a sub-tree? I still need this for the translated chunks that use lexicons -- at least.
In the same plugin, set the locale; the top-level container in the tree represents the language, so once you detect the top level parent, you know the language. This is no different than in 0.9.x/1.0 (aka Evolution).]]>
opengeek Aug 10, 2009, 06:57 PM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155137
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155136 LaurentGom Aug 10, 2009, 12:44 PM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155136 <![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155135 Quote from: LaurentGom at Aug 10, 2009, 04:00 PM

I’ll try this solution, as I don’t know how to write a plugin yet. If I understand correctly, I’ll also have to change my rewrite rules in .htaccess to map the virtual language folders to the physical ones?
Good point; actually, it may be better to leave the rewrite rules alone for now. We should focus on solving the problem, and then optimizing in this case. You need a plugin to detect the first segment of the requested URL, which will be rewritten into the $_GET[’q’] variable (though ’q’ is configurable in Revolution via $modx->getOption(’request_param_alias’)) when using friendly_urls with mod_rewrite. A plugin like this might be used to do the context switching, assigned to the OnWebPageInit event:
<?php
$lang = 'en';
$pos = strpos($_GET[$modx->getOption('request_param_alias')], '/');
if ($pos > 0) {
    $lang = substr($_GET[$modx->getOption('request_param_alias')], 0, $pos);
}
switch ($lang) {
   case 'fr':
      $modx->switchContext('fr');
      break;
   default:
      // by default, don't do anything
      break;
}
?>

[Please note this is not tested; I just threw this together for example purposes]

But again, if you are just using subfolders, you may not even need to go to the trouble of dividing this into contexts. This is more useful for multi-domain configurations. In your case, just figuring out how to link the translations between folders is all you really need, unless you are going to be serving hundreds/thousands of pages per language.]]>
opengeek Aug 10, 2009, 11:52 AM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155135
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155134 This is managed by Content Type in Revolution. The suffix and prefix from Evo are no longer applicable and are retained there only for the interest of migrations. Ok, I see.

Which is best really depends on your hosting situation. For instance, if you have full control of a dedicated server or VPS, and need more scalability for a large volume of traffic, then using custom index.php’s that directly invoke a specific context will be your best option. This customization is as simple as copying the index.php in the root directory to an fr/ folder and changing the call to $modx->initialize(’web’) to $modx->initialize(’fr’), though you will also need to copy the config.core.php file and make sure the values are correct for the new location.
I’ll try this solution, as I don’t know how to write a plugin yet. If I understand correctly, I’ll also have to change my rewrite rules in .htaccess to map the virtual language folders to the physical ones?

As for linking related nodes across translations, there is nothing built-in for this in 2.0. Again, this depends on your needs and I expect that several solutions to this will materialize as developers implement similar solutions. This could be as simple as creating a TV on the main page which has a comma-delimited list of translated nodes (and possibly a second TV on the translations that point back to main node), or as complex as creating a custom table to map the relations explicitly.

Once we get to our initial RC releases of Revolution, I’m sure we will be providing sample solutions for these issues. For the time being, your exploration of the subject is a pioneering effort, though greatly appreciated.
Thanks for the hints. I’ll post back here once I’ve made all this stuff work smiley]]>
LaurentGom Aug 10, 2009, 11:00 AM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155134
<![CDATA[Re: Switching between contexts]]> https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155133 Quote from: LaurentGom at Aug 10, 2009, 06:21 AM

(BTW, is there a way to remove the ".html" suffix? I changed the corresponding system property with an empty string, but it doesn’t seem to have any effect)
This is managed by Content Type in Revolution. The suffix and prefix from Evo are no longer applicable and are retained there only for the interest of migrations.

Quote from: LaurentGom at Aug 10, 2009, 06:21 AM

You could use a plugin to detect the subdomain from the http_host setting, or a particular subfolder in the requested URL, and switch to a particular context based on that information. Or you could create physical subfolders with custom index.php files in each one to prevent loading the main ’web’ context on each request and then switching (i.e. directly initialize a particular context).
Can you elaborate on that? Which solution is the best?
And what about finding the corresponding translated node/URL ?
Which is best really depends on your hosting situation. For instance, if you have full control of a dedicated server or VPS, and need more scalability for a large volume of traffic, then using custom index.php’s that directly invoke a specific context will be your best option. This customization is as simple as copying the index.php in the root directory to an fr/ folder and changing the call to $modx->initialize(’web’) to $modx->initialize(’fr’), though you will also need to copy the config.core.php file and make sure the values are correct for the new location. A quicker and less complex solution would be to have a plugin which detects the requested subfolder and switches to the appropriate context from the main ’web’ context.

As for linking related nodes across translations, there is nothing built-in for this in 2.0. Again, this depends on your needs and I expect that several solutions to this will materialize as developers implement similar solutions. This could be as simple as creating a TV on the main page which has a comma-delimited list of translated nodes (and possibly a second TV on the translations that point back to main node), or as complex as creating a custom table to map the relations explicitly.

Once we get to our initial RC releases of Revolution, I’m sure we will be providing sample solutions for these issues. For the time being, your exploration of the subject is a pioneering effort, though greatly appreciated.]]>
opengeek Aug 10, 2009, 10:34 AM https://forums.modx.com/thread/28848/switching-between-contexts#dis-post-155133