diff --git a/features/makepot.feature b/features/makepot.feature index 40233b3a..a2d7019e 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -198,3 +198,191 @@ Feature: Generate a POT file of a WordPress plugin """ And STDERR should be empty And the foo-plugin/languages/foo-plugin.pot file should exist + + Scenario: Extract all supported functions + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin.php file: + """ + 'translators', 'constants' => [], 'functions' => [ - '_' => 'dgettext', - '__' => 'dgettext', - '_e' => 'dgettext', - '_c' => 'pgettext', - '_n' => 'ngettext', - '_n_noop' => 'noop', - '_nc' => 'dgettext', - '__ngettext' => 'dgettext', - '__ngettext_noop' => 'noop', - '_x' => 'pgettext', - '_ex' => 'pgettext', - '_nx' => 'dnpgettext', - '_nx_noop' => 'noop', - '_n_js' => 'ngettext', - '_nx_js' => 'npgettext', - 'esc_attr__' => 'dgettext', - 'esc_html__' => 'dgettext', - 'esc_attr_e' => 'dgettext', - 'esc_html_e' => 'dgettext', - 'esc_attr_x' => 'dgettext', - 'esc_html_x' => 'pgettext', - 'comments_number_link' => 'ngettext', + '__' => 'text_domain', + 'esc_attr__' => 'text_domain', + 'esc_html__' => 'text_domain', + '_e' => 'text_domain', + 'esc_attr_e' => 'text_domain', + 'esc_html_e' => 'text_domain', + '_x' => 'text_context_domain', + '_ex' => 'text_context_domain', + 'esc_attr_x' => 'text_context_domain', + 'esc_html_x' => 'text_context_domain', + '_n' => 'single_plural_number_domain', + '_nx' => 'single_plural_number_context_domain', + '_n_noop' => 'single_plural_domain', + '_nx_noop' => 'single_plural_context_domain', + + // Compat. + '_' => 'gettext', // Same as 'text_domain'. + + // Deprecated. + '_c' => 'text_domain', + '_nc' => 'single_plural_number_domain', + '__ngettext' => 'single_plural_number_domain', + '__ngettext_noop' => 'single_plural_domain', ], ]; diff --git a/src/WordPress_Functions_Scanner.php b/src/WordPress_Functions_Scanner.php index 47d33d87..229211a2 100644 --- a/src/WordPress_Functions_Scanner.php +++ b/src/WordPress_Functions_Scanner.php @@ -23,15 +23,8 @@ public function saveGettextFunctions( Translations $translations, array $options $domain = $context = $original = $plural = null; switch ( $functions[ $name ] ) { - case 'pgettext': - if ( ! isset( $args[1] ) ) { - continue 2; - } - - list( $original, $context ) = $args; - break; - - case 'dgettext': + case 'text_domain': + case 'gettext': if ( ! isset( $args[1] ) ) { continue 2; } @@ -39,7 +32,7 @@ public function saveGettextFunctions( Translations $translations, array $options list( $original, $domain ) = $args; break; - case 'dpgettext': + case 'text_context_domain': if ( ! isset( $args[2] ) ) { continue 2; } @@ -47,23 +40,23 @@ public function saveGettextFunctions( Translations $translations, array $options list( $original, $context, $domain ) = $args; break; - case 'npgettext': - if ( ! isset( $args[2] ) ) { + case 'single_plural_number_domain': + if ( ! isset( $args[3] ) ) { continue 2; } - list( $original, $plural, $context ) = $args; + list( $original, $plural, $number, $domain ) = $args; break; - case 'dnpgettext': - if ( ! isset( $args[3] ) ) { + case 'single_plural_number_context_domain': + if ( ! isset( $args[4] ) ) { continue 2; } - list( $original, $plural, $context, $domain ) = $args; + list( $original, $plural, $number, $context, $domain ) = $args; break; - case 'dngettext': + case 'single_plural_domain': if ( ! isset( $args[2] ) ) { continue 2; } @@ -71,9 +64,17 @@ public function saveGettextFunctions( Translations $translations, array $options list( $original, $plural, $domain ) = $args; break; + case 'single_plural_context_domain': + if ( ! isset( $args[3] ) ) { + continue 2; + } + + list( $original, $plural, $context, $domain ) = $args; + break; + default: - parent::saveGettextFunctions( $translations, $options ); - return; + // Should never happen. + \WP_CLI::error( sprintf( "Internal error: unknown function map '%s' for '%s'.", $functions[ $name ], $name ) ); } // Todo: Require a domain?