Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Unfortunately translating for menus isn’t implemented yet. In my site I’m switching nav menu based on the current locale by using this additional code in my custom theme’s functions.php:

    add_action( 'init', 'cf7com_register_additional_menus', 11 );
    
    function cf7com_register_additional_menus() {
    	register_nav_menu( 'primary_ja', _x( 'Primary (Japanese)', 'nav menu location', 'cf7com' ) );
    }
    
    add_filter( 'wp_nav_menu_args', 'cf7com_nav_menu_args' );
    
    function cf7com_nav_menu_args( $args ) {
    	$locale = get_locale();
    
    	if ( 'ja' == $locale )
    		$args['theme_location'] = 'primary_ja';
    
    	return $args;
    }

    Hope this helps.

    Thread Starter HrvojeKC

    (@hrvojekc)

    Thanks for the tip!

    I just wondered if there is something I fail to notice.

    With a little tweaking this worked well for me. Thanks Takayuki!

    I am quite new to php and would love a little help…
    How can I set up menu switching with 3 different languages (Dutch, English and French). I use pagelines framework that uses hooks to place code in the right area. Can you help me with the code for 3 languages and also if its possible what the hooks are in your code. Thanks a lot!

    Hello, this is how we solved switching menu based on what language is currently being displayed:

    I have 3 menus registerred:

    register_nav_menu( 'sv_SE_top-menu', 'Top Menu Sv' );
    register_nav_menu( 'de_DE_top-menu', 'Top Menu De' );
    register_nav_menu( 'en_US_top-menu',  'Top Menu En' );

    In header.php (or where you render you navigation):

    wp_nav_menu( array( 'theme_location' => apply_filters( 'language_prefix_menu', 'top-menu' ) ) );

    In functions.php:

    function add_language_prefix($menu_identifier) {
        global $post;
        $language_prefix = get_post_meta( $post->ID, '_locale', true );
        return $language_prefix . '_' . $menu_identifier;
    }
    add_filter('language_prefix_menu', 'add_language_prefix');

    The above is probably cleaner but here’s another way to slice it using 2 languages and 4 menus:
    functions.php

    function register_my_menus() {
      register_nav_menus(
        array(
          'primary-en' => __( 'Primary En' ),
          'secondary-en' => __( 'Secondary En' )
        )
      );
    }
    add_action( 'init', 'register_my_menus' )

    header.php

    <?php $locale = get_locale();
    
    	if ('es_ES' == $locale  ) { ?>
                        <?php $theme->hook('menu_primary'); ?>
    <?php } else { ?>
    <?php wp_nav_menu( array( 'theme_location' => 'primary-en', 'container_class' => 'menu-primary-container' ) ); ?>
    <?php } ?>

    Repeat if clause for additional menus.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to translate menus?’ is closed to new replies.