You are here

function i18n_get_lang_prefix in Internationalization 5.3

Same name and namespace in other branches
  1. 5 i18n.module \i18n_get_lang_prefix()
  2. 5.2 i18n.module \i18n_get_lang_prefix()

Get language code from path.

Parameters

$path:

$trim: TRUE to remove language code from $path

4 calls to i18n_get_lang_prefix()
i18n_get_normal_path in ./i18n.module
This function is similar to drupal_get_normal_path, but language-aware Also removes language from path
i18n_path in ./i18n.module
Produces i18n paths, with language prefix If path is empty or site frontpage, path = 'lang' Check for frontpage and search for alias before adding language
i18n_url_rewrite in ./i18n.module
Rewrites path with current language and removes prefix if searching for source path
translation_url in translation/translation.module
Produces url of translated page

File

./i18n.module, line 496
Internationalization (i18n) module

Code

function i18n_get_lang_prefix(&$path, $trim = FALSE) {
  $exploded_path = explode('/', $path);
  $maybelang = array_shift($exploded_path);
  $languages = i18n_languages();
  if (array_key_exists($maybelang, $languages)) {
    if ($trim) {
      $path = trim(substr($path, strlen($maybelang)), '/');
    }
    return $maybelang;
  }
}