Skip to content
Snippets Groups Projects
Commit 62141b57 authored by dyszczo's avatar dyszczo
Browse files

lang support

parent b7d6ab90
No related branches found
No related tags found
1 merge request!13Feature/repository plugins
......@@ -5,6 +5,7 @@
- Factory can create checker from requirement array
- Support for update suggestion when required plugin not found
- WPDesk_Basic_Requirement_Checker_With_Update_Disable can temporarily say that requirements are not met when required plugin is in the process of being updated
- Translations
## [2.4.0] - 2019-06-04
### Added
......
......@@ -12,17 +12,20 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker_With_Update_Disable' ) )
* Falicitates createion of requirement checker
*/
class WPDesk_Basic_Requirement_Checker_Factory {
const LIBRARY_TEXT_DOMAIN = 'requirement-checker';
/**
* Creates a simplest possible version of requirement checker.
*
* @param string $plugin_file
* @param string $plugin_name
* @param string|null $text_domain
* @param string|null $text_domain Text domain to use. If null try to use library text domain.
*
* @return WPDesk_Requirement_Checker
*/
public function create_requirement_checker( $plugin_file, $plugin_name, $text_domain = null ) {
return new WPDesk_Basic_Requirement_Checker( $plugin_file, $plugin_name, $this->initialize_translations($text_domain), null, null );
return new WPDesk_Basic_Requirement_Checker( $plugin_file, $plugin_name,
$this->initialize_translations( $text_domain ), null, null );
}
/**
......@@ -30,8 +33,8 @@ class WPDesk_Basic_Requirement_Checker_Factory {
*
* @param string $plugin_file
* @param string $plugin_name
* @param string $text_domain
* @param array $requirements
* @param string $text_domain Text domain to use. If null try to use library text domain.
* @param array $requirements Requirements array as given by plugin.
*
* @return WPDesk_Requirement_Checker
*/
......@@ -74,6 +77,22 @@ class WPDesk_Basic_Requirement_Checker_Factory {
* @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;
}
}
......@@ -22,6 +22,9 @@ class Test_Basic_Requirement_Checker_Factory extends PHPUnit\Framework\TestCase
),
);
WP_Mock::wpFunction( 'get_locale' )
->andReturn( 'pl_PL' );
$factory = new WPDesk_Basic_Requirement_Checker_Factory();
$checker = $factory->create_from_requirement_array( 'whatever', 'whatever', $requirements );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment