| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Helpers; |
| 4 |
|
| 5 |
use WPSEO_Language_Utils; |
| 6 |
use Yoast\WP\SEO\Config\Researcher_Languages; |
| 7 |
|
| 8 |
/** |
| 9 |
* A helper object for language features. |
| 10 |
*/ |
| 11 |
class Language_Helper { |
| 12 |
|
| 13 |
/** |
| 14 |
* Checks whether word form recognition is active for the used language. |
| 15 |
* |
| 16 |
* @param string $language The used language. |
| 17 |
* |
| 18 |
* @return bool Whether word form recognition is active for the used language. |
| 19 |
*/ |
| 20 |
public function is_word_form_recognition_active( $language ) { |
| 21 |
$supported_languages = [ 'de', 'en', 'es', 'fr', 'it', 'nl', 'ru', 'id', 'pt', 'pl', 'ar', 'sv', 'he', 'hu', 'nb', 'tr', 'cs', 'sk', 'el', 'ja' ]; |
| 22 |
|
| 23 |
return \in_array( $language, $supported_languages, true ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Checks whether the given language has function word support. |
| 28 |
* (E.g. function words are used or filtered out for this language when doing some SEO and readability assessments). |
| 29 |
* |
| 30 |
* @param string $language The language to check. |
| 31 |
* |
| 32 |
* @return bool Whether the language has function word support. |
| 33 |
*/ |
| 34 |
public function has_function_word_support( $language ) { |
| 35 |
$supported_languages = [ 'en', 'de', 'nl', 'fr', 'es', 'it', 'pt', 'ru', 'pl', 'sv', 'id', 'he', 'ar', 'hu', 'nb', 'tr', 'cs', 'sk', 'fa', 'el', 'ja' ]; |
| 36 |
|
| 37 |
return \in_array( $language, $supported_languages, true ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Checks whether we have a specific researcher for the current locale and returns that language. |
| 42 |
* If there is no researcher for the current locale, returns default as the researcher. |
| 43 |
* |
| 44 |
* @return string The language to use to select a researcher. |
| 45 |
*/ |
| 46 |
public function get_researcher_language() { |
| 47 |
$researcher_language = WPSEO_Language_Utils::get_language( \get_locale() ); |
| 48 |
$supported_languages = Researcher_Languages::SUPPORTED_LANGUAGES; |
| 49 |
|
| 50 |
if ( ! \in_array( $researcher_language, $supported_languages, true ) ) { |
| 51 |
$researcher_language = 'default'; |
| 52 |
} |
| 53 |
return $researcher_language; |
| 54 |
} |
| 55 |
} |
| 56 |
|