| @@ -1,31 +1,113 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | - exit; // Exit if accessed directly | |
| 5 | -} | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Merchant - Multi Language | |
| 9 | - */ | |
| 10 | -if ( ! interface_exists( 'Merchant_Language_Strategy' ) ) { | |
| 11 | - interface Merchant_Language_Strategy { | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * Register a string for translation. | |
| 15 | - * | |
| 16 | - * @param string $string The string to translate. | |
| 17 | - * @param string $context The context of the string. | |
| 18 | - * @param bool $multiline Whether the string is multiline or not. | |
| 19 | - */ | |
| 20 | - public function register_string( $string, $context, $multiline = false ); | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * Translate a string. | |
| 24 | - * | |
| 25 | - * @param string $string The string to translate. | |
| 26 | - * | |
| 27 | - * @return string | |
| 28 | - */ | |
| 29 | - public function translate_string( $string ); | |
| 30 | - } | |
| 31 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit; // Exit if accessed directly | |
| 5 | +} | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Merchant - Multi Language | |
| 9 | + */ | |
| 10 | +if ( ! interface_exists( 'Merchant_Language_Strategy' ) ) { | |
| 11 | + interface Merchant_Language_Strategy { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Register a string for translation. | |
| 15 | + * | |
| 16 | + * @param string $string_to_register The string to translate. | |
| 17 | + * @param string $context The context of the string. | |
| 18 | + * @param bool $multiline Whether the string is multiline or not. | |
| 19 | + */ | |
| 20 | + public function register_string( $string_to_register, $context, $multiline = false ): void; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * Translate a string. | |
| 24 | + * | |
| 25 | + * @param string $string_to_translate The string to translate. | |
| 26 | + * | |
| 27 | + * @return string | |
| 28 | + */ | |
| 29 | + public function translate_string( $string_to_translate ); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Get Current language code | |
| 33 | + * | |
| 34 | + * @return string | |
| 35 | + */ | |
| 36 | + public function get_current_lang(); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Translate a taxonomy term slug or ID to another language. | |
| 40 | + * | |
| 41 | + * When $term is a string (slug), returns the translated slug. | |
| 42 | + * When $term is an int (term ID), returns the translated term ID. | |
| 43 | + * Returns the original $term unchanged if no translation is found. | |
| 44 | + * | |
| 45 | + * @param string|int $term The term slug or term ID to translate. | |
| 46 | + * @param string $taxonomy The taxonomy name (e.g. 'product_cat'). | |
| 47 | + * @param string|null $language Target language code. Null = current language. | |
| 48 | + * | |
| 49 | + * @return string|int Translated term (same type as input). | |
| 50 | + * | |
| 51 | + * @since 2.1.9 | |
| 52 | + */ | |
| 53 | + public function translate_term( $term, $taxonomy, $language = null ); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Switch the active language context for subsequent queries. | |
| 57 | + * | |
| 58 | + * Call restore_language() to revert to the original language. | |
| 59 | + * | |
| 60 | + * @param string $language Language code to switch to. | |
| 61 | + * | |
| 62 | + * @return void | |
| 63 | + * | |
| 64 | + * @since 2.1.9 | |
| 65 | + */ | |
| 66 | + public function switch_language( $language ); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Restore the language context to what it was before switch_language(). | |
| 70 | + * | |
| 71 | + * @return void | |
| 72 | + * | |
| 73 | + * @since 2.1.9 | |
| 74 | + */ | |
| 75 | + public function restore_language(); | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Get the default (primary) language code. | |
| 79 | + * | |
| 80 | + * @return string Language code (e.g. 'en'), or empty string if unavailable. | |
| 81 | + * | |
| 82 | + * @since 2.1.9 | |
| 83 | + */ | |
| 84 | + public function get_default_language(); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Get the language code that disables language filtering. | |
| 88 | + * | |
| 89 | + * Intended for use with switch_language() to query terms | |
| 90 | + * across all languages (e.g. admin Select2 dropdowns). | |
| 91 | + * | |
| 92 | + * @return string The "all languages" code for this plugin. | |
| 93 | + * | |
| 94 | + * @since 2.1.9 | |
| 95 | + */ | |
| 96 | + public function get_all_languages_code(); | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Get the language code for a specific post. | |
| 100 | + * | |
| 101 | + * Useful in AJAX contexts where the current language detection | |
| 102 | + * may be unreliable, allowing callers to determine the actual | |
| 103 | + * language of the content being evaluated. | |
| 104 | + * | |
| 105 | + * @param int $post_id The post ID to check. | |
| 106 | + * | |
| 107 | + * @return string Language code (e.g. 'ar', 'en'), or empty string if unavailable. | |
| 108 | + * | |
| 109 | + * @since 2.1.9 | |
| 110 | + */ | |
| 111 | + public function get_post_language( $post_id ); | |
| 112 | + } | |
| 113 | +} | |