Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: joomla/joomla-platform
base: staging
...
head fork: realityking/joomla-platform
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
53 libraries/joomla/language/factory.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Language
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Factory for the language package.
+ *
+ * @package Joomla.Platform
+ * @subpackage Language
+ * @since 12.1
+ */
+class JLanguageFactory
+{
+ private static $_adapters = array('snowball', 'porteren');
+
+ private static $_stemmers = array();
+
+ public static function registerStemmer($adapter)
+ {
+ self::$_adapters[] = $adapter;
+ }
+
+ public static function getStemmer($lang)
+ {
+ // Check if we already got a stemmer
+ if (isset(self::$_stemmers[$lang])
+ {
+ return self::$_stemmers[$lang];
+ }
+
+ // Appearently not, so lets look trough all those registered and choose one that works
+ foreach (self::$_adapters as $adapter)
+ {
+ $class = 'JLanguageStemmer' . ucfirst($adapter);
+ if (class_exists($stemmer) && $class::supportsLanguage($lang)
+ {
+ self::$_stemmers[$lang] = JLanguageStemmer::getInstance($adapter);
+ return self::$_stemmers[$lang];
+ }
+ }
+
+ // We still haven't found a suitable stemmer but ran out of options. Let's use a fake one.
+ self::$_stemmers[$lang] = JLanguageStemmer::getInstance('dummy');
+ return self::$_stemmers[$lang];
+ }
+}
View
11 libraries/joomla/language/stemmer.php
@@ -75,4 +75,15 @@ public static function getInstance($adapter)
* @since 12.1
*/
abstract public function stem($token, $lang);
+
+ /**
+ * Test if a stemmer supports a given language.
+ *
+ * @param string $lang The language to test.
+ *
+ * @return boolean True if the language is supported.
+ *
+ * @since 12.1
+ */
+ abstract public function supportsLanguage($lang);
}
View
50 libraries/joomla/language/stemmer/dummy.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Language
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * Fake stemmer that doesn't actually stem. It's fast though.
+ *
+ * @package Joomla.Platform
+ * @subpackage Language
+ * @since 12.1
+ */
+class JLanguageStemmerDummy extends JLanguageStemmer
+{
+
+ /**
+ * Method to stem a token and return the root.
+ *
+ * @param string $token The token to stem.
+ * @param string $lang The language of the token.
+ *
+ * @return string The root token.
+ *
+ * @since 12.1
+ */
+ public function stem($token, $lang)
+ {
+ return $token;
+ }
+
+ /**
+ * Test if a stemmer supports a given language.
+ *
+ * @param string $lang The language to test.
+ *
+ * @return boolean True if the language is supported.
+ *
+ * @since 12.1
+ */
+ public function supportsLanguage($lang)
+ {
+ return true;
+ }
+}
View
18 libraries/joomla/language/stemmer/porteren.php
@@ -79,6 +79,24 @@ public function stem($token, $lang)
return $this->cache[$lang][$token];
}
+
+ /**
+ * Test if a stemmer supports a given language.
+ *
+ * @param string $lang The language to test.
+ *
+ * @return boolean True if the language is supported.
+ *
+ * @since 12.1
+ */
+ public function supportsLanguage($lang)
+ {
+ if ($lang === 'en')
+ {
+ return true;
+ }
+ return false;
+ }
/**
* Step 1

No commit comments for this range

Something went wrong with that request. Please try again.