Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: add utility function for dynamic string translation #975

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions wpo-ips-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,3 +989,20 @@ function wpo_wcpdf_get_simple_template_default_table_headers( $document ): array

return apply_filters( 'wpo_wcpdf_simple_template_default_table_headers', $headers, $document );
}

/**
* Dynamic string translation
*
* @param string $string
* @param string $textdomain
* @return string
*/
function wpo_wcpdf_dynamic_translate( string $string, string $textdomain ): string {
if ( ! function_exists( 'translate' ) ) {
return $string;
}

$translation = translate( $string, $textdomain );

return $translation !== $string ? $translation : $string; // Fallback to original if not translated
}
Loading