-1

I am using polylang plugin for multiple language in my project. I created a custom Event using following code.

function post_types()
{
    $labels = array(
        "name"          => "Events",
        "add_new_items" => "Add New Event",
        "edit_item"     => "Edit Event",
        "all_items"     => "All Events",
        "singular_name" => "Event"
    );

    $events = array(
        "has_archive" => true,
        "public"      => true,
        "menu_icon"   => "dashicons-calendar",
        "labels"      => $labels,
    );
    register_post_type("event", $events);
}

add_action("init", "post_types");

I am not sure how can I change the language of the posts inside this event?

nas
  • 2,289
  • 5
  • 32
  • 67
  • 1
    You must need to use `text domain` for each your labels which are visible - https://polylang.pro/doc/multilingual-custom-post-types-and-taxonomies/ here you may understand how you can translate your custom post types and taxonomies – Krunal Prajapati Feb 12 '20 at 08:08

1 Answers1

1

Please use a text domain:

function post_types()
{
    $labels = array(
        "name"          => __( "Events", "your-text-domain" ),
        "add_new_items" => __( "Add New Event", "your-text-domain" ),
        "edit_item"     => __( "Edit Event", "your-text-domain" ),
        "all_items"     => __( "All Events", "your-text-domain" ),
        "singular_name" => __( "Event, "your-text-domain" )"
    );

    $events = array(
        "has_archive" => true,
        "public"      => true,
        "menu_icon"   => "dashicons-calendar",
        "labels"      => $labels,
    );
    register_post_type("event", $events);
}

add_action("init", "post_types");

Then create a language file(.po/.mo) for your desired language. I basically use Loco Translate Plugin for creating a language file.

Learn More:https://developer.wordpress.org/apis/handbook/internationalization/localization/

  • What is your-text-domain mean? – nas Feb 12 '20 at 07:28
  • It can be anything that needs to initialized before using "load_plugin_textdomain" for plugin and "load_theme_textdomain" for theme. Please see https://developer.wordpress.org/reference/functions/load_theme_textdomain/#user-contributed-notes and https://developer.wordpress.org/reference/functions/load_plugin_textdomain/#user-contributed-notes – Akhtarujjaman Shuvo Feb 13 '20 at 06:07