How to add a new language string in WordPress?

Basically I want to change the words “Previous post” and “Next Post” for “Previous Work” and “Next work” in this site: http://fontaneriaborja.com/en/portfolio-view/solar-panels-swimming-pool/

I have gone into /wp-content/themes/CherryFramework/loop/loop-single-portfolio.php and found this code:

Read More
<!--BEGIN .pager .single-pager -->
        <ul class="pager single-pager">
        <?php if (get_previous_post()) : ?>
            <li class="previous"><?php previous_post_link('%link', theme_locals("prev_post")) ?>
        <?php endif; ?>

        <?php if (get_next_post()) : ?>
            <li class="next"><?php next_post_link('%link', theme_locals("next_post")) ?>
        <?php endif; ?>
<!--END .pager .single-pager -->

I believe that theme_locals(“prev_post”) and theme_locals(“next_post”) are the strings that call the text.

Ideally what I would like to do is to change and add a new string for something like theme_locals(“prev_work”) and theme_locals(“next_work”) that would generate two new translations to my .po files. However, is here where I get stuck.

It is a multi language WordPress 4.1.1 site using Polylang and a theme from Template Monster with the cherry plugin.

I have already searched around with no luck to understand how this works. So any help would be really appreciated.

Thank you for your time and thanks in advance to all of you.

Best

P.S.: I am a beginner in terms of web development.
P.S.2: I have posted this also on https://wordpress.org/support/topic/add-language-string-in-wordpress and I will try to keep both places updated if I find the solution.

POST EDIT:

As suggested by danbahrami I have found a php file with the function ‘theme_local_init()’ in /wp-content/themes/CherryFramework/includes/locals.php. Here is part of the code, I haven’t put it all because is quite long:

<?php
function theme_local_init() {
    global $is_cherry_local_init, $cherry_locals_arr;
    if ($is_cherry_local_init) return true;

    $domain = CURRENT_THEME;
    $cherry_locals_arr = array(
        //general
        'no' => __('No', 'cherry'),
        'yes' => __('Yes', $domain),
        'slow_speed' => __('Slow', $domain),
        'normal_speed' => __('Normal', $domain),
        'fast_speed' => __('Fast', $domain),
        'normal_size' => __('Normal size', $domain),
        'large_size' => __('Large size', $domain),
        'font_size' => __('Font Size', $domain),
        'lineheight' => __('Lineheight', $domain),
        'font_face' => __('Font Face', $domain),
        'character_sets' => __('Character Sets', $domain),
        'font_style' => __('Font Style', $domain),
        'color' => __('Color', $domain),
        'import' => __('Import', $domain),
        'export' => __('Export', $domain),
        'done' => __('Done', $domain),
        'error' => __('Error', $domain),
        'success' => __('success', $domain),
        'upload' => __('Upload', $domain),
        'try_again' => __('try again', $domain),
        'finish' => __('Finish', $domain),
        'skip' => __('Skip this step', $domain),
        'install_next' => __('next', $domain),
        'none' => __('None', $domain),
        'date' => __('Date', $domain),
        'title' => __('Title', $domain),
        'info' => __('Info', $domain),
        'rand' => __('Random', $domain),
        'comment_count' => __('Comment count', $domain),
        'enable_lightbox' => __('Enable Lightbox', $domain),
        'enable_lightbox_desc' => __('Check this to enable the lightbox.', $domain),
        'permalink_to' => __('Permalink', $domain),
        'read_more' => __('Read more', $domain),
        'view_all' => __('View all', $domain),
        'width' => __('Width', $domain),
        'height' => __('Height', $domain),
        'excerpt_length' => __('Excerpt length (words):', $domain),
        'link_text' => __('Link Text:', $domain),
        'link_url' => __('Link URL', $domain),
        'standard' => __('Standard', $domain),
        'aside' => __('Aside', $domain),
        'quote' => __('Quote', $domain),
        'link' => __('Link', $domain),
        'image' => __('Image', $domain),
        'gallery' => __('Gallery', $domain),
        'audio' => __('Audio', $domain),
        'video' => __('Video', $domain),
        'categories' => __('Categories', $domain),
        'tags' => __('Tags', $domain),
        'show_all' => __('Show All', $domain),
        'search' => __('search', $domain),
        'go' => __('Go', $domain),
        'prev_post' => __('&laquo; Previous post', $domain),
        'next_post' => __('Next Post &raquo;', $domain),

I believe this last two lines are the ones in question but there is still more code.

Related posts

Leave a Reply

1 comment

  1. All you need to do is change the last 2 lines of the theme_local_init function from…

    'prev_post' => __('&laquo; Previous post', $domain),
    'next_post' => __('Next Post &raquo;', $domain),
    

    to…

    'prev_post' => __('&laquo; Previous work', $domain),
    'next_post' => __('Next work &raquo;', $domain),
    

    If you’re interested in learning more about how wordpress deals with translation you should read The i18n page in the WordPress codex. It may help you to understand how your theme works.

    UPDATE: or if you want to only change the text in certain situations you could add more lines to your function e.g.

    'prev_work' => __('&laquo; Previous work', $domain),
    'next_work' => __('Next work &raquo;', $domain),
    

    Then change the post_link functions in your template to use prev_work and next_work instead.

    Then the next time you generate your PO file the new translatable strings will be added.

    Hope that helps

    Dan