Home > multi language > conditional (theme) language selection at 'runtime'

conditional (theme) language selection at 'runtime'

February 23Hits:1
Advertisement

I have two issues to change the language for the theme at 'runtime'. I'm not sure about my question title, hope my description helps.

I already use a plugin Polylang and there nice features: link pages with equal content but different languages AND configure primary menu for each language AND a language switcher which will be added into the primary menu.

(I also tried xLanguage and xili-language, but they were not confortable for me)

Polylang has very nice features, but I need some more:

  • a guestbook, its a page which acts like a guestbook, no content only comments. I need the form, etc. (theme) in two languages, but is only one page
  • I have second menu in the footer, there I also want to use different menu elements (names and links) for each language

Is there a possibility to change the language by passing some HTTP GET params (and redirect) and then check the params and change/reload the page with needed language?

I already tried to change the wordpress_polylang value in the cookie, but no effect. I found the reference for load_theme_textdomain but there is no parameter to pass an language.

I use Starkers theme, based on twentyten.

//edit: I found this snippet in the core.php of the polylang plugin, perhaps it would help.

// NOTE: I believe there are two ways for a plugin to force the WP language // as done by xili_language and here: load text domains and reinitialize wp_locale  //    with the action 'wp' // as done by qtranslate: define the locale with the action 'plugins_loaded', but //     in this case, the language must be specified in the url. function load_textdomains() {     // sets the current language     if (!($this->curlang = $this->get_current_language()))         return; // something went wrong      // set a cookie to remember the language. check headers have not been sent to avoid ugly error     if (!headers_sent())         setcookie('wordpress_polylang', $this->curlang->slug, time() + 31536000 /* 1 year */, COOKIEPATH, COOKIE_DOMAIN);      // set all our language filters and actions     $this->add_language_filters();      // our override_load_textdomain filter has done its job. let's remove it before calling load_textdomain     remove_filter('override_load_textdomain', array(&$this, 'mofile'));      // now we can load text domains with the right language     $new_locale = get_locale();     foreach ($this->list_textdomains as $textdomain)         load_textdomain( $textdomain['domain'], str_replace($this->default_locale, $new_locale, $textdomain['mo']));      // and finally load user defined strings (check first that base64_decode is not disabled)     if (function_exists('base64_decode')) {         global $l10n;         $mo = new MO();         $reader = new POMO_StringReader(base64_decode(get_option('polylang_mo'.$this->curlang->term_id)));         $mo->import_from_reader($reader);         $l10n['pll_string'] = &$mo;     }      // reinitializes wp_locale for weekdays and months, as well as for text direction     global $wp_locale;     $wp_locale->init();     $wp_locale->text_direction = get_metadata('term', $this->curlang->term_id, '_rtl', true) ? 'rtl' : 'ltr'; } 

Answers

I found a solution, realy dirty, but works.

In the core.php file of the polylang plugin I found this stuff:

// NOTE: I believe there are two ways for a plugin to force the WP language
// as done by xili_language and here: load text domains and reinitialize wp_locale with the action 'wp'
// as done by qtranslate: define the locale with the action 'plugins_loaded', but in this case, the language must be specified in the url.
function load_textdomains() {
    // sets the current language

    if (!($this->curlang = $this->get_current_language()))
    return; // something went wrong

    // --- modified --> check for guestbook, which should be display in different languages
    $this->check_joined_content();
    ...
}

define("GUESTBOOK_PAGE_ID", "12");
define("GUESTBOOK_HTTP_PARAM", "guestbook_lang");

function check_joined_content() {
    $gl = $_GET[GUESTBOOK_HTTP_PARAM];
    if(isset($gl)) {
        if ($this->curlang->object_id != GUESTBOOK_PAGE_ID) {
            return;
        }
        if ($gl == "de") {
            $this->curlang = $this->get_language("de");
        } else {
            $this->curlang = $this->get_language("en");
        }
    }
}

access to the pages via http get params: ?guestbook_lang=en and ?guestbook_lang=de

