Extending locale_language_name with fallback

Created on 14 January 2011, over 14 years ago
Updated 18 June 2023, almost 2 years ago

I am working on a website where we use the language list as our source of language names. But not all the languages are enables as the site does not have to be in all languages. To work this way we rely on the locale_language_name function heavily.

What I do miss it a fallback to all the language names that are in locale_language_list. I would propose to add a parameter to the function with a default FALSE. It would look like this. It would save me resources to have that extra processing in my own code.

/**
 * Returns a language name
 */
function locale_language_name($lang, $all = FALSE) {
  static $list = NULL;
  if (!isset($list)) {
    $list = locale_language_list('name', $all);
  }
  return ($lang && isset($list[$lang])) ? $list[$lang] : t('All');
}

The current version is this.

/**
 * Returns a language name
 */
function locale_language_name($lang) {
  static $list = NULL;
  if (!isset($list)) {
    $list = locale_language_list();
  }
  return ($lang && isset($list[$lang])) ? $list[$lang] : t('All');
}
✨ Feature request
Status

Closed: outdated

Version

9.5

Component
Language systemΒ  β†’

Last updated 7 days ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡³πŸ‡±Netherlands matglas86

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024