$opts */ public static function registerStrings( array $opts ): void { if ( ! self::active() ) { return; } $strings = []; foreach ( self::KEYS as $k ) { $strings[ $k ] = (string) ( $opts[ $k ] ?? '' ); } $raw = (array) Plugin::opt( 'fields', [] ); $f = (array) apply_filters( 'admirly_fields', \Admirly\Domain\FieldConfig::normalize( $raw ), $raw ); // untranslated source labels $strings['sub.label'] = $f['sub']['label']; foreach ( self::groups() as $group ) { foreach ( (array) ( $f[ $group ] ?? [] ) as $it ) { $strings[ $group . '.' . $it['slug'] ] = $it['label']; } } foreach ( $f['sub']['options'] as $it ) { $strings[ 'sub.' . $it['slug'] ] = $it['label']; } foreach ( $strings as $name => $value ) { if ( $value === '' ) { continue; } if ( function_exists( 'pll_register_string' ) ) { pll_register_string( $name, $value, self::CONTEXT ); } do_action( 'wpml_register_single_string', self::CONTEXT, $name, $value ); } } public function registerStringsFromOptions(): void { self::registerStrings( Settings::all() ); } /** Translated value for the current language (unchanged when no multilingual plugin is active). */ public static function translate( string $name, string $value ): string { if ( $value === '' || ! self::active() ) { return $value; } if ( function_exists( 'pll__' ) ) { return (string) pll__( $value ); } return (string) apply_filters( 'wpml_translate_single_string', $value, self::CONTEXT, $name ); } /** Translated page id for the current language (falls back to the original). */ public static function pageId( int $id ): int { if ( $id <= 0 || ! self::active() ) { return max( 0, $id ); } if ( function_exists( 'pll_get_post' ) ) { $t = pll_get_post( $id ); return $t ? (int) $t : $id; } return (int) apply_filters( 'wpml_object_id', $id, 'page', true ); } /** Field config with labels translated for the current language. @param array $f */ public static function translateFields( array $f ): array { if ( ! self::active() ) { return $f; } $f['sub']['label'] = self::translate( 'sub.label', $f['sub']['label'] ); foreach ( self::groups() as $g ) { foreach ( (array) ( $f[ $g ] ?? [] ) as $i => $it ) { $f[ $g ][ $i ]['label'] = self::translate( $g . '.' . $it['slug'], $it['label'] ); } } foreach ( $f['sub']['options'] as $i => $it ) { $f['sub']['options'][ $i ]['label'] = self::translate( 'sub.' . $it['slug'], $it['label'] ); } return $f; } /** Reviews are not translated as posts; language lives in meta. @param array $types */ public function excludeFromPolylang( array $types ): array { unset( $types[ Plugin::CPT ] ); return $types; } }