Related Articles

  • conditional (theme) language selection at 'runtime'February 23

    I have two issues to change the language for the theme at 'runtime'. I'm not sure about my question title, hope my description helps. I already use a plugin Polylang and there nice features: link pages with equal content but different languages AND c

  • Windows 7 64bit stuck on language select: USB3 not working?June 9

    I decided that I wanted to put Windows onto this MacBook. So I went and began to partition my harddrive in a way that I could tripple-boot easily. So then I created the boot drive using the Boot Camp assistant. Once done, I booted into Windows. I had

  • GPO to disable/hide language selection on Windows XP

    GPO to disable/hide language selection on Windows XPDecember 22

    Is there a group policy to hide the language selection on the Windows XP taskbar? I need to set this on several machines so don't want to go hiding it one by one. --------------Solutions------------- You can use the following registry setting to remo

  • Why are all languages selected by default in MiKTeX's Settings (Admin)?

    Why are all languages selected by default in MiKTeX's Settings (Admin)?March 7

    Why are all languages selected by default in the MiKTeX 2.9 Settings (Admin)? In my experience in the previous MiKTeX distributions, only a few languages were selected by default. Is there any hidden effect of this new setting? --------------Solution

  • How can I filter by slug depending on language selectionJune 10

    I'm new to this site but looking at the quality of answers provided here I will be here for a long time :) Ok, first a bit of info: I'm developing a bilingual website (English & Japanese) using Wordpress and the WPML Multi-lingual CMS. The site is fo

  • Is it possible to map a xml-field to the node language selection field in drupal with Feeds and XPath?January 8

    So, I've put together an XML import with the Feeds module and the Feeds XPath Parser plugin. I've got everything set up and working and the eventdata from my XML is importing nicely to my content type in the main language of the website. But, now I w

  • Language selection for blog doesn't exist?June 17

    I've been installing and developing on Wordpress for a while with a focus on sites in Hebrew. Recently I moved a site from a multi-site installation I have for development to it's own hosting and domain (in the MU environment I used a third level dom

  • Language selection: top or bottom of the page?November 15

    A client has the requirement to provide translation options on their website, most likely using an automated solution like Google Translate. A colleague and I have been discussing the best way to present that control and are both of the opinion that

  • How do I skip language selection with installation profile?September 25

    I am building an installation profile for Drupal 7 and trying to skip the language selection page. In the .profile file I put the following code: function efocus_install_tasks_alter(&$tasks, $install_state){ $tasks['install_select_locale']['run'] = I

  • Name for a user dropdown, user preference dropdown, preference dropdown, settings dropdown, language selection dropdown

    Name for a user dropdown, user preference dropdown, preference dropdown, settings dropdown, language selection dropdownApril 15

    How is this type of dropdown used in Amazon called? It basically permits you to select among a selection list and then it auto submits your selection via jquery and retains it for the rest of the session. In the case of Amazon EC2 you select the coun

  • Language selectionAugust 10

    Hi Im working on some language selection in a website, so far it is working wery well exept i cant get it to remember the chosen language when changing pages, im thinking it must be done by either using a session or a cookie but im stuck atm. Here is

  • connection between spell correction, language selection, predictive text, and keyboardFebruary 15

    Can someone please explain to me the android conceptual model between language selection spell correction predictive text keyboard I.e., is it the responsibility of the keyboard app to support multiple language, provide dictionaries, and analyze the

  • Language selection not working Chrome Browser

    Language selection not working Chrome BrowserFebruary 21

    My clients Chrome browser is displaying results in French rather than English (UK). I have performed the → Settings → Show Advanced Settings → Language → English. When I select English, Chrome Browser informs me this language cannot be used or be use

  • No CSS class for "language selection" field typeMarch 20

    I've notice Drupal 7 renders Language Selection field types with not an own class, which would be very useful while writing CSS style. <div class="form-item form-type-item"> <label>Language </label>Italian </div> What we

  • Prevent Language selection at ubuntu installationApril 17

    I would like to make a completely unattended installation of Ubuntu Server 14.04 from an USB drive where I extracted the ubuntu-14.04.2-server.iso In /syslinux/txt.cfg of the USB drive, I added the following section menu label ^Unattended Ubuntu Serv

  • Samsung i9300 touchscreen not working, stuck at welcome screen/language selectionJune 11

    My touchscreen is not responsive any more on my Samsung i9300 (Galaxy S3) - I don't know the reason. I successfully installed a stock ROM, but I'm stuck at the language selection/welcome screen. The problem is simple: I need to select a language or t

  • User landed on cached page instead of language selection pageJune 21

    Problem : On multilingual site, varnish caching is enabled. When any user call www.example.com, page gets cached to the first visitor's language preferences. All subsequent visitors get pages in that first visitor's language rather than their own. Fo

  • how to remove language selection option from wordpress?September 29

    I have installed one of theme and It shows Site Language selection option at admin panel. I would like to remove "available language option" and "Installed language option" Can anyone have idea how to remove it from admin side? Thank Y

  • How to specify a Rules condition related to select list values?September 30

    I'm now thoroughly confused about trying to set a Rules Condition on a select list. There are two things I want to do: (a) On a new node of my content type I want to trigger when a certain checkbox in the select list is checked (b) When a node of the

  • Is is possible to conditionally switch languages within one document?

    Is is possible to conditionally switch languages within one document? May 11

    This question already has an answer here: biblatex: per-entry language switching 2 answers I'm quite new to biblatex. I'm typesetting a collection that has papers both in English and Russian, and I'm making a single bibliography at the end of the boo

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.737 s.