Skip to content

Commit

Permalink
Fix type check for property Locale > translations
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-mendonca committed May 22, 2024
1 parent c682ce1 commit 92b7fc5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions includes/class-options-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function core_version_check_locale( $wp_locale ) {
$locale = Translations_API::locale( $wp_locale );

// If the current locale has no Language Packs, set the core update to default 'en_US'.
if ( ! isset( $locale->translations ) ) {
if ( is_null( $locale->translations ) ) {
$wp_locale = 'en_US';
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public function settings_language_field_description() {
// Get the formated Locale name.
$formated_name = self::locale_name_format( $locale );

if ( isset( $locale->translations ) ) {
if ( ! is_null( $locale->translations ) ) {
// Format Locale name.
$locales_with_lang_packs[] = $formated_name;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ public function run_test() {
$translation_project_version = Translations_API::major_version( $translation_project['data']->name );

// Get translation project major version.
if ( isset( $locale->translations ) ) {
if ( ! is_null( $locale->translations ) ) {
$locale_translations_version = Translations_API::major_version( $locale->translations['version'] );
}

// Set language name to 'native_name'.
$formated_name = Options_General::locale_name_format( $locale );

// Check if Language Packs exist for the Locale and if the Language Pack major version is the same as the WordPress installed major version.
if ( isset( $locale->translations ) && isset( $locale_translations_version ) && $translation_project_version === $locale_translations_version ) {
if ( ! is_null( $locale->translations ) && isset( $locale_translations_version ) && $translation_project_version === $locale_translations_version ) {

$this->test_status = self::TRANSLATION_TOOLS_SITE_HEALTH_STATUS_GOOD;
$this->test_label = sprintf(
Expand Down
10 changes: 4 additions & 6 deletions includes/class-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,25 @@ public static function locale_lang_pack_status( $wp_locale ) {

if ( 'en_US' === $wp_locale ) {

$locale = esc_html__( 'WordPress default language, has no translation.', 'translation-tools' );
return esc_html__( 'WordPress default language, has no translation.', 'translation-tools' );

} elseif ( isset( $locale->translations ) ) {
} elseif ( ! is_null( $locale->translations ) ) {

$locale = sprintf(
return sprintf(
/* translators: %s: Locale name. */
esc_html__( '%s has Language Packs.', 'translation-tools' ),
$formated_name
);

} else {

$locale = sprintf(
return sprintf(
/* translators: %s: Locale name. */
esc_html__( '%s has no Language Packs.', 'translation-tools' ),
$formated_name
);

}

return $locale;
}
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-update-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ public function update_core_bottom_section_content() {

foreach ( $locales as $locale ) {

if ( isset( $locale->translations ) ) {
if ( ! is_null( $locale->translations ) ) {
$locale_translations_version = Translations_API::major_version( $locale->translations['version'] );
}

// Set language name to 'native_name'.
$formated_name = Options_General::locale_name_format( $locale );

// Check if Language Packs exist for the Locale and if the Language Pack major version is the same as the WordPress installed major version.
if ( isset( $locale->translations ) && isset( $locale_translations_version ) && $translation_project_version === $locale_translations_version ) {
if ( ! is_null( $locale->translations ) && isset( $locale_translations_version ) && $translation_project_version === $locale_translations_version ) {

$notice_messages[] = sprintf(
wp_kses_post(
Expand Down

0 comments on commit 92b7fc5

Please sign in to comment.