Skip to content

Commit

Permalink
refactor: improve translation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Nov 12, 2024
1 parent 9a9ebba commit db4f768
Show file tree
Hide file tree
Showing 51 changed files with 318 additions and 163 deletions.
2 changes: 1 addition & 1 deletion backend/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ function ppom_load_pro_options() {
'ppom-enf-btn-class' => array(
'type' => 'text',
'title' => __( 'Button Class', 'woocommerce-product-addon' ),
'desc' => __( ' Add custom CSS classes to the enquiry form button, separated by commas.', 'woocommerce-product-addon' ),
'desc' => __( 'Add custom CSS classes to the enquiry form button, separated by commas.', 'woocommerce-product-addon' ),
),
'ppom-enf-btn-text-color' => array(
'type' => 'color',
Expand Down
16 changes: 14 additions & 2 deletions backend/templates/admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ class="nmsf-label <?php echo ! $is_available ? 'ppom-is-locked-section' : ''; ?
<div class="nmsf-panel-settings-area <?php echo ! $is_available ? 'ppom-is-locked-panel' : ''; ?>">
<?php if ( ! $is_available ): ?>
<div class="ppom-notice-upsell"><p>
<?php echo sprintf( __( '%s customization is not available on your current plan. %sUpgrade to the Pro%s plan to unlock the ability to fully enable and customize this functionality.', 'woocommerce-product-addon' ), esc_html( $title ), sprintf( '<a href="%s" target="_blank">', esc_url( tsdk_utmify( PPOM_UPGRADE_URL, $id ) ) ), '</a>' ); ?>
<?php echo sprintf(
/* translators: %1$s: Title, %2$s: Opening anchor tag, %3$s: Closing anchor tag */
__( '%1$s customization is not available on your current plan. %2$sUpgrade to the Pro%2$s plan to unlock the ability to fully enable and customize this functionality.', 'woocommerce-product-addon' ),
esc_html( $title ),
sprintf( '<a href="%s" target="_blank">', esc_url( tsdk_translate_link( tsdk_utmify( PPOM_UPGRADE_URL, $id ) ) ) ),
'</a>'
); ?>
</p>
</div>
<?php endif; ?>
Expand Down Expand Up @@ -142,7 +148,13 @@ class="<?php echo $condition_class; ?>"
<td class="nmsf-section-type" colspan="2">
<?php if ( $is_available && !$is_input_available ): ?>
<div class="ppom-notice-upsell"><p>
<?php echo sprintf( __( '%s customization is not available on your current plan. %sUpgrade to the Pro%s plan to unlock the ability to fully enable and customize this functionality.', 'woocommerce-product-addon' ), esc_html( $title ), sprintf( '<a href="%s" target="_blank">', esc_url( tsdk_utmify( PPOM_UPGRADE_URL, $id ) ) ), '</a>' ); ?>
<?php echo sprintf(
/* translators: %1$s: Title, %2$s: Opening anchor tag, %3$s: Closing anchor tag */
__( '%1$s customization is not available on your current plan. %2$sUpgrade to the Pro%3$s plan to unlock the ability to fully enable and customize this functionality.', 'woocommerce-product-addon' ),
esc_html( $title ),
sprintf( '<a href="%s" target="_blank">', esc_url( tsdk_translate_link( tsdk_utmify( PPOM_UPGRADE_URL, $id ) ) ) ),
'</a>'
); ?>
</p>
</div>
<?php endif; ?>
Expand Down
17 changes: 11 additions & 6 deletions classes/admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function add_menu_pages() {

$menu = add_submenu_page(
$page ['parent_slug'],
__( $page ['page_title'], 'woocommerce-product-addon' ),
$page ['page_title'],
__( 'PPOM Fields', 'woocommerce-product-addon' ),
$cap,
$page ['slug'],
Expand All @@ -165,7 +165,7 @@ function add_menu_pages() {
$cap = 'ppom_options_page';
// Menu page for roles set by PPOM Permission Settings
$menu = add_menu_page(
__( $page ['page_title'], 'woocommerce-product-addon' ),
$page ['page_title'],
__( 'PPOM Fields', 'woocommerce-product-addon' ),
$cap,
$page ['slug'],
Expand Down Expand Up @@ -270,7 +270,14 @@ function get_products() {
$ppom_id = intval( $_GET['ppom_id'] );
$license_status = apply_filters( 'product_ppom_license_status', '' );
$current_saved_value = $this->get_db_field( $ppom_id );
$pro_multiple_fields = ! ppom_pro_is_installed() || 'valid' !== $license_status ? '</br><i style="font-size: 90%">' . sprintf( __( 'Your current plan supports adding one group of fields per product. To add multiple groups to the same product, please %supgrade%s your plan!', 'woocommerce-product-addon' ), '<a target="_blank" href="' . tsdk_utmify( tsdk_translate_link( PPOM_UPGRADE_URL ), 'multiple-fields' ) . '">', '</a>' ) . '</i>' : '';
$pro_multiple_fields = ! ppom_pro_is_installed() || 'valid' !== $license_status
? '</br><i style="font-size: 90%">' . sprintf(
// translators: %1$s: the opening tag for upsell link, %2$s: the closing tag for upsell link.
__( 'Your current plan supports adding one group of fields per product. To add multiple groups to the same product, please %1$supgrade%2$s your plan!', 'woocommerce-product-addon' ),
'<a target="_blank" href="' . tsdk_utmify( tsdk_translate_link( PPOM_UPGRADE_URL ), 'multiple-fields' ) . '">',
'</a>'
) . '</i>'
: '';
$select_products_id_component = ( new \PPOM\Attach\SelectComponent() )
->set_id( 'attach-to-products' )
->set_title( __( 'Display on Specific Products', 'woocommerce-product-addon' ) )
Expand Down Expand Up @@ -680,10 +687,8 @@ function validate_plugin() {

echo '<div class="wrap">';
echo '<h2>' . __( 'Provide API key below:', 'woocommerce-product-addon' ) . '</h2>';
echo '<p>' . __( 'If you don\'t know your API key, please login into your: <a target="_blank" href="http://wordpresspoets.com/member-area">Member area</a>', 'woocommerce-product-addon' ) . '</p>';

echo '<form onsubmit="return validate_api_wooproduct(this)">';
echo '<p><label id="plugin_api_key">' . __( 'Entery API key', 'woocommerce-product-addon' ) . ':</label><br /><input type="text" name="plugin_api_key" id="plugin_api_key" /></p>';
echo '<p><label id="plugin_api_key">' . __( 'Enter API key', 'woocommerce-product-addon' ) . ':</label><br /><input type="text" name="plugin_api_key" id="plugin_api_key" /></p>';
wp_nonce_field();
echo '<p><input type="submit" class="button-primary button" name="plugin_api_key" /></p>';
echo '<p id="nm-sending-api"></p>';
Expand Down
24 changes: 16 additions & 8 deletions classes/fields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function render_field_settings() {
// new model
$html .= '<div class="ppom-modal-box ppom-slider ppom-field-' . esc_attr( $fields_type ) . '">';
$html .= '<header>';
$html .= '<h3>' . sprintf( __( '%s', 'woocommerce-product-addon' ), $field_title ) . '</h3>';
$html .= '<h3>' . esc_html( $field_title ) . '</h3>';
$html .= '</header>';
$html .= '<div class="ppom-modal-body">';

Expand Down Expand Up @@ -298,11 +298,11 @@ function render_field_meta( $field_meta, $fields_type, $field_index = '', $save_
$html .= '<div data-meta-id="' . esc_attr( $fields_meta_key ) . '" class="' . esc_attr( $panel_classes ) . '">';
$html .= '<div class="form-group">';

$html .= '<label>' . sprintf( __( '%s', 'woocommerce-product-addon' ), $title ) . '';
$html .= '<label>' . esc_html( $title ) . '';
if ( ! empty( $learn_more['link'] ) ) {
$html .= '. <a href="' . esc_url( $learn_more['link'] ) . '" class="ppom-repeater-learn-more" target="_blank">' . $learn_more['text'] . '<span class="dashicons dashicons-external"></span></a>';
} else if( ! empty( $desc ) ) {
$html .= '<span class="ppom-helper-icon" data-ppom-tooltip="ppom_tooltip" title="' . sprintf( __( '%s', 'woocommerce-product-addon' ), $desc ) . '">';
$html .= '<span class="ppom-helper-icon" data-ppom-tooltip="ppom_tooltip" title="' . esc_html( $desc ) . '">';
$html .= '<i class="dashicons dashicons-editor-help"></i>';
}
$html .= '</span>' . $link . '';
Expand Down Expand Up @@ -408,14 +408,22 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$weight_unit = get_option( 'woocommerce_weight_unit' );
$plc_discount = ( isset( $placeholders[2] ) && ! empty( $placeholders ) ) ? $placeholders[2] : __( 'Discount', 'woocommerce-product-addon' );
$plc_tooltip = ( isset( $placeholders[3] ) && ! empty( $placeholders ) ) ? $placeholders[3] : __( 'Tooltip', 'woocommerce-product-addon' );
$plc_weight = ( isset( $placeholders[4] ) && ! empty( $placeholders ) ) ? $placeholders[4] : __( "Weight-{$weight_unit} (PRO only)", 'woocommerce-product-addon' );
$plc_weight = ( isset( $placeholders[4] ) && ! empty( $placeholders ) ) ? $placeholders[4] : sprintf(
// translators: $s: the weight unit.
__( 'Weight-%s (PRO only)', 'woocommerce-product-addon' ),
$weight_unit
);
$plc_stock = ( isset( $placeholders[5] ) && ! empty( $placeholders ) ) ? $placeholders[5] : __( 'Stock (PRO only)', 'woocommerce-product-addon' );

if ( ppom_pro_is_installed() ) {

$plc_discount = ( isset( $placeholders[2] ) && ! empty( $placeholders ) ) ? $placeholders[2] : __( 'Discount', 'woocommerce-product-addon' );
$plc_tooltip = ( isset( $placeholders[3] ) && ! empty( $placeholders ) ) ? $placeholders[3] : __( 'Tooltip', 'woocommerce-product-addon' );
$plc_weight = ( isset( $placeholders[4] ) && ! empty( $placeholders ) ) ? $placeholders[4] : __( "Weight-{$weight_unit} (optional)", 'woocommerce-product-addon' );
$plc_weight = ( isset( $placeholders[4] ) && ! empty( $placeholders ) ) ? $placeholders[4] : sprintf(
// translators: $s: the weight unit.
__( 'Weight-%s (optional)', 'woocommerce-product-addon' ),
$weight_unit
);
$plc_stock = ( isset( $placeholders[5] ) && ! empty( $placeholders ) ) ? $placeholders[5] : __( 'Stock (optional)', 'woocommerce-product-addon' );
}

Expand Down Expand Up @@ -827,7 +835,7 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$operator_less = ( $condition['operators'] == 'less than' ) ? 'selected="selected"' : '';

$html_input .= '<div class="webcontact-rules" id="rule-box-' . esc_attr( $rule_i ) . '">';
$html_input .= '<div class="col-md-12 col-sm-12"><label>' . __( 'Rule ', 'woocommerce-product-addon' ) . $rule_i ++ . '</label></div>';
$html_input .= '<div class="col-md-12 col-sm-12"><label>' . __( 'Rule', 'woocommerce-product-addon' ) . ' ' . $rule_i ++ . '</label></div>';

// conditional elements
$html_input .= '<div class="col-md-4 col-sm-4">';
Expand Down Expand Up @@ -923,13 +931,13 @@ function render_all_input_types( $name, $data, $fields_type, $field_index, $valu
$html_input .= '</select> ';
$html_input .= '</div>';
$html_input .= '<div class="col-md-4 col-sm-4">';
$html_input .= '<p>' . __( ' of the following matches', 'woocommerce-product-addon' ) . '</p>';
$html_input .= '<p> ' . __( 'of the following matches', 'woocommerce-product-addon' ) . '</p>';
$html_input .= '</div>';
$html_input .= '</div>';

$html_input .= '<div class="row ppom-condition-clone-js">';
$html_input .= '<div class="webcontact-rules" id="rule-box-' . esc_attr( $rule_i ) . '">';
$html_input .= '<div class="col-md-12 col-sm-12"><label>' . __( 'Rule ', 'woocommerce-product-addon' ) . $rule_i ++ . '</label></div>';
$html_input .= '<div class="col-md-12 col-sm-12"><label>' . __( 'Rule', 'woocommerce-product-addon' ) . ' ' . $rule_i ++ . '</label></div>';

// conditional elements
$html_input .= '<div class="col-md-4 col-sm-4">';
Expand Down
6 changes: 5 additions & 1 deletion classes/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ function( $collapse_field ) {
}

if ( empty( $data_name ) ) {
printf( __( 'Please provide data name property for %s', 'woocommerce-product-addon' ), $title );
printf(
// translators: $s: the name of the field.
__( 'Please provide data name property for %s', 'woocommerce-product-addon' ),
$title
);
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions classes/frontend-scripts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public static function load_scripts_by_product_id( $product_id, $ppom_id = null,
$input_js_vars['wc_no_decimal'] = $decimal_palces;
$input_js_vars['wc_product_price'] = ppom_get_product_price( $product, '', 'product' );
$input_js_vars['wc_product_regular_price'] = ppom_get_product_regular_price( $product );
$input_js_vars['product_title'] = sprintf( __( '%s', 'woocommerce-product-addon' ), $product->get_title() );
$input_js_vars['product_title'] = $product->get_title();
$input_js_vars['show_price_per_unit'] = $show_price_per_unit;
$input_js_vars['show_option_price'] = $ppom->price_display;
$input_js_vars['product_id'] = $product_id;
Expand Down Expand Up @@ -566,12 +566,12 @@ private static function set_localize_data( $handle, $var_name, $product, $js_var
'wc_thousand_sep' => wc_get_price_thousand_separator(),
'wc_currency_pos' => get_option( 'woocommerce_currency_pos' ),
'wc_decimal_sep' => get_option( 'woocommerce_price_decimal_sep' ),
'total_discount_label' => sprintf( __( '%s', 'woocommerce-product-addon' ), $ppom_label_total_discount ),
'total_discount_label' => $ppom_label_total_discount,
'price_matrix_heading' => '',
'product_base_label' => sprintf( __( '%s', 'woocommerce-product-addon' ), $ppom_label_product_price ),
'option_total_label' => sprintf( __( '%s', 'woocommerce-product-addon' ), $ppom_label_option_total ),
'fixed_fee_heading' => sprintf( __( '%s', 'woocommerce-product-addon' ), $ppom_label_fixed_fee ),
'total_without_fixed_label' => sprintf( __( '%s', 'woocommerce-product-addon' ), $ppom_label_total ),
'product_base_label' => $ppom_label_product_price,
'option_total_label' => $ppom_label_option_total,
'fixed_fee_heading' => $ppom_label_fixed_fee,
'total_without_fixed_label' => $ppom_label_total,
'product_quantity_label' => __( 'Product Quantity', 'woocommerce-product-addon' ),
'per_unit_label' => __( 'unit', 'woocommerce-product-addon' ),
'text_quantity' => __( 'Quantity', 'woocommerce-product-addon' ),
Expand Down
2 changes: 1 addition & 1 deletion classes/inputs/input.audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function __construct() {

$this->title = __( 'Audio / Video', 'woocommerce-product-addon' );
$this->desc = __( 'Audio File Selection', 'woocommerce-product-addon' );
$this->icon = __( '<i class="fa fa-file-video-o" aria-hidden="true"></i>', 'woocommerce-product-addon' );
$this->icon = '<i class="fa fa-file-video-o" aria-hidden="true"></i>';
$this->settings = self::get_settings();

}
Expand Down
2 changes: 1 addition & 1 deletion classes/inputs/input.checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function __construct() {

$this->title = __( 'Checkbox Input', 'woocommerce-product-addon' );
$this->desc = __( 'regular checkbox input', 'woocommerce-product-addon' );
$this->icon = __( '<i class="fa fa-check-square-o" aria-hidden="true"></i>', 'woocommerce-product-addon' );
$this->icon = '<i class="fa fa-check-square-o" aria-hidden="true"></i>';
$this->settings = self::get_settings();

}
Expand Down
2 changes: 1 addition & 1 deletion classes/inputs/input.color.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function __construct() {

$this->title = __( 'Color picker', 'woocommerce-product-addon' );
$this->desc = __( 'Color pallete input', 'woocommerce-product-addon' );
$this->icon = __( '<i class="fa fa-modx" aria-hidden="true"></i>', 'woocommerce-product-addon' );
$this->icon = '<i class="fa fa-modx" aria-hidden="true"></i>';
$this->settings = self::get_settings();

}
Expand Down
2 changes: 1 addition & 1 deletion classes/inputs/input.cropper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function __construct() {

$this->title = __( 'Image Cropper', 'woocommerce-product-addon' );
$this->desc = __( 'Crop images', 'woocommerce-product-addon' );
$this->icon = __( '<i class="fa fa-crop" aria-hidden="true"></i>', 'woocommerce-product-addon' );
$this->icon = '<i class="fa fa-crop" aria-hidden="true"></i>';
$this->settings = self::get_settings();

}
Expand Down
Loading

0 comments on commit db4f768

Please sign in to comment.