Topic Closed
1.5K Posts
16 Plugins
design, web development & visual effects

1st of all -  great to see the forum back online. Thank you Josh!

For my question: I used Multi Language Manager several times recently and it works great. But i couldn't figure out how to retrieve the current language of a page in PHP.

I need this to set a proper lang attribute in the <html> tag in the template like <html lang="en"> and <html lang="de"> for the english/german pages.
This is crucial if one wants to use CSS3 hyphenation (see below) which works pretty well in most major browsers (except Chrome and Adroid Stock for now).

#content {
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
Especially in mobile design, hyphenation helps a lot to make narrow text blocks look good and to break too long words. For that purposse I'd want to have the lang attribute set correctly in the <html> tag. Is there a way to retrieve this from the plugin to do sth. like …
<html lang="<?php
   if isset($currentlang) { echo $currentlang; } else { echo 'en'; }

… in the template code.

Is there a way to get $currentlang?

Thanks in advance!


(PS: For now I can set a lang attribute in every section on every page using the section’s "Options" but that's cumbersome. In fact i do some awkward jQuery hack to retrieve it from the language selector and apply it to the <html> tag but browsers do not exactly like setting the lang attribute @domready sometimes.)

5 years ago#7300

263 Posts
1 Themes
8 Plugins

Is there a way to get $currentlang?


global $ml_object, $page;
$list = $ml_object->GetList($page->gp_index);
$page_lang = is_array($list) && ($page_lang = array_search($page->gp_index,$list)) !== FALSE ? $page_lang : 'en';
<html lang="<?php echo $page_lang; ?>">

I hope this will help you and I am glad to see the forum live again too.

5 years ago#7302

1.5K Posts
16 Plugins
design, web development & visual effects
Works like a charm.

Thanks a lot Frédéric!
5 years ago#7304

1.5K Posts
16 Plugins
design, web development & visual effects

For everybody interested in this topic:

If you want even more internationalization support in your template, i have made a function that can be included in your template php (e.g. at the very end):



function getPageLanguage() {

  global $page, $languages, $config, $dataDir, $ml_object;

  $lang = $config["language"]; // gpEasy interface language

  if ($ml_object) { // only if Multi-Language Manager ist installed
    $ml_list = $ml_object->GetList($page->gp_index);
    $ml_lang = is_array($ml_list) && ($ml_lang = array_search($page->gp_index, $ml_list)) !== false ? $ml_lang : false;
  } else {
    $ml_lang = false;

  $page_lang = $ml_lang ? $ml_lang : $lang;

  $page->head  .= "\n<script type=\"text/javascript\">\n";
  $page->head  .= 'var gp_pagelang = "' . $page_lang . '"; ' . "\n";

  if ($ml_lang != $lang && array_key_exists($ml_lang, $languages)) {
    $lang_inc_file = $dataDir . "/include/languages/" . $ml_lang . "/";
    if ( file_exists($lang_inc_file) ) {
      // message("Multi-Language Manager='" . $ml_lang . "', gpEasy Interface='" . $lang . "', Page='" . $page_lang . "'");
      include $lang_inc_file; // loads current page language $langmessage array
      $page->head  .= 'var colorbox_lang = {' .
        '"previous":"' . $langmessage['Previous'] . '",' .
        '"next":"' . $langmessage['Next'] . '",' .
        '"close":"' . $langmessage['Close'] . '",' .
        '"caption":"' . $langmessage['caption'] . '",' .
        '"current":"' . sprintf( $langmessage['Image_of'], '{current}', '{total}' ) . '"}; ' . "\n";
  $page->head  .= "</script>\n";
  return $page_lang;



and insert …

<!doctype html>
<html lang="<?php echo getPageLanguage(); ?>">

… in the <html> tag.


when the function is called, it doesn't only return the current language but…

  • in case the page's language is also available as translation in gpEasy, it will make colorbox use it ("Previous/Next, Image 1 of n, Close etc.")
  • it sets a global JavaScript variable gp_pagelang that can be used in other JS/jQuery scripts, e.g. jQuery UI datepicker.




Edited: 5 years ago#7321

Topic Closed



elFinder 2.1.50 in Upcoming Release

A new release for Typesetter is in the works with a lot of improvements including the ... Read More

Typesetter 5.1

Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In