Created
June 4, 2025 19:40
-
-
Save luiskabes-arch/935c815e32061475757b06744c0f878f to your computer and use it in GitHub Desktop.
Render text based on the current language, using the primary and secondary languages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Render text based on the current language, using the primary and secondary languages. | |
| * Supports placeholders like %s. | |
| * @param string $primary_language The primary language text to be rendered. | |
| * @param string $secondary_language The secondary language text to be rendered. | |
| * @param mixed $args Additional arguments to replace placeholders in the text. | |
| */ | |
| function localized_text($primary_language, $secondary_language, ...$args) { | |
| // Get the current language | |
| $current_language = apply_filters('wpml_current_language', NULL); | |
| // Get the default (primary) language dynamically | |
| $default_language = apply_filters('wpml_default_language', NULL); | |
| // Determine the language text to use | |
| $text = ($current_language === $default_language) ? $primary_language : $secondary_language; | |
| // Replace placeholders in the text (e.g., %s) with the provided arguments | |
| return vsprintf($text, $args); // vsprintf() allows for dynamic string replacement | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment