0

I'm translating my whole site with gettext and I'm using shortcodes for the content in my pages that in turn call gettext. However shortcodes don't seem to work for menu items I need to figure out a way to translate them.

I'm wondering whether there is some way to modify my menu from my functions.php to add it a _("") function somewhere between retrieving the menu items labels from the database and echoing them.

Is that possible? if not, how can I translate menu items?

  • Although admiring the learning / coding drive , why not using a plugin like qTranslate ? – krembo99 Mar 8 '14 at 4:12
0

Retrieved menu items pass through wp_get_nav_menu_items filter, as well as few others in wp_get_nav_menu_items() and around.

--

EDIT - This is what I used:

function translate_menu( $items, $menu, $args ) {
    foreach ( $items as $key => $item ) {
        $items[$key]->title = _($items[$key]->title);
    }
    return $items;
}
  • Thanks Rarst, I just found it in wp-includes. If imagine that if I modify it there it won't survive wordpress updates, is there any way to add gettext from wp-content? – Lisandro Vaccaro Mar 7 '14 at 20:36
  • @LisandroVaccaro why? The whole point of filters is to be able to modify data without editing core code. – Rarst Mar 7 '14 at 20:39
  • thanks Rarst, I hadn't read about filters until now. I got it to work, I'll add the code to your answer – Lisandro Vaccaro Mar 7 '14 at 20:51

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.