not-only-code / qtranslate-slug

Adds support for permalink translations and fix some Qtranslate deficiencies since wordpress 3.0
http://wordpress.org/extend/plugins/qtranslate-slug
46 stars 31 forks source link

Translate support in Custom links in Nav Menus #20

Open not-only-code opened 11 years ago

not-only-code commented 11 years ago

I think andreu is talking about the custom links where you input the links manually. It is not a bug. I assume you just didn't implement the functionality to that feature. However, like andreu said, by manually applying qTranslate's tags (<--:en-->), it will automatically become compatible with the plugin's nav menu translator.

jeroenschermer commented 11 years ago

do you have a solution at the moment?

Deelux commented 11 years ago

You can very easily add different languages by using the shortcodes: [:en]Home [:de]Startseite [:tr]Anasayfa

You just add these at the "Navigation Label" of your menu.

jeroenschermer commented 11 years ago

thanks, this works great

2013/5/27 Deelux notifications@github.com

You can very easily add different languages by using the shortcodes: [:en]Home [:de]Startseite [:tr]Anasayfa

— Reply to this email directly or view it on GitHubhttps://github.com/not-only-code/qtranslate-slug/issues/20#issuecomment-18501820 .

http://www.arkvannoach.com/

robertdiaz commented 11 years ago

Using a quick tag works for the name of the link, but I'm actually curious about the URL of the custom link. In my case, my custom link is an inline anchor link. WP doesn't seem tike quick tags or xml language tags. It just removes everything.

renesprringmann commented 11 years ago

Will it be possible to define a different link for each language too, i would really need this. So somthing like "[:de]http://google.de[:en]http://google.com" could work.

jsapoznik commented 11 years ago

After all day of reaseach on custom link I was able to fix it by creating two menus, one in english (Nav_en) and one in spanish (Nav), which is also selected as default menu, and default language is Spanish. Then on Header.php I added this code:

Let me know if it worked for you, Cheers!!

robertdiaz commented 11 years ago

Wow, this worked for me as well.

If you only have 1 or 2 custom links in your navigation, you could just add some inline css to your header with your if statement solution, in order to show/hide the custom links depending on the language.

For example: <?php if(qtrans_getLanguage()=='en') // put your inline css here to hide any non-English links { ?>

<?php } elseif(qtrans_getLanguage()=='es') // put your code here if the current language code is 'es' (Español) { ?>

<?php } ?>

not-only-code commented 11 years ago

Added as enhancement https://github.com/not-only-code/qtranslate-slug/issues/55

jsapoznik commented 11 years ago

So I just encounter a problem with the code... It doesn't work with Chrome installed in languages that are neither english or spanish... Maybe it's missing one generic line of code for a default language, Any thoughts on this?

LC43 commented 11 years ago

For example, to use english as the fallback language, use this:

} else {
// the default lang, u can use the english code
}

On Thursday, October 24, 2013, Johanna wrote:

So I just encounter a problem with the code... It doesn't work with Chrome installed in languages that are neither english or spanish... Maybe it's missing one generic line of code for a default language, Any thoughts on this?

— Reply to this email directly or view it on GitHubhttps://github.com/not-only-code/qtranslate-slug/issues/20#issuecomment-27027727 .

LC43 commented 11 years ago

So for example

if (qtrans_getLanguage()=='es') {
  wp_nav_menu( array('menu' => 'Nav' ));
} else {
  wp_nav_menu( array('menu' => 'Nav_en' ));
}
bmachuel commented 10 years ago

Try and copy/paste this in your function.php:

// Makes menu urls work with Qtranslate
function qtranslate_menu_item( $menu_item ) {
  if (stripos($menu_item->url, get_site_url()) !== false){
    $menu_item->url = qtrans_convertURL($menu_item->url);
  }     
  return $menu_item;
}

add_filter('wp_setup_nav_menu_item', 'qtranslate_menu_item', 0);
/**************************************************/
dvkch commented 10 years ago

This last answer works like a charm but not for themes with a top left icon going to the home page. I use Responsive theme, and there is an icon the upper left corner of the header, above the main menu, which gets the user to the home page. This link resets the current language.

dvkch commented 10 years ago

Woops, actually the link is alright. Sorry for the previous post

oaigudmundsson commented 10 years ago

Thanks bmachuel! It works!

jlnery-zz commented 10 years ago

hello,

I tried the "bmachuel" solution, and looks solve the problem of showing the url in the menu.

My problem is when I try to save it. When I put the url with tags: "http://xxxxx/pt

http://xxxxx/en http://xxxxx/es" The string is not commited in the database when i save in Admin page. I have to updade in database the string, so I can retrieve the url with the bmachuel solution. Somebody have any idea?
derbub commented 10 years ago

Thank you, bmachuel, works perfectly. I just have one little issue: I have a language selector in one menu (custom links which link to the domain itself (language 1) and the domain/sl (language 2). Your function now translates these links as well, turning them into domain/sl (language 1) and domain/sl/sl (language 2).

Is there away to make your function work only on one of the two menus? Or not allow it to translate in the second?

Thanks for your help,

derbub

bmachuel commented 10 years ago

Hi Derbub,

Have you tried Qtranslate's built-in language selector?

Benoît

lepatachou commented 10 years ago

@bmachuel : thanks for your solution but when I put your code at the end of function.php (WP 3.8.1), an error occurs : Fatal error: Call to undefined function add_filter() in /home/MyName/public_html/wp-includes/functions.php on line 4205

LC43 commented 10 years ago

@lepatachou no no no , that code should go into your theme's function.php. don't edit that file wp-includes/functions.php, its the wordpress core file. If you update wp, all the changes will be lost.

wouts commented 10 years ago

I don't understand the posted solution of you bmachuel. I want the shortcodes to work with my custom links. By adding your code to functions.php it still doesnt save the shortcoded custom link fields, so it doesn't do anything.

Please explain further for non-coders.

lepatachou commented 10 years ago

@LC43 : Thanks for your remark. It works fine now. @wouts : shortcodes are not saved in data base but added, by this code, dynamicaly in the link.

wouts commented 10 years ago

Aha, yes it works. I checked the code and it looks for your site url (your domain) in the custom link. It didnt work because i had my links like this: /#link (without the domain in front). made them like this: http://mydomain.com/#link And it works. Thanks for your reply lepatachou, and also big thanks to bmachuel for the code ofcourse!

derbub commented 10 years ago

Hey bmachuel,

the widget is not really an option for me, as I need to include the language selector in the top primary menu. Is there maybe a way to disable your function for a certain menu, keeping it working for the other menus?

bmachuel commented 10 years ago

@derbub Can you post a link to your webpage so that we have an idea of what you are trying to achieve?

sardbaba commented 10 years ago

@bmachuel thanks, qtranslate_menu_item is a lifesaver!

jp1976 commented 10 years ago

hi, i have inserted the @bmachuel code in my theme functions.php, but, a question, how i can insert my custom link in menu? I need to make a menu with links to an external site, but with correct language redirection. qtrans Shortcodes don't works. Can u help please?

jp1976 commented 10 years ago

it works, but i have checked the code and it looks for your site url, now i have another problem, i need to insert an external custom link (from another site) and NOT from my site.

ratulo commented 10 years ago

@bmachuel hi, just great piece of code. Is it possible to somehow exclude 1 or more items from menu? I mean everywhere give me www.xxxxxx.com/pl/xxxxxx,but i need i one item to give me wtihout language- just pure www.xxxxx.com/xxxx. is it somehow with some class or what? Thanks all best

pollydesh commented 9 years ago

Hello,

@wouts - how did you add the custom urls? Because I have pasted the code from @bmachuel and also tried lots of different ways to put the links in the menu (I am ok with the headers using "За тебFor You" for instance) but with the urls I have no success. And the theme doesn't give me to create different menus (because it has different navigations and for each navigation it only gives me one option to put only one menu there).

Please, I could really use some help here :)

bmachuel commented 9 years ago

@wouts Can you post a link to your webpage so that we have an idea of what you are trying to achieve?

testdummyid commented 9 years ago

Thanks bmachuel.

I have used following code shared by you and it works for me. Cheers!!!!! // Makes menu urls work with Qtranslate function qtranslate_menu_item( $menu_item ) { if (stripos($menu_item->url, get_site_url()) !== false){ $menu_item->url = qtrans_convertURL($menu_item->url); }
return $menu_item; }

add_filter('wp_setup_nav_menu_item', 'qtranslate_menu_item', 0); /**/

davITnemec commented 8 years ago

Hello everybody. I have similar problem like you solved it before.

I have multilanguage blog and I need set up custom links from menu.

EN blog page -> link www.abc.co.uk and text "Visit us" CS blog page -> link www.abc.cz and text "Navštivte nás" SLO blog page -> link www.abc.si and text "Pogledajte nas"

I'm able to set up texts of links, but links - URL address I'm not. I tried to add @bmachuel function to functions.php file, but when I opened Appereance->Menu page, there is a error.

image

Could you please help me? Thank you

bmachuel commented 8 years ago

Can you please copy/paste the block of code you are using so that we can see what line 26 looks like?

davITnemec commented 8 years ago

I used excatly the same part of code like you posted and the error is on this line:

$menu_item->url = qtrans_convertURL($menu_item->url);

bmachuel commented 8 years ago

