• Hello!
    I use Polylang and have made a searchform.php in my Zerif Lite Child theme. I would like to translate the terms “Search for:” and “Search on our website”, so that is dependent on the chosen language. How can I do it?
    `<?php
    /**
    * default search form
    */
    ?>
    <form role=”search” method=”get” id=”search-form” action=”<?php echo esc_url( home_url( ‘/’ ) ); ?>”>
    <div class=”search-wrap”>
    <label class=”screen-reader-text” for=”s”> <?php _e( ‘Search for:’, ‘zerif-lite-child’ ); ?></label>
    }
    <input type=”search” placeholder=”<?php echo esc_attr( ‘Search on our website’, ‘zerif-lite-child’ ); ?>” name=”s” id=”search-input” value=”<?php echo esc_attr( get_search_query() ); ?>” />
    <input class=”screen-reader-text” type=”submit” id=”search-submit” value=”Search” />
    <input type=”submit” class=”search-submit” value=”S?k”>
    </div>
    </form>`

    https://www.ads-software.com/plugins/polylang/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Chrystl

    (@chrystl)

    Hi

    You can use the Loco Translate plugin to handle these translations.

    But before replace:

    <?php echo esc_attr( 'Search on our website', 'zerif-lite-child' ); ?>

    by

    <?php echo esc_attr_e( 'Search on our website', 'zerif-lite-child' ); ?>
    Thread Starter AudunBK

    (@audunbk)

    I understand that Loco Translate can be used to edit .po files, but since this is a searchform.php that was not part of my theme but one I added which .po file should I edit?

    Plugin Support Chrystl

    (@chrystl)

    You can create your po/mo files or edit them thanks to Loco Translate. Select your Zerif Lite Child theme in Loco Translate and choose to edit your po file if it exists.

    Thread Starter AudunBK

    (@audunbk)

    Thanks for the fast replies! I have created a nb_NO : Norwegian (Bokm?l) translation of my child theme in Loco Translate, where I also translated the string ‘Search on our website’ as mentioned above. So this looks promising. But when I choose “Norsk Bokm?l” in Polylang on my page, nothing is changed. The strings that should have been translated remains the same. Must I do something to make my theme use the translation or link it with Polylang?

    Plugin Support Chrystl

    (@chrystl)

    Do you use a cache plugin?

    Thread Starter AudunBK

    (@audunbk)

    No, I don’t. I have tried to clear cache in my webbrowser, but it did not help.

    Plugin Support Chrystl

    (@chrystl)

    Did you change the nb_NO Locale in your language (Settings > Languages > Languages tab)?

    Thread Starter AudunBK

    (@audunbk)

    No, but I see that the setting is correct. The current setting for “Locale” is “nb_NO” for “Norsk Bokm?l” in the language tab.

    Plugin Support Chrystl

    (@chrystl)

    I tested and it works with this code:

    <form role="search" method="get" id="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <div class="search-wrap">
    <label class="screen-reader-text" for="s"> <?php _e( 'Search for:', 'zeriflitechild' ); ?></label>
    }
    <input type="search" placeholder="<?php esc_attr_e( 'Search on our website', 'zeriflitechild' ); ?>" name="s" id="search-input" value="<?php echo esc_attr( get_search_query() ); ?>" />
    <input class="screen-reader-text" type="submit" id="search-submit" value="Search" />
    <input type="submit" class="search-submit" value="S?k">
    </div>
    </form>

    * I added a languages directory: zerif-lite-child/languages/

    * I defined the textdomain in the functions.php.
    See: https://developer.www.ads-software.com/themes/advanced-topics/child-themes/#internationalization

    * I enqueued Styles and Scripts in the functions.php.
    See: https://developer.www.ads-software.com/themes/advanced-topics/child-themes/#7-enqueueing-styles-and-scripts

    * I created my po/mo files thanks to Loco Translate then put them in zerif-lite-child/languages/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Translate search form’ is closed to new replies.