diff --git a/CHANGELOG.md b/CHANGELOG.md index 03827dd0df8fac2af966bc0b36429a65bc9b70de..68b058f7668cca769b2738fa025129c31f06b811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [3.1.0] - 2019-11-13 +### Changed +- Removed .mo file +- Translation set in composer extra section + ## [3.0.5] - 2019-09-20 ### Fixed - Fixed missing wp_create_nonce function diff --git a/composer.json b/composer.json index b025d7f2fce6f6552a845762208dce3c8275f06d..5ab9f3e522a1d5ae48397fad0eb441849ae712d3 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,13 @@ "autoload-dev": { "classmap": ["src", "tests"] }, + "extra": { + "text-domain": "wp-basic-requirements", + "translations-folder": "lang", + "po-files": { + "pl_PL": "wp-basic-requirements-pl_PL.po" + } + }, "scripts": { "phpcs": "phpcs", "phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never", diff --git a/lang/wp-basic-requirements-pl_PL.mo b/lang/wp-basic-requirements-pl_PL.mo deleted file mode 100644 index 93b469251941882eb7ff80bb52a03b48b846f2e6..0000000000000000000000000000000000000000 Binary files a/lang/wp-basic-requirements-pl_PL.mo and /dev/null differ diff --git a/src/Basic_Requirement_Checker_Factory.php b/src/Basic_Requirement_Checker_Factory.php index 1fff53a083dfacedb2081c3e9b8a3839426eb4ff..6098eaac11a81412848b84e4a4acb876a0ca235d 100644 --- a/src/Basic_Requirement_Checker_Factory.php +++ b/src/Basic_Requirement_Checker_Factory.php @@ -42,7 +42,7 @@ $requirements_checker = new WPDesk_Basic_Requirement_Checker_With_Update_Disable( $plugin_file, $plugin_name, - $this->initialize_translations( $text_domain ), + $text_domain, $requirements['php'], $requirements['wp'] ); @@ -70,31 +70,4 @@ return $requirements_checker; } - - /** - * Tries to initialize translations for requirement checker. If not given then default library translation is used. - * - * @param string|null $text_domain - * - * @return string - */ - private function initialize_translations( $text_domain = null ) { - if ( $text_domain === null ) { - $text_domain = self::LIBRARY_TEXT_DOMAIN; - - if ( function_exists( 'determine_locale' ) ) { - $locale = determine_locale(); - } else { // before WP 5.0 compatibility - $locale = get_locale(); - } - $locale = apply_filters( 'plugin_locale', $locale, self::LIBRARY_TEXT_DOMAIN ); - - $lang_mo_file = __DIR__ . '/../lang/' . self::LIBRARY_TEXT_DOMAIN . '-' . $locale . '.mo'; - if ( file_exists( $lang_mo_file ) ) { - load_textdomain( self::LIBRARY_TEXT_DOMAIN, $lang_mo_file ); - } - } - - return $text_domain; - } } \ No newline at end of file diff --git a/tests/unit/Test_Basic_Requirement_Checker_Factory.php b/tests/unit/Test_Basic_Requirement_Checker_Factory.php index fc65e8f06b944c40fb51f91a08d641197eb0c3ce..a8ca81a5b6b40d1eb781778b4c879d8a3b9aae2b 100644 --- a/tests/unit/Test_Basic_Requirement_Checker_Factory.php +++ b/tests/unit/Test_Basic_Requirement_Checker_Factory.php @@ -1,53 +1,50 @@ <?php - - - class Test_Basic_Requirement_Checker_Factory extends PHPUnit\Framework\TestCase { - public function test_can_create_checker_withn_valid_requirements() { - $existing_locale = 'pl_PL'; - $requirements = array( - 'php' => '5.6', - 'wp' => '4.5', - 'plugins' => array( - array( - 'name' => 'woocommerce/woocommerce.php', - 'nice_name' => 'WooCommerce', - 'version' => '1.0' - ), + + +class Test_Basic_Requirement_Checker_Factory extends PHPUnit\Framework\TestCase { + public function test_can_create_checker_withn_valid_requirements() { + $existing_locale = 'pl_PL'; + $requirements = array( + 'php' => '5.6', + 'wp' => '4.5', + 'plugins' => array( + array( + 'name' => 'woocommerce/woocommerce.php', + 'nice_name' => 'WooCommerce', ), - 'repo_plugins' => array( - array( - 'name' => 'flexible-checkout-fields/flexible-checkout-fields.php', - 'version' => '1.0', - 'nice_name' => 'Flexible Checkout Fields', - ), + ), + 'repo_plugins' => array( + array( + 'name' => 'flexible-checkout-fields/flexible-checkout-fields.php', + 'version' => '1.0', + 'nice_name' => 'Flexible Checkout Fields', ), - ); - - WP_Mock::wpFunction( 'get_locale' ) - ->andReturn( $existing_locale ); - WP_Mock::wpFunction( 'load_textdomain' ) - ->once(); // locale pl_PL exists so it should try to load it - - $factory = new WPDesk_Basic_Requirement_Checker_Factory(); - $checker = $factory->create_from_requirement_array( 'whatever', 'whatever', $requirements ); - - WP_Mock::wpFunction( 'get_plugins' ) - ->andReturn( array() ); - - WP_Mock::wpFunction( 'get_option' ) - ->withArgs( array( 'active_plugins', array() ) ) - ->andReturn( array() ); - - WP_Mock::passthruFunction( 'self_admin_url' ); - WP_Mock::passthruFunction( 'wp_kses' ); - WP_Mock::passthruFunction( 'wp_nonce_url' ); - WP_Mock::passthruFunction( 'wp_create_nonce' ); - WP_Mock::passthruFunction( 'admin_url' ); - - $this->assertFalse( $checker->are_requirements_met(), '2 plugins required and there should be none activated' ); - - $this->expectOutputRegex( '/Flexible Checkout Fields/' ); - $this->expectOutputRegex( '/WooCommerce/' ); - $checker->handle_render_notices_action(); - } - } \ No newline at end of file + ), + ); + + WP_Mock::wpFunction( 'get_locale' ) + ->andReturn( $existing_locale ); + + $factory = new WPDesk_Basic_Requirement_Checker_Factory(); + $checker = $factory->create_from_requirement_array( 'whatever', 'whatever', $requirements ); + + WP_Mock::wpFunction( 'get_plugins' ) + ->andReturn( array() ); + + WP_Mock::wpFunction( 'get_option' ) + ->withArgs( array( 'active_plugins', array() ) ) + ->andReturn( array() ); + + WP_Mock::passthruFunction( 'self_admin_url' ); + WP_Mock::passthruFunction( 'wp_kses' ); + WP_Mock::passthruFunction( 'wp_nonce_url' ); + WP_Mock::passthruFunction( 'wp_create_nonce' ); + WP_Mock::passthruFunction( 'admin_url' ); + + $this->assertFalse( $checker->are_requirements_met(), '2 plugins required and there should be none activated' ); + + $this->expectOutputRegex( '/Flexible Checkout Fields/' ); + $this->expectOutputRegex( '/WooCommerce/' ); + $checker->handle_render_notices_action(); + } +}