0

Hello world/ Bonjour le monde,

What technical limitations exist that would prevent the following from working (assume all static content with translations made in .mo file)

Pseudo code:

For every request:

  • Check if query string contains field :myLang:
  • If value of :myLang: equals "en_US"
  • Then ~somehow change WPLANG to "en_Us"
    (Or force Wordpress to behave as if WPLANG was actually set to '')
  • Else- serve request as French using the fr_FR.mo as defined in wp-config.php

I am vaguely aware that it has something to do with the way Wordpress is initialized. I know WPLANG can't be changed on the fly.

1
  • It's how PHP works: You can't change an already defined constant. But there're filters for that.
    – kaiser
    Commented Jun 10, 2013 at 5:58

1 Answer 1

0

I am vaguely aware that it has something to do with the way Wordpress is initialized. I know WPLANG can't be changed on the fly.

It's how PHP works: You can't change an already defined constant.

But there're filters for that. The following plugin is a sketch that you could use and try to see if this direction fits your needs.

<?php
defined( 'ABSPATH' ) OR exit;
/**
 * Plugin Name: (#102471) Query Locale
 */

add_filter( 'locale', 'wpse_102471_locale', 20 );
/**
 * Callback to filter the locale/textdomain.
 * Assumes that you got a `lang` query var
 * @param  bool $locale
 * @return mixed string/bool $locale|$GLOBALS['wp_query']['lang']
 */
function wpse_102471_locale( $locale = false )
{
    global $wp_query;
    if ( isset( $wp_query['lang'] ) )
         return $wp_query['lang'];

    return $locale;
}
1
  • That's perfect!
    – Yeow_Meng
    Commented Jun 10, 2013 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.