Edit: The latest version does not need any modification to core code! Simply install and use..
Edit: This module is now in cvs!
Hi all--
I think there are a few people out there who really want this feature.. we don't have a full solution yet, but I have put together some code to support this with only a small change to the G2 core code, so if you're interested you can try it out.
What it does:
- Adds a site admin page to pick the languages you wish to support
- Adds a MultiLanguage tab on the edit item view.. here you can set the title/summary/description for your additional languages (you still put the "primary" title/summary/description in the normal edit view)
- When items are loaded it checks the multilanguage table for the user's language and overrides the title/summary/description if data is found
The first 2 items above fit nicely in G2's module system.. the last one requires a small change to G2 core code.
To use this module:
- Download the attached file and unzip in your gallery2/modules directory
- Edit modules/core/classes/GalleryItem.class and add the following code just before the last } in the file:
function onLoad() {
$ret = parent::onLoad();
if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); }
$view = GalleryUtilities::getRequestVariables('view');
if ($view != 'core:ItemAdmin') {
GalleryCoreApi::relativeRequireOnce('modules/multilang/classes/MultiLangHelper.class');
$ret = MultiLangHelper::onLoad($this);
if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); }
}
return GalleryStatus::success();
}
- Install/activate the module, visit the site admin page to pick languages
- Edit a few items to set captions in multiple languages
- Change the language for your session (visit site admin / general to turn on language selector in sidebar if needed) to see the captions change!
Enjoy![/]
[/]
Posts: 328
Awesome, it totally rocks! The UI needs some improvement, but its a first nice step in a good direction here!
Thanks, mindless
Posts: 8601
Agreed.. I just put together the minimum to get the functionality for those who really want it.. it's lacking in:
- seamless integration (needs that patch)
- search support
- performance (adds a query for every item loaded.. no caching now)
Posts: 8601
and baschny pointed out that if you edit the regular title/summary/description while your session language is one of your additional-languages then it will show you the multilanguage data instead of the real title/summary/description data. so be careful of this if you try out this module... edit the primary title/summary/description fields with your session using your primary language.
Posts: 24
Are there any updates to this code? Any work to get it into the mainline?
It'd be great to have multi-language captioning out-of-the-box.
Posts: 8601
no further work has been done. if anyone is interested in working on this, let us know.
i just updated the attachment above to work with recent core api changes.
Posts: 2
API is updated again. Can you please update your module? Thanks a lot. :D
Posts: 314
mindless, if you don't mind I'll be happy to take over it (especially that I really need it as well)
Posts: 8601
attachment above is updated.. thanks for the reminder to post the update.
virshu, do you have a design in mind to make this a well-behaved module? (ie, not requiring that patch in GalleryItem....) Perhaps an onLoad event? (adds a big load in event management though, as this event happens extremely frequently)
Posts: 8601
I also updated the "onLoad" block in the first post above to resolve the problem where multilang data is shown in Edit Item / General... it won't put the multilang data in place for core:ItemAdmin view so you'll see the primary language data while editing items.
Posts: 314
My first reaction would be to have module to register an even listener, something like:
and then have GalleryItem traverse the list of registered modules. That's what you are suggesting, right?
Performance-wise, I thought that if there are no modules registered, and there is no list to got through, then the performance overhead is minimal (although minimal times a lot may still be too bad). I guess, it's worth getting it implemented - and then do some profiling...
Posts: 8
Is there any online example of this setup ?
thanks
Gr Ovis
Posts: 314
mindless, I noticed that if I start gallery and I am already logged in, I am getting default captures only. Apparently, Gallery::setActiveUser() is never called, and my language never gets put in the session. So, when Gallery::getActiveLanguageCode() is trying to get language from the session - there ain't none!
If I log out and then log back in - it's working fine.
I realize, that if my analysis is correct - it isn't really up to this module to fix it... But I think you still would want to know it :wink:
Posts: 314
ouch, and if you make all the changes that are required you won't be able to get into SiteAdmin menu...
Apparently, GalleryItem is trying to execute the module before it is even activated. So, for now you need to install and activate the module first, and make changes in GalleryItem only after that...
Posts: 8601
yes, i didn't put an active-check in this hack
Posts: 8601
how can setActiveUser not get called? it's in init.php, GalleryInitSecondPass. maybe you can debug further why you see the wrong language..
Posts: 314
will do... Bharat gave me 4-page code review; my ears are buring; in the meantime I played with the locks too much (the habits of old thief die hard ) and now nothing is working; so it will take a little while!
btw, what did we decide about 'registering' for OnLoad (if anything)?
I'll keep posting here (probably tomorrow)
Posts: 314
mindless, you were right - my guess about setActiveUser was off-base... Here is what's happening - if you go to User preferences, and change the language - this change doesn't propagate to current session. Once I have the following change in UserPreferences
it works fine.
If you don't have any objections - I'll check it in.
Cheers
Posts: 8601
sounds good to me.. and since you took us on a tangent, how about posting something to get this topic back on track?
Posts: 314
attached is the module that doesn't require 'hacking' the core code; however it does require changing core code (the difference between hacking and changing will be a topic of another discussion :P )
You need to take out the changes that were described in GalleryItem.class and replace the onLoad function with the following:
I think merging this into the base is coming soon now...
Posts: 8601
yes, i already have code like this in my dev install.. the code you posted doesn't work though, right? to implement this event strategy i had to change GalleryEvent to set and get the entity by reference.. otherwise your event handler is just setting the multilang values on a copy of the item..
how will you handle searching? i suppose you can implement the search interface and search against the session's language, though it will seem odd to users that the main search checkboxes apply to some other language and to search against their own lang they must check some other box..
Posts: 314
eeehhh - it does work... http://www.galan.rabinovich.org/gallery2/ I wouldn't post this code here if it didn't, now wouldn't I?
What I think is happening - PHP5 is copying obects by reference without any additional effort on my part. When I uploaded to PHP4 site - it is indeed making changes on the update only, and you are right - it doesn't work!
So, for all of you on the edge with PHP5 - take it away... The others should upgrade :evil:
Posts: 8601
Today I added an onLoadHandlers field to GalleryEntity. Now multilang module can add a handler on any item where multilang data is added. Bonuses:
1) this module works with no changes to core code
2) query on multilang table is only executed for items that have some multilang data (not necessarily for the active language though)
I've attached the updated module back in the first post of this topic. I also added a search impl.. so now you can search the title/summary/description of the active language too. seems like we are much closer now to getting this module in cvs.. we'll see how the next review goes.
Posts: 8601
Remaining problems:
1) if you have a non-default language selected the first time an item is loaded then the captions for that language are placed in the disk cache.. if you then switch to the default language you still see those captions (since it gets the item from the cache). i have a core update locally that fixes this.. basically always put the pre-onload item into the disk cache. this makes more sense anyway since we already run onload after we load an item from the disk cache (so currently those items get on-loaded twice).
2) sooner or later you're gonna get your default-language captions overwritten by another language.. since we replace the default language captions with the active language at the time the item is loaded, if at some time later in the request that item gets saved it will save with those values in place. the 0.3.0 code skips the multilanguage check for core:ItemAdmin view so you see the right thing in the edit-item General tab. i found if i save a change on edit-album Album tab I can get the active-language captions copied into the main captions. i can avoid this by checking for ItemEdit controller, but who knows where else an item may get saved? perhaps the right thing is to skip multilanguage check for any controller? hmm..
Posts: 40
whoops.... ignore this post...
:roll:
Posts: 8601
um, Jester2000, maybe you thought you were posting in the G2 Demo Sites topic..
Posts: 8601
fix for #1 above just committed to cvs.
Posts: 8601
this module is now in cvs, yay!
for problem #2, i went with skipping the multilang check for any controller.. so it's possible some delegated view may show default language instead of active language, but much less likely your captions will get overwritten accidentally.
Posts: 30
Hello
Thanks for this great MultiLanguage Module
But i have a question about comments !
I don't want for example that a deutsh see french comments !
How can we do ?
Thanks a lot for everything
Isa