You are here

function _facebook_comments_get_language_code in Facebook Comments Social Plugin 8

Same name and namespace in other branches
  1. 7 facebook_comments.module \_facebook_comments_get_language_code()

Returns a Language code format pt_PT. If the current language code is not in the conversion array it returns English as default language.

2 calls to _facebook_comments_get_language_code()
FacebookCommentsBlock::build in src/Plugin/Block/FacebookCommentsBlock.php
Builds and returns the renderable array for this block plugin.
FacebookCommentsFormatter::viewElements in src/Plugin/Field/FieldFormatter/FacebookCommentsFormatter.php
Builds a renderable array for a field value.

File

./facebook_comments.module, line 68
Enables users to use Facebook comments on content.

Code

function _facebook_comments_get_language_code() {
  $current_language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();

  // Get available languages.
  $language_codes = _facebook_comments_get_language_codes();
  $languages = array();

  // Get available language codes.
  if (array_key_exists($current_language, $language_codes)) {
    $languages = $language_codes[$current_language];
  }
  else {
    $languages = $language_codes['en'];
  }

  // Get the first elements key, for the available language codes.
  reset($languages);
  return key($languages);
}