Skip to content

Commit a81e20a

Browse files
authored
fix issue when locale is only two chars (#549)
for example "de" instead of "de_DE"
1 parent 9d5bd8c commit a81e20a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

includes/transformer/class-post.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function to_object() {
8282
$object->set_content( $this->get_content() );
8383
$object->set_content_map(
8484
array(
85-
\strstr( \get_locale(), '_', true ) => $this->get_content(),
85+
$this->get_locale() => $this->get_content(),
8686
)
8787
);
8888
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) );
@@ -580,4 +580,25 @@ protected function get_post_content_template() {
580580
protected function get_mentions() {
581581
return apply_filters( 'activitypub_extract_mentions', array(), $this->wp_post->post_content, $this->wp_post );
582582
}
583+
584+
/**
585+
* Returns the locale of the post.
586+
*
587+
* @return string The locale of the post.
588+
*/
589+
public function get_locale() {
590+
$post_id = $this->wp_post->ID;
591+
$lang = \strtolower( \strtok( \get_locale(), '_-' ) );
592+
593+
/**
594+
* Filter the locale of the post.
595+
*
596+
* @param string $lang The locale of the post.
597+
* @param int $post_id The post ID.
598+
* @param WP_Post $post The post object.
599+
*
600+
* @return string The filtered locale of the post.
601+
*/
602+
return apply_filters( 'activitypub_post_locale', $lang, $post_id, $this->wp_post );
603+
}
583604
}

0 commit comments

Comments
 (0)