0

I have written and translated a theme and all is working fine, except the starter content. It seems that i am not able to translate the content and it is still displayed in English, even though I have included translation in another language and the default WordPress language is set to the other language. Here is my starter content array:

    'posts' => array(
        //Add pages
        'home' => array(
            'post_type' => 'page', 
            'post_title' => _x( 'Homepage', 'slug' ),
            'post_content' => _x( 'Welcome to your site! This is your homepage, which is what most visitors will see when they come to your site for the first time. Use the customizer to choose between a static homepage or display the latest posts in a beautiful 2-column layout instead.', 'slug' ),
        ),
        'about' => array(
            'post_type' => 'page', 
            'post_title' => _x( 'About', 'slug' ),
            'thumbnail' => '{{featured-image-about}}',
            'post_content' => _x( 'Welcome on board! This is your about page, which is what most visitors will check to find out more information about yourself. Write here about your hobbies, work and passion.', 'slug' ),
        ),
        'contacts' => array(
            'post_type' => 'page', 
            'post_title' => _x( 'Contacts', 'slug' ),
            'post_content' => _x( 'This is a good place to add some basic contact information, such as an address and a phone number. You can also add a contact form with contact form 7 or another plugin', 'slug' ),
        ),
    ),

P.S.: It seems like the pages (home, about, contacts) are stored in alphabetical order (about, contacts, home) and displayed alphabetically as menu items. I would also be interested to know if there is a way to sort the pages by the way they entered, e.g. home, about, contacts rather than about, contacts, home.

1

As you're using _x() as your translation function you should do one of the following.

1) If 'slug' is supposed to be your text-domain, add context to the _x() functions, e.g. _x( 'Homepage', 'page title', 'slug' ).

2) If 'slug' is your context, then add the text-domain, the third parameter, to your translation functions as the text strings you have don't seem to be default texts and most likely won't be found in the default text-domain.

3) Switch to using for example __() or esc_html__() translation function, which only needs stringand text-domain as parameters.

  • I tried to use _x() with second parameter as context and i also tried using __() as you suggested, but it is still not working with starter content. All other translation functions in my theme work, except for the starter content. – Badan Aug 30 at 21:09
  • 1
    Is "slug" your text domain or is it something else? How are you loading the starter content and the translations? – Antti Koskinen Aug 30 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.