Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED Dynamic (fake) pages and $language
#1
Hi Guys & Dolls,

I'm writing a plugin that creates dynamic pages on a multi-lingual frontend, so pages that are not on the "Pages"-page (lot of pages there Big Grin). The menu is also dynamically created by the plugin.

First some code snippets to show you what I mean:

In the top section of the plugin:
PHP Code:
# add in this plugin's language file
i18n_merge('my_plugin') || i18n_merge('my_plugin''en_US'); 

Filters added:
PHP Code:
add_filter('menuitems''my_menuitems');
add_filter('data_index''my_data_index'); 

Function my_menuitems:
This adds a new (dynamic) menuitem.
PHP Code:
function my_menuitems($menu) {

    global 
$SITEURL;

    if ((isset(
$_GET['id'])) &&($_GET['id'] === 'my_plugin')) {
        
$menu .= '<li class="index current active"><a href="' $SITEURL 'index.php?id=my_plugin" title="' i18n_r('my_plugin/MEN_FAKE') . '">' i18n_r('my_plugin/MEN_FAKE') . '</a></li>';
    } else {
        
$menu .= '<li class="index"><a href="' $SITEURL 'index.php?id=my_plugin" title="' i18n_r('my_plugin/MEN_FAKE') . '">' i18n_r('my_plugin/MEN_FAKE') . '</a></li>';
    }
    
    return 
$menu;


Function my_data_index:
This adds the actual dynamic page.
PHP Code:
function my_data_index($data_index) {
    
    
$data_index = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?>' "\n" '<item></item>');
    
$data_index->addChild('title'i18n_r('my_plugin/MEN_FAKE'));
    
$data_index->addChild('menu'i18n_r('my_plugin/MEN_FAKE'));
    
$data_index->addChild('pubDate''');
    
$data_index->addChild('meta''');
    
$data_index->addChild('metad''');
    
$data_index->addChild('url''my_plugin');
    
$data_index->addChild('content'i18n_r('my_plugin/CONTENT'));
    
$data_index->addChild('parent''');
    
$data_index->addChild('template''');
    
$data_index->addChild('private''');    

    return 
$data_index;


This all works like a charm... as long as the language isn't changed Sad

After some digging around, I found a couple of things:
  • Fontend language code is language only, meaning not "en_US" but solely "en" (fr, de, ...)
  • The current language is in the global variable $language
Now here is the problem: that global variable $language is empty in those functions, so I added the following at the top of those functions:

PHP Code:
    global $language;
    if (isset(
$_COOKIE['language'])) {
        
$language $_COOKIE['language'];
        
i18n_merge('my_plugin'$language);
    } else {
        
i18n_merge('my_plugin''en');
    } 

And i disabled this at the top of the plugin:
PHP Code:
# add in this plugin's language file
//i18n_merge('my_plugin') || i18n_merge('my_plugin', 'en_US'); 

But it isn't working as (I) expected...
  • The menu is translated ok
  • The dynamic page is translated ok
  • In "header.inc.php" $language is still "en"
Somewhere in the I18N docs there is briefly mentioned that a plugin should add i18n_init() at the top, but doing this gives some unexpected results, it messes up the translation of the static pages and their components.

Sorry for this long post, but could someone shine his or her light on this, I'm strugling with this for days now and there is not much info on this available.

Thanks,
Fripsy.
Reply


Messages In This Thread
Dynamic (fake) pages and $language - by fripsy - 2014-11-27, 20:09:12



Users browsing this thread: 1 Guest(s)