Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/helpers
File: language-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Language_Utils;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\Greek_Support_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Conditionals\Japanese_Support_Conditional;
[6] Fix | Delete
use Yoast\WP\SEO\Config\Researcher_Languages;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* A helper object for language features.
[10] Fix | Delete
*/
[11] Fix | Delete
class Language_Helper {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Represents the Japanese support conditional.
[15] Fix | Delete
*
[16] Fix | Delete
* @var Japanese_Support_Conditional
[17] Fix | Delete
*/
[18] Fix | Delete
protected $japanese_conditional;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Represents the Greek support conditional.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Greek_Support_Conditional
[24] Fix | Delete
*/
[25] Fix | Delete
protected $greek_conditional;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Language_Helper constructor.
[29] Fix | Delete
*
[30] Fix | Delete
* @param Japanese_Support_Conditional $japanese_conditional The Japanese support conditional.
[31] Fix | Delete
* @param Greek_Support_Conditional $greek_conditional The Greek support conditional.
[32] Fix | Delete
*/
[33] Fix | Delete
public function __construct( Japanese_Support_Conditional $japanese_conditional, Greek_Support_Conditional $greek_conditional ) {
[34] Fix | Delete
$this->japanese_conditional = $japanese_conditional;
[35] Fix | Delete
$this->greek_conditional = $greek_conditional;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Checks whether word form recognition is active for the used language.
[40] Fix | Delete
*
[41] Fix | Delete
* @param string $language The used language.
[42] Fix | Delete
*
[43] Fix | Delete
* @return bool Whether word form recognition is active for the used language.
[44] Fix | Delete
*/
[45] Fix | Delete
public function is_word_form_recognition_active( $language ) {
[46] Fix | Delete
$supported_languages = [ 'de', 'en', 'es', 'fr', 'it', 'nl', 'ru', 'id', 'pt', 'pl', 'ar', 'sv', 'he', 'hu', 'nb', 'tr', 'cs', 'sk', 'fa' ];
[47] Fix | Delete
[48] Fix | Delete
// If JAPANESE_SUPPORT feature is enabled, push Japanese to the array of the supported languages.
[49] Fix | Delete
if ( $this->japanese_conditional->is_met() ) {
[50] Fix | Delete
\array_push( $supported_languages, 'ja' );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
// If GREEK_SUPPORT feature is enabled, push Greek to the array of the supported languages.
[54] Fix | Delete
if ( $this->greek_conditional->is_met() ) {
[55] Fix | Delete
\array_push( $supported_languages, 'el' );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
return \in_array( $language, $supported_languages, true );
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Checks whether the given language has function word support.
[63] Fix | Delete
* (E.g. function words are used or filtered out for this language when doing some SEO and readability assessments).
[64] Fix | Delete
*
[65] Fix | Delete
* @param string $language The language to check.
[66] Fix | Delete
*
[67] Fix | Delete
* @return bool Whether the language has function word support.
[68] Fix | Delete
*/
[69] Fix | Delete
public function has_function_word_support( $language ) {
[70] Fix | Delete
$supported_languages = [ 'en', 'de', 'nl', 'fr', 'es', 'it', 'pt', 'ru', 'pl', 'sv', 'id', 'he', 'ar', 'hu', 'nb', 'tr', 'cs', 'sk', 'fa' ];
[71] Fix | Delete
[72] Fix | Delete
// If JAPANESE_SUPPORT feature is enabled, push Japanese to the array of the supported languages.
[73] Fix | Delete
if ( $this->japanese_conditional->is_met() ) {
[74] Fix | Delete
\array_push( $supported_languages, 'ja' );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
// If GREEK_SUPPORT feature is enabled, push Greek to the array of the supported languages.
[78] Fix | Delete
if ( $this->greek_conditional->is_met() ) {
[79] Fix | Delete
\array_push( $supported_languages, 'el' );
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
return \in_array( $language, $supported_languages, true );
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Checks whether we have a specific researcher for the current locale and returns that language.
[87] Fix | Delete
* If there is no researcher for the current locale, returns default as the researcher.
[88] Fix | Delete
*
[89] Fix | Delete
* @return string The language to use to select a researcher.
[90] Fix | Delete
*/
[91] Fix | Delete
public function get_researcher_language() {
[92] Fix | Delete
$researcher_language = WPSEO_Language_Utils::get_language( \get_locale() );
[93] Fix | Delete
$supported_languages = Researcher_Languages::SUPPORTED_LANGUAGES;
[94] Fix | Delete
[95] Fix | Delete
// If JAPANESE_SUPPORT feature is enabled, push Japanese to the array of the supported languages.
[96] Fix | Delete
if ( $this->japanese_conditional->is_met() ) {
[97] Fix | Delete
\array_push( $supported_languages, 'ja' );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// If GREEK_SUPPORT feature is enabled, push Greek to the array of the supported languages.
[101] Fix | Delete
if ( $this->greek_conditional->is_met() ) {
[102] Fix | Delete
\array_push( $supported_languages, 'el' );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
if ( ! \in_array( $researcher_language, $supported_languages, true ) ) {
[106] Fix | Delete
$researcher_language = 'default';
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
return $researcher_language;
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function