You did not say whether you were using qtranslate or qtranslate-x. If you are using qtranslate-x, you need to re-activate deprecated functions at the bottom of the Integration menu (Settings>Languages>Integration

davITnemec commented 8 years ago

Thank you, I'm using qtranslate-x and after clicking on that checkbox it works. But I still can't change URL of link. When I filled normal URL, it is stay for every language. If I tried like on picture, it's gone after clicking on save. What am I doing wrong? :)

image

bmachuel commented 8 years ago

Have you tried to use the "Language switcher" menu instead?

davITnemec commented 8 years ago

How do you mean it? :) I'm using Language switcher for switching language of my blog and it works. Now I would like to have classic menu ITEM which has not only different label, but also different URL link inside. Does Language switcher able to do that? And if yes - how? :) Thank you

bmachuel commented 8 years ago

Try this:

Create 3 custom URL menus (one for each of EN, CS and SL) and place them above one another.

EN: put the English URL only and leave navigation labels empty except for the English language. Same for the other 2 languages.

davITnemec commented 8 years ago

You are THE king! Thank you a lot. It's woking now!

bmachuel commented 8 years ago

You are welcome. Benoît ———

David Němec a écrit:

You are THE king! Thank you a lot. It's woking now!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/not-only-code/qtranslate-slug/issues/20#issuecomment-244052041,

or mute the thread https://github.com/notifications/unsubscribe-auth/AGYS3N4A8_A8g9vqj7-UK6ktlItHcPG1ks5qlrepgaJpZM4AUm-l.

maioona commented 8 years ago

Hi @bmachuel You are very helpful to everyone.

Please I am trying to read and search but no luck.

I have two languages website. My menu is all custom links. I have already created two sepreate menus for each language, EN and AR. But I can not see an option to choose one for each language I only have ONE option for the MAIN MENU. So please can you tell me hwat do u mean by this, sorry i couldnt understand it. I have managed to change labels languages using [:en]Director General Message[:ar]رسالة المدير العام[:] but links are one only.


Try this:

Create 3 custom URL menus (one for each of EN, CS and SL) and place them above one another.

EN: put the English URL only and leave navigation labels empty except for the English language. Same for the other 2 languages.


please advice thanks a lot

jannekeenzo commented 7 years ago

Hello @bmachuel,

I read you helped a lot of people, that's so good to see! Unfortunately the solutions mentioned don't seem to work for me.

I have a bilingual site (NL-ENG). With Full Page sections (vertical scroll), with anchors in it instead of Row ID's (via plugin FullPage for Visual Composer). In the Menu, I therefore have set custom URL's, but they cannot be saved for each language.

I copy/pasted your code to the Functions.php of the PhotoMe theme, but nothing changed. Maybe because the kind of ID I use is different?

The other solution, create multiple menus, I do not get how to place multiple menus "above one another".

Can you help me out?

Website: https://andantec.nl/

Menu: schermafbeelding 2017-07-04 om 15 54 16

Thanks in Advance! Janneke

bmachuel commented 7 years ago

Hi there,

I am not sure what exactly you want to achieve.

I visited your website and the only thing that does not seem to work is that when you select the alternative language, it takes you back to the top of the page instead of the anchor you were in. Is that the problem you want to solve?

jannekeenzo commented 7 years ago

Hi!

Sorry I wasn't very clear indeed.

The English menu doesn't work, only the pages that have exactly the same name in Dutch work (Contact, Partners).

But other pages like Prices or About me don't jump to the page because their exact URL cannot be saved in the Menu.

The problem you mentioned (switching language and then moving to the top instead of the anchor in the other language) would be nice, but is not that important.

Kind regards, Janneke

bmachuel commented 7 years ago

There should be a solution to your problem in this thread, but if you need a quick solution without any additional coding, you can use the following plugin: Menu Item Visibility Control

It adds a "visibility" field to each menu item, whereby you can toggle visibility based on a condition of your choosing, including the active language. Just duplicate all menu items that do not currently work and add the desired condition to that field. Not very elegant but efficient indeed.

jannekeenzo commented 7 years ago

Hello,

Thanks a lot, in the meantime, i was trying another time to understand your 2nd solution, which i figured out now (& which works!!): Make a menu for your first language including navigation labels; remove all navigation labels in the other language tab. And then add a home and following pages for the second language including navigation labels; remove the navigation label in the first language tab.

Thanks for that solution and also your other suggestion, the plugin Menu Item Visibiliy Control. You seem to know a lot about the subject!

Kind regards, Janneke

bmachuel commented 7 years ago

Great! Happy you managed to make it work. Best wishes, Benoît

fedenuche commented 7 years ago

Hi, thanks in advance for your help.

This is my site (http://depraiabrasil.com), if you go to the menu (located on the top left) you can see that the last item is "Reservation". That is a custom link with a external link. On the home page it is working as expected but if you go to other page (exaple: http://depraiabrasil.com/en/kitesurf/) you will see that the link has my site URL before. So instead to show <a href="http://external_site_link"> it shows<a href="http://depraiabrasil.com/en/http://external_site_link">

I'm tried to use the setlang=no parameter but it didn't work.