Closed (fixed)
Project:
Internationalization
Version:
master
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Dec 2004 at 08:00 UTC
Updated:
28 Jan 2007 at 18:47 UTC
Jump to comment: Most recent file
Comments
Comment #1
mikeryanSecond the request!
Comment #2
loony commentedWe need this! :)
Comment #3
Marc Bijl commentedNearly December again...
Comment #4
jose reyero commented> Nearly December again...
It only means that nobody who needs it has done it yet -or did it but didnt contribute it back. But thanks for the reminder anyway. So should we have like an anniversary party? ;-)
Some good news is that I'm implementing translatable user-defined menu items for a client, so it will be here soon.
Comment #5
Marc Bijl commentedWOW... FAB, FAB, FAB!!! I'm really looking forward to it...
Sorry if my post sounded a bit frustrated, but that was just how I felt that night. Searched so long, tried so many things, but just walked in circles all the time. Wish I was a programmer, so I could help and do some additional work... Therefore: I really appreciate the things you guys do!!!
Right now I hack around this using the following code (i.e. for submenu 74 and its subs):
And then translate the separate menu-item-strings using localization. Got it from Bert somewhere at the forum. Can you please tell me Jose, if this is the best way to -temporary- solve the problem?
Thanks,
Marc
Comment #6
jose reyero commentedOk, understood.
As I told, it's in the works. Here's a "preview". Maybe someone can help me testing it? :-)
This is a new small module that runs configurable menu items through localization system. Bit tricky, but doesn't need patching :-)
Comment #7
Marc Bijl commentedOf course I want to help testing; would be great is this module is gonna work!
Can you please tell me what need to be done? Make a seperate directory for this module? Or save it in the i18n directory? Then I suppose I have to visit all of my pages (so menus) and translate the items using localization?
Comment #8
Marc Bijl commentedFirst test results are here! Probably I did something wrong, but it doesn't seem to work right now. Here's an overview of what I've done:
First, I saved the file as i18n_menu.module in the existing i18n directory (not sure if this is right - can it be the module must be saved in it's own and separate directory?);
Second, I switched the recognized module on (aminister > modules);
Third, I deleted the code from above (#5) in my page template and changed it back into:
Fourth, I deleted the rows from locales_source which were created by the code / workaround I mentioned a few posts earlier (#5), in this case rows with lid 1632, 1633, 1634, 1635, 1636;
Fifth, I deleted rows with the same lid from locales_target;
Sixth, I surfed a bit accross my website;
Seventh, I noticed a lot of new rows were created in both locales_source and locales_target;
Eighth, I translated one of the submenu-options: searched for the term "realisatie" (which means realization or building) and translated it into dutch: "realisatie" and into english: "realization";
Nineth, I surfed across the english site (newoceans.nl/en-local);
Tenth, unfortunately nothing happened. Well, nothing happened with the submenu: it's still dutch...
Comment #9
Marc Bijl commentedThis is interesting!
I managed to get the translated item visible. Only once...
Then, after quiet a struggle, I managed to get it visible again. Indeed, only once...
Finally I found out how to reproduce. It seems there's only one situation in which I can get the translated item visible, and then still once. This is the situation I'm talking about:
- I log into the dutch(!) administration using newoceans.nl/user
- I go to administer > settings, just do nothing but save configuration.
- I logout and will be redirected to newoceans.nl/nl
The first (front-) page is a kind of journal, so:
- I click on primary link webdesign, which directs to page newoceans.nl/nl/webdesign
This is the dutch page about webdesign, in an overall dutch site
The dutch page's URL alias is: "webdesign" (no language prefix in this alias)
- I click on the english language icon in the block, which goes to newoceans.nl/en-local/webdesign
This is the dutch page about webdesign, in an overall english site
The english page's URL alias is: web-design (no language prefix in this alias)
In this overall english site, there's a submenu (theme_menu_tree(74)) with indeed, the english term "realization". However...
After clicking only once on another primary link (as going to another page), to come back immediately(!), the term has already changed into "realisatie" again, and there seems to be no way to get it visible as "realization" anymore...
The only way I got it reproduced (I mean, visible as "realization" again) is as written above: log into the dutch administration, save the settings, logout (being redirected to dutch site newoceans.nl/nl), goto page webdesign, and finally click on english language button in block.
Hope this info can help...
Comment #10
jose reyero commentedThe menu items are cached, so in order to refresh the cache, you'd need to edit/save any menu item, or, in the db: "DELETE FROM cache".
Then you switch languages to any non english one, and the new strings will be in locale. After you translate them, you have to refresh the menus again.
Hope this helps
Comment #11
Marc Bijl commentedJust tried what you explained. Using "delete from cache;" has the same effect as what I found out another way, namely saving the settings. The effect is: the into english translated submenu-items are only shown once, after that, they will be shown as dutch items again - and persist in being so :-)
Summary
- login (to newoceans.nl/user = dutch site administration)
- in the database: delete from cache;
- logout (being directed to newoceans.nl/nl = dutch site = default!)
- goto page webdesign (primary link directing to newoceans.nl/nl/webdesign = dutch page in dutch site)
- english button in block (directing to newoceans.nl/en-local/webdesign = dutch page in english site*)
* Which I think is wrong; this should be newoceans.nl/en-local/web-design = english page in english site (URL alias dutch webdesignpage = "webdesign", URL alias english webdesignpage = "web design". But don't worry, that's not part of this problem - I think
Doing things written above, the submenu at the english webdesignpage shows english items (the correct translations of the dutch terms), but only once. So, after visiting any other page at this english site (newoceans.nl/en-local/...), and coming back to the webdesign page, the items are dutch again...
Even stranger than this: when looking to the page with the english submenu-items and pressing F5 (refresh)... Indeed, the submenu becomes dutch again. Just in front of my eyes :-\
Some additional information
- language: en (drupal's standard definitions, turned of)
- language: nl (custom dutch language, turned on, default)
- language: en-local (custom english language, turned on)
- In drupal I have cache support disabled**
- In firefox I have set the buffer to zero**
** Both to have a kind of "refresh" every time I visit any page (for testing purpose).
And then this info about my database tables:
After running the site with i18n_menu.module the first time, I got lots of extra rows in table locales_source and locales_target. Translating i.e. "realisatie" into "realisatie" (dutch) and into "realization" (english), I got this situation:
locales_source
- 1655 (lid)
- /en-local/admin/modules?PHPSESSID=e4378e6ffb2ef5d742616f256186c1dc (location)
- realisatie (source)
locales_target
- 1655 (lid)
- realisatie (translation)
- nl (locale)
- 0 (plid)
- 0 (plural)
- 1655 (lid)
- realization (translation)
- en-local (locale)
- 0 (plid)
- 0 (plural)
For some strange reason, later I got these rows too:
locales_source
- 1681 (lid)
- /en-local/webdesign (location) ***
- realization (source)
*** Which I think is wrong, and might be caused by clicking the english language icon in the block, directing to the wrong page (dutch page in english site) - URL alias problem?
locales_target
- 1681 (lid)
- [empty] (translation) ****
- en-local (locale)
- 0 (plid)
- 0 (plural)
**** Not too sure, but should this be empty indeed?
Well, that's quiet a lot of stuff to dig into (are you still there :-D), but I hope it makes some sense and can help solving the problems. If you have any questions, just ask; if you want me to run a kind of checklist, I'll be all yours!
Comment #12
Marc Bijl commentedIt has been changed, and it's working now - although I get some errors when translating strings...
I studied the code of i18n_menu.module, but -as not being a programmer- I didn't understand a word :-\ So I tried to do the best I could and find some logic. I recognized an if-else statement, which had to do something with the cache. Moreover, it seemed "everything" only gets translated if a certain part of the statement runs twice(?).
I thought, let's push it to translate at any run :-D Therefore I changed:
into:
A bit rude, but hey, just to give it a try and see what happens... Well, the good news is: it works! No, it rocks! The bad news is: I now get an error message everytime a translate a string... The message is like:
It's good to know where it goes wrong. I will take a further look and see what I can do... But it would be great to get some response, and maybe a hint ;-)
Comment #13
Marc Bijl commentedGet even errors at every save... So this is not the way to go :-(
Comment #14
Marc Bijl commentedAnother solution, that seems to work pretty fine (wow, exciting :-D) can be found here:
- http://drupal.org/node/25847
It's a function that I've tried to implement in:
- either page.tpl.php
- or menu.inc
Both options show the results I've been hunting for. Therefore I decided to "patch" (and document for myself) menu.inc - as it only requires one edit (I know, I know it's core...). This is the code where it's all about:
Wonder if this solution can make a chance...
Comment #15
jose reyero commentedWow!, you've been working really hard :-)
I still insist in the one I proposed -the small i18n_menu module- , but I realize it needs some more instructions. So let's try some step by step:
0. Enable i18n_menu.module
1. Create all your custom menus / menu items in English (If they're already created, it's ok)
3. Display your menu in a block
4. Switch language to some non english one -while viewing the block-, so the 'locales' table gets populated with the new strings
5. Translate the strings with the localization (manage strings) interface
6. Refresh the menu cache, for which you can:
a) Edit and save any custom menu item
or
b) In the database: DELETE FROM cache
7. Play!
When you switch languages, the *custom* menu item names should be translated.
Comment #16
Marc Bijl commentedThanks for your reply, good to hear from you! I will give your instructions a go (of course I will :-D). And while I'm doing this, I hope you're still online and see this post as I have a few questions:
drupal's english -> turned off(!)
custom dutch -> turned on -> default
custom english -> turned on
And if you have noticed, don't you think it will conflict with your proposed solution?
I also want to mention that the last post I made (#14) is not an ideal solution either, as it does not work with URL aliases. Trying to fix that, I created a situation in which my sections.module started to scream too.
Pfff, quiet some digging ahead :-\
Hope you will reply soon, in the meantime I will start working with your instructions. Thanks mate!
Comment #17
Marc Bijl commentedWow, this is whole thing is driving me crazy...
I started all over, from the very, very, very beginning, and stil it doesn't work. Here's what I did, and I'll try to explain it step by step - by step:
> enabled, default
> enabled
> enabled
* Both dutch pages with these URL aliases
The submenu-item shown was analysis (english) - so far so good...
The submenu-item shown was analysis (english) - of course not translated yet...
the submenu-item shown was analyse (translated dutch) - mmm, very promising...
the submenu-item shown was analysis (english) - indeed, translation gone...
I give up...
I tried these kind of things so many times, with all kind of settings. Every time it is like this: the right submenu-item shows up only once and that's it. Even pressing F5 (refresh) makes it disappear, right in front of my eyes. And if I do not browse to the right page immediately after deleting cache, I don't see the translated dutch submenu-item at all...
Where do I go wrong? Has it something to do with:
Help...
Comment #18
Marc Bijl commentedCan it be caused by a conflict with any other module may be (i.e. sections.module)?
Comment #19
Marc Bijl commentedCan it be caused by using this for showing a (sub-) menu:
I'm lost...
Comment #20
Marc Bijl commentedSomething with $cid may be?
Jose, I've tried to track what's going on in the cache by using drupal messages after every declaration, if-then-else, et cetera.
Can it be $cid get's a wrong value by using
$cid = "menu:$user->uid:$locale";? The one and only value I see it's getting is "menu::" both for english and dutch...Comment #21
jose reyero commentedThis was really some help, thanks :-)
Added two missing 'global' definitions. That explains why the site was working for me -developing, testing only as a single user- but not for anybody else.
Hope this one is better - I din't have the chance to test it though.
Btw: sorry abt delay, but travelling this week and really busy!. Posting from some hotel room in Barcelona :-)
Comment #22
Marc Bijl commentedHey Jose!
Good to hear from you! You're crazy man, posting from a hotel room in Barcelona... ;-)
You should be at the Ramblas! So therefore thanks very much for all your effort! And I have to say, there's some good news -well I think I can even say some excellent news(!)- and there's some "bad" news...
First things first, the good news. It works! No, it rocks! It's fab, it's neat, it's everything I have been dreaming about! And that's no joke. This is so excellent stuff, and many people have been waiting for this! Good job mate!
Second things second, the bad news... There are some errors, and warnings. Taken these into account, it's quite a "struggle" to get at the end of the road. The errors appeared when I started administering the menus and their translations - with the administration environment in the default english language (en). So I thought it had to do something with the fact I was administering. Then I found out the errors were still there when surfing the site (still logged in) in the english (en) environment, but disappeared in the dutch (nl) environment and local english (en-local) environment. So it should be something with the languages, with english (en) as my default. But then I noticed the errors disappeared in the english (en) environment too!
Hard for me to say where the consistency of this behaviour can be found. So the only thing I can do is describe what happened when I first added and administered a menu and its items. Here we go!
First is when administering and pressing "menus". Then I get this:
In the Netherlands we would say: I can't make any chocolate of this :-D
Second is pressing "add menu item". Then I get this (seems to be pretty much the same...):
Going on, which is saving the menu item, no error message appears. So, the next step is to show the menu on a webpage. Then I get both an error and a warning.
The error is (yes indeed, it's the same again...):
And the warning is:
Well, it goes on pretty much this way. But as said before, at the end of the road it rocks! Hope my description and error messages can help you adding the finishing touch. Loads of succes!
BTW
Trying to get translation of menu items working, my locales tables (both source and target) are quiet a mess... Duplicate entries, I mean, related to items with the same meaning but stored twice as some are english, and some are dutch. Some of them are related to a long path without absolute language prefix and with a session id, some of them are related to a short path with an absolute language prefix and without session id. Et cetera. Can you advice a good way to clean it up a bit?
Cheers,
Marc
Comment #23
Marc Bijl commentedAnd another question...
Is there any difference using this module between this:
and this:
And the same way: can I define my menu items in dutch (nl) and translate them into other languages,
or is it neccessary to define them in english (en) and then translate them?
Cheers,
Marc
Comment #24
jose reyero commentedWell, these errors look like it lacks something like
function i18n_menu_translate_all(){
global $_menu;
global $user;
global $locale;
$cid = "menu:$user->uid:$locale";
cache_clear_all($cid);
...
...
And about the questions, I think you could try any language for the original menu items, but for consistency with the localization system, they *must* be defined in english (en).
Comment #25
Marc Bijl commentedExcellent, this seems to do the trick!
Just implemented the latest addition, and everything seems to work fine now. Only played a bit around, will test it more extensively next few days when implementing several international menus!
Thanks so far, good job!
Comment #26
Marc Bijl commentedHi Jose!
I'm stuck, and I have a strong feeling that a solution is just around the corner :\
As the menu-items are translated by using localization now,
every menu-item has only one basic form to edit things like title, description and path.
Is that right? If so, does it mean I can only link to one, single page?
Instead I would love to link to language dependant pages...
For example, I have these two pages:
- "grafische vormgeving" (dutch page)
- "graphic design" (english page)
In fact, they're the same page (translated v.v.), but have different node id's and URL aliases.
How can I link one menu-item to any of these pages, dependant of the language the site is viewed in?
The same way, I like to link from one menu-item to nodes that have the same taxonomy term,
but which is translated and therefore is stored as two actual terms:
- "nieuws" (dutch, term 5)
- "news" (english, term 69)
Hope this makes a bit sense, and hope even more that there's a solution close by...
Thanks!
Comment #27
Marc Bijl commentedAdditional note:
I use different URL aliases because they're defined in the right language too.
This is mainly because of dutch people searching for dutch terms in search engines.
Comment #28
chombium commentedHi,
I've done some test myself 'cos I need translatable menus on the
web site I'm working on.
I'm using the English locale (that comes with Drupal) and
Macedonian (mk) locale for my native language. Default locale is English
I've done the things described in #15.
At first sight everything seemed perfect.
As I translated the "custom" menus they were appearing in the non-english
(particulary Macedonian) locale that was selected and I strated playing around.
I divided my test in two parts:
1. to check the links (browse the site) without changing the locale
2. to change the locale to English and back to Macedonian and to
do the first test again.
Here are results:
Frist test:
After translating the strings they were there in the selected locale.
Then I clicked on one link in the menu and they were gone,
tried another link and they were ok again. I've experienced something
really weird, it seems that menus appear correctly every 2nd/3rd click
click on one of the links.Sometimes I've deleted the cache, but it didn't help.
This is really weird, maybe it's just my old rusty home machine. I'll test
this on few other machines and I'll write the results.
Second test:
Switched to English. Browsing in it (the default locale) was good.
Back to Macedonian. First impression, bad. The menus were still in English.
Tried to switch the locale vice-versa but the result was same.
Contiued browsing of the site, no sight of menus translated in Macedonian.
Lastly I've set Macedonian as default locale. Nothing changed, everything
was in English.
After this unsuccessful tests, I tried to add another menu and to translated
it in Macedonian, just to see if I'll get back at the begining.
I was succesful, got back to test number 1 :-/
I'll do the same tests on some other machines in the next few days and I'll keep you
informed.
btw. Jose, Can you write some simmilar module for user created blocks? It seems to me
there wouldn't be much things to do when you'll get the menu module working.
GREETZ, chombium
Comment #29
Marc Bijl commentedHi Jovan,
Just to be sure, did you check:
• #21: http://drupal.org/node/14783#comment-52608 ?
• #24: http://drupal.org/node/14783#comment-52805 ?
Comment #30
chombium commentedHi Marc,
Seems like you had the same problems but I didn't have any problems with
the database.
I didn't read this discussion that well to find and add the code to the module :(
I'll try that now to see if it will do any good.
What do you think? Is it hard to get this working with custom blocks
GREETZ, Jovan aka chombium ;)
Comment #31
Marc Bijl commentedNo worries mate!
About translating user defined blocks: I managed to do that using i18n.module, flexinode.module and a custom defined block. You can find my solution here:
• http://drupal.org/node/37118
But it's not the best solution there is... It's pretty complex. Too complex may be. Jose Reyero (maintainer i18n.module) gave me the advice not to do that much php coding in blocks, because they are stored as field data in the database. Instead he suggested to get the same thing done creating my own modules. But therefore I need to do some homework first :-D
I would say, let's stay on topic in this post; if you want to ask me anything about the way I translated blocks, please use http://drupal.org/node/37118. Hope the info there will be helpful for you!
Success!
Marc
Comment #32
chombium commentedThank's alot mate, for pointing those posts that
i didn't read.
You saved my life ;)
After pathcing the i18n_menu.module
everything's going great.
GREETZ, Jovan
Comment #33
pepeek commentedSince there was so many changes/patch-patching going on, could you please post the very latest patched i18n_menu.module?
Thanks a lot!
--Josef
Comment #34
pepeek commentedOK, I think I've managed to get the latest module. It is the combination of #21 + added one bold line from #24 (the 'cache_clear_all' one).
What puzzles me is the behavior of i18n module itself.
I have 2 translations of one page (page translated via the i18n module: translation):
/node/12 -> English
/node/19 -> Czech
Which one should I use for the menu item path? There is only one menu Item and therefore only one path!
The behavior I got is the following:
- I've used the /node/19 (Czech) path for the menu item
- I've followed the instructions from #15 the got the i18n menu and sure it works great (Czech label for Czech language and English label for English language)
- if my starting language is Czech, then everything works great
- however, if I start browsing the site in English and I hit this menu item (pointing to /en/node/19) then the resulting page shows in Czech (remember? 19 -> Czech) instead of English.
Now the questions:
1) Should the request for /en/node/19 be inteligent and return/redirect to /node/12 (by knowing that EN is requested, which for node 19 is actualy node 12)
2) or should the menu item have two paths, one for each language?
3) Do I totaly miss something?
Your help is very apprecieted!
--Josef
Comment #35
Marc Bijl commentedHi Josef,
Just like you, I had the problem of pointing from 1 menu-item to 2 possible nodes,
depending on the sites language: http://drupal.org/node/37168
I managed to get it work, although it might not be a very clean solution...
Now I use i18n.module, and i18n_menu.module.
Besides I made some changes i18n.inc of i18n.module.
Got the idea from here: http://drupal.org/node/25847
What I did is this:
The code of the extra function:
The code of the changed function:
Hope this can help...
Cheers,
Marc (www.newoceans.nl/en-local)
Comment #36
pepeek commentedI've done the mods according to your instructions, but nothing has changed. The menu item still points to the node with incorrect language. Do I have to change theme_menu_item_link() function in my theme's template.php as noted in http://drupal.org/node/25847 ?
--Pp
Comment #37
pepeek commentedI've tried to understand your suggestion but could not make any sence of it, sorry.
If I think about my problem, here is the solution. Currently my custom menu item path is a static one as entered during the menu item creation. I need this path not to be static (as entered) but dynamic according to the current language/locale.
That means:
- while having the two nodes:
/node/12 -> English
/node/19 -> Czech
- staticly entered path in the custom menu item is:
/node/12 (English)
- now when my current language is English, my custom menu item must point to /node/12
- and when I switch to Czech then my custom menu item must also switch to point to /node/19
The best place to make this change is where the menu label is changed, which is in i18n_menu.module:
so the resulting code should be:
and the magic bit getPathForLocale is my puzzle (sorry again).
How can I get the path to the node which is a $locale translation of $_menu['items'][$mid]['path'] node? In my above example it is '/node/19' for language/locale 'cs' and original path '/node/12'.
Comment #38
Marc Bijl commentedTo point to the right node (I have 2 nodes for 1 menu-item too - dutch and english),
I added this new, extra function to i18n.inc:
In addition, I use URL aliases, which means that the path found above
needs to be turned into the right alias.
Therefore, I added this line to the existing function
i18n_l($text, $lang , $url = '' , $attributes = array(), $query = NULL) in i18n.inc:
For me these changes do the trick:
I'm not sure about how to change i18n_menu.module to get the same effect...
Comment #39
plj commentedHello Jose, Marc and others,
I've basically same requirements as Marc. What I'd have also liked, however, would have been the ability to translate the menu links manually, so that I could have pointed different languages to totally different pages – for example, one to a taxonomy term and another to a specific node.
I first turned on i18nmenu.module, and make the following change into it:
I also tried Marc's approach. Unfortunately, the problem with both of these approaches is that they do not work if some of the translated menu items are collapsing, as they both break menu.inc's
menu_set_location(). This is quite nasty, because clicking a parent menu item won't then reveal its children, unless user switches to english site.Any suggestions? All hacks are welcome, as this came as a nasty surprise, and I should get the site to function Real Soon Now.
Comment #40
adixon commentedi think i had this same problem (though i just had a little line of code to translate menu items that are nodes), and solved it by going into the $_menu internals to also change the reverse path stored in the 'path index' key. In other words, if your change path $path for menu item $mid to $new_path, you also need to do this:
in order for menu_active_trail to behave properly.
Note - this was in 4.6, i haven't looked at 4.7 to know whether this would work.
Comment #41
adixon commentedsee my patch here:
http://drupal.org/node/76631
Comment #42
jose reyero commentedThis is already implemented in i18n DRUPAL-5 branch
Comment #43
(not verified) commented