Merge pull request #23150 from woocommerce/fix/23135

Made WooCommerce roles translatable
This commit is contained in:
Claudio Sanches 2019-07-08 18:39:33 -03:00 committed by GitHub
commit 8b04f8d6cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -853,3 +853,27 @@ function wc_update_user_last_active( $user_id ) {
}
update_user_meta( $user_id, 'wc_last_active', (string) strtotime( date( 'Y-m-d', current_time( 'timestamp', true ) ) ) );
}
/**
* Translate WC roles using the woocommerce textdomain.
*
* @since 3.7.0
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string
*/
function wc_translate_user_roles( $translation, $text, $context, $domain ) {
// translate_user_role() only accepts a second parameter starting in WP 5.2.
if ( version_compare( get_bloginfo( 'version' ), '5.2', '<' ) ) {
return $translation;
}
if ( 'User role' === $context && 'default' === $domain && in_array( $text, array( 'Shop manager', 'Customer' ), true ) ) {
return translate_user_role( $text, 'woocommerce' );
}
return $translation;
}
add_filter( 'gettext_with_context', 'wc_translate_user_roles', 10, 4 );