Integration with WP3 Nav Menu Feature

Having Problems? Need Help? Post here!

Re: Integration with WP3 Nav Menu Feature

Postby bedex78 » Tue Nov 23, 2010 2:56 am

@NengQs:

As far as I know, you can't auto-translate external links. You probably need to hard code it.
bedex78
 
Posts: 31
Joined: Mon Oct 04, 2010 9:11 am

Re: Integration with WP3 Nav Menu Feature

Postby ddyer » Tue Nov 23, 2010 1:49 pm

Hi, WordPress newbie here. I've managed to use both your first and second solutions to successfully localize the actual link text (appearing between the <a ...> and </a> tags. I believe thats the Navigation Label argument, but the anchor tag's title attribute and URL I'm unable to localize.

My Nav Label looks like : [:en]Test EN[:fr]Test Fr[:id]Test ID
I've tried the title the same, and also tried using <!--:en --><!--:--> notation. The first way displays the full string eg "[:en]Test EN[:fr]Test Fr[:id]Test ID" and the second just whatever is in between the html comment tags eg:

<!--:en -->Test EN<!--:--><!--:fr -->Test Fr<!--:--> writes TestENTestFR into the title atttribute of the rendered a tag.

URL seems to be unable to save if it isn't simply http://.... so I'm unable to modify that at all.

Any hints or ideas as to what I'm doing wrong?

EDIT: Additional info, I'm using WordPress 3.0.1 and the Constructor theme by Anton Shevchuk.
ddyer
 
Posts: 3
Joined: Tue Nov 23, 2010 10:26 am

Re: Integration with WP3 Nav Menu Feature

Postby bedex78 » Tue Nov 23, 2010 4:24 pm

@ddyer:

For the attribute, if you're using solution #1, you might want to change this line:

Code: Select all
$attributes  = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';


to this:

Code: Select all
$attributes  = ! empty( $item->attr_title ) ? ' title="' . $item->attr_title .'"' : '';


Then use <!--:en --><!--:--> to translate it.

This is just a theory since I haven't tried it myself. Technically, the esc_attr() function encodes '<' and '>', which was why the <!--:en --> filter couldn't work.

As for the URL, I'm not really sure why it didn't work as I can't really tell what you were doing. The only two possibilities that I can think of is either you are linking to external URL or your theme isn't utilising the native WP3 nav menu.
bedex78
 
Posts: 31
Joined: Mon Oct 04, 2010 9:11 am

Re: Integration with WP3 Nav Menu Feature

Postby ddyer » Tue Nov 23, 2010 5:52 pm

You're right about the URL's, it's because I was testing using an external link
ddyer
 
Posts: 3
Joined: Tue Nov 23, 2010 10:26 am

Re: Integration with WP3 Nav Menu Feature

Postby pankipan4e » Thu Dec 23, 2010 4:05 pm

Hey @bedex78 , I've tried your first solution and all the menu items disappeared except the home button. The other 2 I don't know how to use them. Can you please help, it's urgent. I haven't set custom menu, and in the header.php I have this line: <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?> . It's the twentyten theme.
pankipan4e
 
Posts: 3
Joined: Thu Dec 23, 2010 3:54 pm

Re: Integration with WP3 Nav Menu Feature

Postby bedex78 » Sun Jan 02, 2011 1:54 am

Hi, @pankipan4e... I can't really tell unless you give me more details of what you did... and probably give me the URL of the website you're working on so I can have a look...
bedex78
 
Posts: 31
Joined: Mon Oct 04, 2010 9:11 am

Re: Integration with WP3 Nav Menu Feature

Postby gazpachu » Tue Jan 25, 2011 11:22 pm

Any idea on how to translate the URL of external menu links?

Code: Select all
<!--:en-->https://webmarket.es/clients/index.php?lang=English<!--:--><!--:es-->https://webmarket.es/clients/index.php?lang=Espanish<!--:-->


If I try to save that code, it disappears :cry:

From my Wordpress website I need to link to a CRM.
gazpachu
 
Posts: 3
Joined: Wed Dec 29, 2010 7:36 pm

Re: Integration with WP3 Nav Menu Feature

Postby marsv » Thu Feb 03, 2011 4:50 am

@bedex78
thanks so much! you are amazing... spent hours looking for a solution and technique #2 worked for me (but not #3) with WP3 & studiopress genesis (delicious child theme).
marsv
 
Posts: 2
Joined: Thu Feb 03, 2011 4:47 am

Re: Integration with WP3 Nav Menu Feature

Postby mattcav » Thu Feb 10, 2011 4:41 pm

How can I translate also item->description and item->attr_title?

I've tried to remove esc_attr() function, but it doesn't works.

I use <!--:en--> method on the menu field.
mattcav
 
Posts: 2
Joined: Thu Feb 10, 2011 4:33 pm

Re: Integration with WP3 Nav Menu Feature

Postby brasofilo » Sat Feb 12, 2011 7:27 pm

the same as abmcr solution but i modified 1 extra line in nav-menu.php (WP 3.0.4):
Code: Select all
//line 79
$title = empty( $item->label ) ? __($title) : __($item->label);

// line 240 : added __($)
$output .= empty( $item->label ) ? esc_html( __($item->title) ) : esc_html( __($item->label) );

abmcr wrote:I have solved the problem 2


<!--:en-->Page<!--:--><!--:it-->Pagina<!--:-->

but with an edit on the core file :-(
I post this edit , may be someone put the code in the functions

I have edited the nav-menu.php file into the wp-admin/includes folder


i have changed the line 240 as
Code: Select all
   $output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->label );


in
Code: Select all
      $output .= empty( $item->label ) ? esc_html( get_language($item->title) ) : esc_html( get_language($item->title) );


And i have added this small and stupid function at line
257

Code: Select all
function get_language($mystring,$lg='it'){
      //find the position of the strin needed
      $pos=strpos($mystring, $lg."-->");
      if (!$pos) return $mystring;
      $string=substr($mystring, $pos+5, (strlen($mystring)-($pos+5)));
      //now search the end of the language identifier
      $pos=strpos($string, "<!--:-->");
      $string=substr($string, 0, -(strlen($string)-$pos));
      return $string;
   }

NB: in this function the filter is based on the code of language: in this example the italian language. Change as your preference

Bad code, i know :-(
If this function goes on the functions php file of the theme....
brasofilo
 
Posts: 15
Joined: Sun Feb 06, 2011 5:45 pm

PreviousNext

Return to qTranslate Support Forum

Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 3 guests