diff --git a/README.md b/README.md index b522e54..05617c6 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ In your project's `composer.json`, add the following: ], "scripts": { "post-install-cmd": [ - "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " + "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " ], "post-update-cmd": [ - "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " + "./10up-lib/wp-compat-validation-tool/replace-namespace.sh " ] }, "extra": { @@ -43,6 +43,9 @@ In your project's `composer.json`, add the following: Replace `` with a unique namespace specific to your project. The `WP_Compat_Validation_Tools` namespace will be replaced by `` to avoid namespace collisions in situations where multiple plugins use this package as their dependencies. +Replace `` with a unique translation domain specific to your project. +This is usually the slug for your theme or plugin. The `wp-compat-validation-tool` translation domain will be replaced by ``. + ## Usage ```php diff --git a/replace-namespace.sh b/replace-namespace.sh index 1ff562b..8cf015a 100755 --- a/replace-namespace.sh +++ b/replace-namespace.sh @@ -4,14 +4,21 @@ SCRIPT_DIR="$(dirname "$0")" SCRIPT_NAME="$(basename "$0")" -# Check for the required argument -if [ "$#" -ne 1 ]; then +# Check for the required first argument +if [ -z "$1" ]; then echo "Usage: $0 New_Namespace" exit 1 fi NEW_NAMESPACE="$1" +# Check for the optional translation domain argument and set it if provided +if [ -n "$2" ]; then + TRANSLATION_DOMAIN="$2" +else + echo "No translation domain provided. Skipping translation domain replacement." +fi + # Use find to get all files recursively from the script's directory, excluding the script itself find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do echo $file @@ -19,4 +26,13 @@ find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIP perl -pi -e "s/WP_Compat_Validation_Tool/$NEW_NAMESPACE/g" "$file" done +# If a new translation domain was provided, replace the old one with the new one +if [ -n "$TRANSLATION_DOMAIN" ]; then + find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do + echo $file + # Replace the exact string when surrounded by either single or double quotes + perl -pi -e "s/(['\"])wp-compat-validation-tool\\1/\\1$TRANSLATION_DOMAIN\\1/g" "$file" + done +fi + cd 10up-lib/wp-compat-validation-tool && rm -rf .git .github .gitignore composer.json composer.lock CHANGELOG.md CONTRIBUTING.md README.md LICENSE.md CODE_OF_CONDUCT.md CREDITS.md replace-namespace.sh diff --git a/src/Validator.php b/src/Validator.php index 1a76482..e186120 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -1,6 +1,10 @@ messages[] = sprintf( esc_html__( 'The minimum PHP version required is %s' ), $item_details['value'] ); + // translators: %s: PHP version + $this->messages[] = sprintf( __( 'The minimum PHP version required is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; case 'php_max_required_version': if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '>' ) ) { - $this->messages[] = sprintf( esc_html__( 'The maximum PHP version supported is %s' ), $item_details['value'] ); + // translators: %s: PHP version + $this->messages[] = sprintf( __( 'The maximum PHP version supported is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); + } + break; + + case 'wp_min_required_version': + if ( ! empty( $item_details['value'] ) && version_compare( $this->wp_get_wp_version(), $item_details['value'], '<' ) ) { + // translators: %s: WordPress version + $this->messages[] = sprintf( __( 'The minimum WordPress version required is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); + } + break; + + case 'wp_max_required_version': + if ( ! empty( $item_details['value'] ) && version_compare( $this->wp_get_wp_version(), $item_details['value'], '>' ) ) { + // translators: %s: WordPress version + $this->messages[] = sprintf( __( 'The maximum WordPress version supported is %s', 'wp-compat-validation-tool' ), $item_details['value'] ); } break; @@ -149,7 +190,10 @@ public function render_php_compat_error() {

- checklist['plugin_name']['value'] ); ?> + checklist['plugin_name']['value'] ) ); + ?>

messages ) > 1 ) : ?>