Automattic\WooCommerce\Admin\RemoteInboxNotifications

SpecRunner::get_action_locale()public staticWC 1.0

Get the action locale that matches the note locale, or fall back to the en_US locale.

Method of the class: SpecRunner{}

No Hooks.

Return

Object. The matching locale, or the en_US fallback locale, or null if neither was found.

Usage

$result = SpecRunner::get_action_locale( $action_locales );
$action_locales(Array) (required)
The locales from the spec's action.

SpecRunner::get_action_locale() code WC 8.6.1

public static function get_action_locale( $action_locales ) {
	$wp_locale           = get_user_locale();
	$matching_wp_locales = array_values(
		array_filter(
			$action_locales,
			function ( $l ) use ( $wp_locale ) {
				return $wp_locale === $l->locale;
			}
		)
	);

	if ( count( $matching_wp_locales ) !== 0 ) {
		return $matching_wp_locales[0];
	}

	// Fall back to en_US locale.
	$en_us_locales = array_values(
		array_filter(
			$action_locales,
			function( $l ) {
				return $l->locale === 'en_US';
			}
		)
	);

	if ( count( $en_us_locales ) !== 0 ) {
		return $en_us_locales[0];
	}

	return null;
}