You are here

public function Stemmer::setLanguage in Snowball Stemmer 8

Same name and namespace in other branches
  1. 2.x src/Stemmer.php \Drupal\snowball_stemmer\Stemmer::setLanguage()

Set language.

Parameters

string $language: Two character language code.

Return value

bool True if able to set, false if not supported.

File

src/Stemmer.php, line 49

Class

Stemmer
Service wrapper class for stemmer.

Namespace

Drupal\snowball_stemmer

Code

public function setLanguage($language) {
  $supported = [
    'da' => 'Danish',
    'nl' => 'Dutch',
    'en' => 'English',
    'fr' => 'French',
    'de' => 'German',
    'it' => 'Italian',
    'no' => 'Norwegian',
    'pt' => 'Portuguese',
    'ro' => 'Romanian',
    'ru' => 'Russian',
    'es' => 'Spanish',
    'sv' => 'Swedish',
  ];
  if (isset($supported[$language])) {
    $this->language = $language;
    if (empty($this->stemmers[$language])) {
      $class = 'Wamania\\Snowball\\' . $supported[$language];
      $this->stemmers[$language] = new $class();
    }
    return TRUE;
  }
  return FALSE;
}