Skip to content

Commit e7bf91b

Browse files
committed
chore: making generation of localized title aware of special programs
1 parent bfa7e80 commit e7bf91b

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

src/languages/ggl-post-types-de_DE.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ msgstr ""
44
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/custom-post-"
55
"types\n"
66
"POT-Creation-Date: 2026-03-18T13:32:54+00:00\n"
7-
"PO-Revision-Date: 2026-03-18 14:34+0100\n"
7+
"PO-Revision-Date: 2026-03-18 15:28+0100\n"
88
"Last-Translator: Jan Eike Suchard <jan@gegenlicht.net>\n"
99
"Language-Team: German <website@gegenlicht.net>\n"
1010
"Language: de\n"

src/public-functions.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,38 @@ function ggl_get_localized_title( int|WP_Post $post = 0 ): string {
114114

115115
// Check if the function shall return the real titles for the movie/event
116116
$show_details = apply_filters( "ggl__show_full_details", false, $post );
117+
if ( $show_details ) {
118+
// as we only want to get the language for the localization we take a
119+
// substring of the first two characters here as those are the
120+
// language part of the BCP 47 tag that are returned by get_user_locale
121+
$desired_language = substr( get_user_locale(), 0, 2 );
122+
$meta_prefix = match ( $desired_language ) {
123+
"de" => "german",
124+
default => "english"
125+
};
126+
127+
// now return the appropriate post metadata
128+
return get_post_meta( $post->ID, $meta_prefix . "_title", true );
129+
}
130+
131+
if ( $post->post_type === "event" ) {
132+
return __( "An unnamed event", "ggl-post-types" );
133+
}
117134

118-
if ( ! $show_details ) {
119-
if ( $post->post_type === "event" ) {
120-
return __( "An unnamed event", "ggl-post-types" );
121-
} else {
122-
return __( "An unnamed movie", "ggl-post-types" );
123-
}
135+
136+
$is_in_special_program = get_post_meta( $post->ID, "program_type", true ) === "special_program";
137+
if ( ! $is_in_special_program ) {
138+
return get_post_meta( $post->ID, "original_title", true );
124139
}
125140

126-
// as we only want to get the language for the localization we take a
127-
// substring of the first two characters here as those are the
128-
// language part of the BCP 47 tag that are returned by get_user_locale
129-
$desired_language = substr( get_user_locale(), 0, 2 );
130-
$meta_prefix = match ( $desired_language ) {
131-
"de" => "german",
132-
default => "english"
133-
};
134-
135-
// now return the appropriate post metadata
136-
return get_post_meta( $post->ID, $meta_prefix . "_title", true );
141+
$assigned_special_program = array_first( wp_get_post_terms( $post->ID, "special-program" ) );
142+
if ( $assigned_special_program === null ) {
143+
return __( "An unnamed special", "ggl-post-types" );
144+
} else {
145+
return $assigned_special_program->name;
146+
}
147+
148+
137149
}
138150

139151
/**

0 commit comments

Comments
 (0)