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 ). 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:
Filters added:
Function my_menuitems:
This adds a new (dynamic) menuitem.
Function my_data_index:
This adds the actual dynamic page.
This all works like a charm... as long as the language isn't changed
After some digging around, I found a couple of things:
And i disabled this at the top of the plugin:
But it isn't working as (I) expected...
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.
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 ). 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
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
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"
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.