Skip to content

Instantly share code, notes, and snippets.

@mkschell
Last active October 19, 2023 07:08

Revisions

  1. mkschell revised this gist Jul 11, 2019. No changes.
  2. mkschell revised this gist Jul 11, 2019. No changes.
  3. mkschell revised this gist Jan 28, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    set $lang de;

    if ($http_accept_language ~* "(?!de)en") {
    set $lang en;
    # choose the language that appears first in the accept_language header
    if ($http_accept_language ~* "(de|en)") {
    set $lang $1;
    }

    location ~ ^/$ {
  4. mkschell created this gist Jan 28, 2013.
    17 changes: 17 additions & 0 deletions babelContextRouter.plugin.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php
    if($modx->context->get('key') != "mgr"){
    /* grab the current langauge from the cultureKey request var */
    switch ($_REQUEST['cultureKey']) {
    case 'en':
    /* switch the context */
    $modx->switchContext('en');
    break;
    default:
    /* Set the default context here */
    $modx->switchContext('web');
    break;
    }
    /* unset GET var to avoid
    * appending cultureKey=xy to URLs by other components */
    unset($_GET['cultureKey']);
    }
    6 changes: 6 additions & 0 deletions de context settings
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    site_url http://site.com/de/
    base_url /de/
    cultureKey de
    --- also recommended to provide resource ids for the following settings
    error_page (id)
    site_start (id)
    6 changes: 6 additions & 0 deletions en context settings
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    site_url http://site.com/en/
    base_url /en/
    cultureKey en
    --- also recommended to provide resource ids for the following settings
    error_page (id)
    site_start (id)
    22 changes: 22 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    set $lang de;

    if ($http_accept_language ~* "(?!de)en") {
    set $lang en;
    }

    location ~ ^/$ {
    rewrite ^ $lang/ redirect;
    }

    location ~ ^/(de|en) {
    # redirect favicon.ico and assets/* requests to site root
    rewrite ^/(de|en)/(favicon.ico|assets.*)$ /$2 redirect;
    # main Babel rewrite
    rewrite ^/(de|en)/(.*)$ /?cultureKey=$1&q=$2 break;
    # MODX rewrite
    try_files $uri $uri/ @modx-rewrite;
    }

    location / {
    try_files $uri $uri/ @modx-rewrite;
    }