Usage
Prepare your contexts
After (or before) the installation of LangRouter you have to prepare your contexts.
- Create one context for each language and name it with the language name.
Normally the context key would be equal with the cultureKey context setting
of that language, i.e.
en
as context key andEnglish
as context name when the cultureKey isen
. - Create the context setting base_url in each context and set it to
/
. - Create the context setting cultureKey in each context and set it to the
according cultureKey, i.e.
en
. - For each context create a site_url context setting and fill it with the
following value:
{url_scheme}{http_host}{base_url}{cultureKey}/
. MODX handles the placeholder replacements in that setting on its own. - Fill the MODX system setting babel.contextDefault with the context key of the default language, if you did not fill this during the installation of LangRouter.
- In head section of the template insert the following line
<base href="[[!++site_url]]">
. - Include the static files from the assets folder in your installation with
[[++assets_url]]path/to/static_file
, i.e.<link href="[[++assets_url]]css/site.css" rel="stylesheet">
or<img src="[[++assets_url]]images/whatever.jpg" … >
. You could use[[++base_url]]path/to/static_file
, if your assets are not located inside the assets folder. - Set the MODX system setting link_tag_scheme to
-1
(URL is relative to site_url)
To create these settings easily, you could use the Cross Contexts Settings extra available on MODX Extras.
Example
Example settings for an en
context
Context setting | Value |
---|---|
base_url | / |
cultureKey | en |
site_url | {url_scheme}{http_host}{base_url}{cultureKey}/ |
System settings
LangRouter uses the following system settings in the namespace langrouter
:
Key | Description | Default |
---|---|---|
langrouter.debug | Log debug information in the MODX ystem log. | No |
langrouter.response_code | Response code for the redirect to the right context, if the culture key is not set. | HTTP/1.1 301 Moved Permanently |
langrouter.contextKeys | (optional) Comma separated list of context keys which could be switched to. Defaults to the babel.contextKeys system setting. |
- |
Caution
Please don't activate the friendly_urls_strict MODX system setting, if you use LangRouter. That could cause nasty redirect loops.
Usage with other extras
Some extras settings have to be changed to work well with LangRouter (and other routing plugins):
pThumb
Please set the system setting phpthumbof.cache_url
to /
. Otherwise, the
generated thumbnail path of the snippet/output filter will contain the
{base_url}{cultureKey}
prefix.
Then you need an additional .htaccess rule that removes this prefix. You have to change the list of culture keys in the following example. It has to be inserted before the friendly URLs part:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|de|fr|nl)/assets(.*)$ assets$2 [L,QSA]