English source => translation (only strings that differ). */ public static function js_map() { $locale = function_exists( 'determine_locale' ) ? determine_locale() : get_locale(); $brand = self::brand(); // English sites without a white-label name need no map at all. if ( ( 0 === strpos( $locale, 'en_' ) || 'en' === $locale ) && 'Akram' === $brand ) { return array(); } $mo = WP_LANG_DIR . '/plugins/akram-' . $locale . '.mo'; // Updated translation files or strings invalidate the cache on their own. $key = 'akram_i18n_' . md5( $locale . AKRAM_VERSION . $brand . ( file_exists( $mo ) ? filemtime( $mo ) : 0 ) . @filemtime( AKRAM_DIR . 'assets/build/strings.json' ) ); $cached = get_transient( $key ); if ( is_array( $cached ) ) { return $cached; } $file = AKRAM_DIR . 'assets/build/strings.json'; $strings = file_exists( $file ) ? json_decode( (string) file_get_contents( $file ), true ) : array(); $map = array(); foreach ( (array) $strings as $s ) { $tr = translate( (string) $s, 'akram' ); // phpcs:ignore WordPress.WP.I18n if ( $tr !== $s ) { $map[ $s ] = $tr; } } set_transient( $key, $map, DAY_IN_SECONDS ); return $map; } /** Product name shown to users (white label). */ public static function brand() { $b = trim( (string) Options::get( 'brand_name', '' ) ); return '' === $b ? 'Akram' : $b; } public static function brand_logo() { return esc_url_raw( (string) Options::get( 'brand_logo', '' ) ); } public static function is_rtl() { return function_exists( 'is_rtl' ) && is_rtl(); } }