From b1887897064298e374a33bcdfa270f1686a8ebbe Mon Sep 17 00:00:00 2001 From: Patrick Joyce Date: Tue, 20 Jan 2026 13:55:51 -0500 Subject: [PATCH] Tab translation --- fetch-meditation.php | 64 +++++++++++++++++++++++++++++++++++++++----- readme.txt | 6 ++++- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/fetch-meditation.php b/fetch-meditation.php index 3c370b1..bf39cfa 100644 --- a/fetch-meditation.php +++ b/fetch-meditation.php @@ -6,7 +6,7 @@ * Install: Drop this directory in the "wp-content/plugins/" directory and activate it. You need to specify "[fetch_meditation]", "[jft]", or "[spad]" in the code section of a page or a post. * Contributors: pjaudiomv, bmltenabled * Author: bmltenabled - * Version: 1.4.7 + * Version: 1.4.8 * Requires PHP: 8.1 * Requires at least: 6.2 * License: GPL v2 or later @@ -363,6 +363,48 @@ private static function get_user_friendly_message( string $error_message, string return sprintf( 'Unable to load today\'s %s meditation at this time. Please try refreshing the page or check back later.', strtoupper( $book ) ); } + + /** + * Get translated title for a book in a specific language + * + * @param string $book The book type (jft or spad) + * @param string $language The language code + * @return string Translated title + */ + private static function get_translated_title( string $book, string $language ): string { + $translations = [ + 'jft' => [ + 'english' => 'Just For Today', + 'french' => 'Juste pour aujourd\'hui', + 'german' => 'Nur für heute', + 'italian' => 'Solo per oggi', + 'portuguese' => 'Só por hoje', + 'portuguese-pt' => 'Só por hoje', + 'russian' => 'Только на сегодня', + 'spanish' => 'Sólo por hoy', + 'swedish' => 'Bara för idag', + ], + 'spad' => [ + 'english' => 'Spiritual Principle A Day', + 'french' => 'Principe spirituel du jour', + 'german' => 'Spirituelles Prinzip des Tages', + 'italian' => 'Principio spirituale del giorno', + 'portuguese' => 'Princípio espiritual do dia', + 'portuguese-pt' => 'Princípio espiritual do dia', + 'russian' => 'Духовный принцип дня', + 'spanish' => 'Principio espiritual del día', + 'swedish' => 'Andlig princip för dagen', + ], + ]; + + // Return translated title or fall back to English + if ( isset( $translations[ $book ][ $language ] ) ) { + return $translations[ $book ][ $language ]; + } + return $translations[ $book ]['english']; + } + + /** * Render both JFT and SPAD meditations in a tabbed interface * @@ -431,17 +473,21 @@ private static function render_both_shortcode( string|array $attrs = [] ): strin // Build tabbed or accordion interface if ( 'accordion' === $tabs_layout ) { - return static::render_accordion( $instance_counter, $jft_content, $spad_content, $jft_theme, $spad_theme ); + return static::render_accordion( $instance_counter, $jft_content, $spad_content, $jft_theme, $spad_theme, $jft_language, $spad_language ); } + // Get translated titles + $jft_title = esc_html( self::get_translated_title( 'jft', $jft_language ) ); + $spad_title = esc_html( self::get_translated_title( 'spad', $spad_language ) ); + // Build tabbed interface (horizontal) $content = "\n
\n"; $content .= " \n"; $content .= "
\n"; @@ -469,13 +515,17 @@ private static function render_both_shortcode( string|array $attrs = [] ): strin * @param string $spad_theme SPAD theme * @return string Rendered accordion HTML */ - private static function render_accordion( int $instance_counter, string $jft_content, string $spad_content, string $jft_theme, string $spad_theme ): string { + private static function render_accordion( int $instance_counter, string $jft_content, string $spad_content, string $jft_theme, string $spad_theme, string $jft_language, string $spad_language ): string { + // Get translated titles + $jft_title = esc_html( self::get_translated_title( 'jft', $jft_language ) ); + $spad_title = esc_html( self::get_translated_title( 'spad', $spad_language ) ); + $content = "\n
\n"; // JFT Accordion Item $content .= "
\n"; $content .= " \n"; $content .= "
\n"; @@ -487,7 +537,7 @@ private static function render_accordion( int $instance_counter, string $jft_con // SPAD Accordion Item $content .= "
\n"; $content .= " \n"; $content .= "