This question has been answered by Bruno17. See the first response.
if (empty($reqCultureKey)) {
//$modx->sendRedirect($_REQUEST['cultureKey'] . '/' . $_REQUEST['q']);
} # Determine language from request
$reqCultureKeyIdx = strpos($_REQUEST['q'], '/');
$reqCultureKey = substr($_REQUEST['q'], 0, $reqCultureKeyIdx);
# Serve the proper context and language
if (array_key_exists(strtolower($reqCultureKey), array_change_key_case($languages))) {
# Remove cultureKey from request
$_REQUEST['q'] = substr($_REQUEST['q'], $reqCultureKeyIdx + 1);
$_REQUEST['cultureKey'] = $reqCultureKey;
if ($_REQUEST['q']) {
} else {
// $_REQUEST['q'] shouldn't be empty
$_REQUEST['q'] = '_mml_home';
}
# logRequest('Culture key found in URI');
} else {
$clientCultureKey = array_flip(array_intersect_key(clientLangDetect(), $languages));
if ($clientCultureKey) {
$_REQUEST['cultureKey'] = current($clientCultureKey);
} else {
$_REQUEST['cultureKey'] = trim($modx->getOption('cultureKey'));
}
} if ($_REQUEST['q']) {
} else {
// $_REQUEST['q'] shouldn't be empty
// $_REQUEST['q'] = '_mml_home';
}