Hello, just install last dev. version with the new feature "Activity per node type".

It works great! thanks.

But I would like to translate both Author message & Public message.

I don't know exactly how to do it. How it works. With tokens. Is the t funtion works?

What have I to do?

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Scott Reynolds’s picture

I originally thought this would be easy but its going to require some more work.

When we display the message, we are going to need to have the message template. Then str_replace [ with ! and str_replace ] with ''. Then pull out the final message and to find the positions of the token replacement and extract for translation.

This, will end up being a separate Views handler. It will behave like the current Views handler, but because of the extra overhead, I only want it deployed on sites needing translation.

This is in the works.

Basically, make the message t()-able

Scott Reynolds’s picture

Im goin to tackle this when I decide to take on this itch. But these are my final implementation thoughts
1.) add another column to the activity_messages table called 'template'. This template will reflect the message template used to generate the message but it will be processed

// make the template column the t()-able string
str_replace("[", "!", $message);
str_replace("]", "", $message);

2.) create a activity_views_handler_translatable_field_message handler. This is the Views Field handler that handles the translation and the only piece of code that uses the new column. In this handlers pre_render() function, it processes the message using some string magik to find and set the message up for t(). Pulls out the variables based on the template and the actual message.

The reason for the new handler, is so that sites not requiring multiple languages for their activity messages don't have to handle the extra overhead.

Junro’s picture

ok thanks! I knew it it will be not so easy! Unfortunatly I can't contribe to this work, I'm not a php developper. But I will follow it with great attention!

Scott Reynolds’s picture

Ok I came up with a solution that I like this weekend. Basically, avoid t(). t() is useful if you can distrubte translations for that specific string with the module. In this case, we can't predict what the text will be in the message.

So, in the activity messages table, we add a column language. And we do a Views query substitution **CURRENT_USER_LANGUAGE** in the JOIN to the Activity table.

This then means on the activity templates form, we present fieldsets for each language on the server for messages. This allows us to deal directly with the language and we avoid having to deal with t() and variables and such.

It is modeled off how path.module deals with multiple language.s

Scott Reynolds’s picture

As a followup, coming from a discussion on the Dev list.
http://drupal.org/node/304002

vermario’s picture

Hi!

Reading your second to last message, I wonder whether you have already implemented the solution you propose,or if it just means you made up your mind on how to do it in the future... :-)

so, any updates on this feature?

Thanks! :)

thekayra’s picture

subscribing...

Scott Reynolds’s picture

Title: Translation of activity messages per node type. » Provide a means for translating activity messages
Assigned: Unassigned » Scott Reynolds
Category: support » feature

Changing title

Scott Reynolds’s picture

FileSize
10.29 KB

Ok so here is a patch. I haven't decided on if I should write an update function as this will blow up all your existing activity messages and templates. It requires this to be run on your mysql server

alter table activity_targets add column language char(2);

and then apply this patch and clear ALL caches (the schema and Views for sure need to be cleared)

You should see a fieldset for each langauge on the message creation page like this
http://skitch.com/supermanscott/nb2gj/edit-scotts-contrib

Scott Reynolds’s picture

Status: Active » Needs review
FileSize
10.25 KB

reroll without the dpm() in it

Scott Reynolds’s picture

Having thought about the update it becomes as simple as this

update_sql("UPDATE {activity_targets} SET language = '%s'", language_default()->language);

or in plain mysql

UPDATE activity_targets SET language = 'en';

Where 'en' is for english. use the proper language code for your desired language for the older messages.

vermario’s picture

GREAT! :-)

Will test as soon as possible and report results.

Scott Reynolds’s picture

Status: Fixed » Needs review

This has been committed. http://drupal.org/cvs?commit=271064

After talking briefly with sirktree we both agree, no update function needs to be written as there hasn't been a stable release.

If you were using Activity2 on a production site prior to that commit, then you will need to update your database

ALTER TABLE activity_targets ADD COLUMN language char(2);
ALTER TABLE activity_targets DROP PRIMARY KEY;
ALTER TABLE activity_targets ADD PRIMARY KEY (aid, uid, language);
ALTER TABLE activity_targets ADD UNIQUE KEY (amid);
UPDATE activity_targets SET language = 'en';

Please remember that I use 'en' for the last MySQL query there as my sites default language is 'english'. Use the proper two digit language code for that.

Scott Reynolds’s picture

Status: Needs review » Fixed

Marking as fixed.

vermario’s picture

Very, very cool!
It seems to work perfectly.

Only doubt I have (maybe it's by design): when viewing activity views as a logged in user, the language settings set in the path prefix do not seem to be respected. The only way to change the messages from english to the secondary language is to change the user preference language setting. Just using the language switcher theme or changing the path prefix does not have any effect.

Anyway, thank you very much for this, it was really needed! :-)

Now off to the next task, integrating it somehow with userpoints and organic groups. I'll read the docs.

Scott Reynolds’s picture

Only doubt I have (maybe it's by design): when viewing activity views as a logged in user, the language settings set in the path prefix do not seem to be respected. The only way to change the messages from english to the secondary language is to change the user preference language setting. Just using the language switcher theme or changing the path prefix does not have any effect.

ugg! unfortunetly links will have to be handled differently. I would sugguest an implementation, like globalredirect module, that redirects a node/nid to the proper path prefix for the given user.

There is no way around this with Activity, it really is by design.

Junro’s picture

Thanks for this new feature! I will use it as soon as possible on my website. www.pariscine.com, on user profile page. :)

vermario’s picture

ugg! unfortunetly links will have to be handled differently. I would sugguest an implementation, like globalredirect module, that redirects a node/nid to the proper path prefix for the given user.

Hi!

I'm not sure I understand your suggestion... I'll try to explain the situation better.

User: Mario
Language (set in user profile): Italian
Goes to: mysite/it/activity/all -> Activity elements in italian
Goes to: mysite/en/activity/all -> Activity elements in Italian

User: Bob
Language (set in user profile): English
Goes to: mysite/it/activity/all -> Activity elements in English
Goes to: mysite/en/activity/all -> Activity elements in English

So, the view is not reacting to the language setting (which drupal gets through the path prefix), but only to the setting of each user.

To be sure to have a view in which activity messages would show only in English or Italian, what shall I do? Is there some filter i can set in the view? This way I could make two different views and send users there.

(it's not really a big deal, but it is to clarify.. :-) )

thanks!

Scott Reynolds’s picture

Sure so Activity module use the Language set by user profile always.

It could conceivably just default to the global language which I believe is set by the path prefix. Unsure at the moment.

What I meant was the node links. So if the message is "Bob created Awesome post ", does the link work right? does it redirect to the proper node? does the path prefix work?

AntiNSA’s picture

I am receiving this error:

user warning: Unknown column 'activity_targets.language' in 'on clause' query: SELECT activity.aid AS aid, COALESCE(activity_personal_messages.message, activity_messages.message) AS activity_messages_message, activity.aid AS activity_aid FROM activity activity INNER JOIN node node_activity ON activity.nid = node_activity.nid INNER JOIN users users_activity ON activity.uid = users_activity.uid INNER JOIN activity_targets activity_targets ON activity.aid = activity_targets.aid AND (activity_targets.uid = 0 AND activity_targets.language = 'en') INNER JOIN activity_messages activity_messages ON activity_targets.amid = activity_messages.amid LEFT JOIN activity_targets activity_personal_targets ON activity.aid = activity_personal_targets.aid AND (activity_personal_targets.uid = 1 AND activity_personal_targets.language = 'en') LEFT JOIN activity_messages activity_personal_messages ON activity_personal_targets.amid = activity_personal_messages.amid ORDER BY activity_aid DESC LIMIT 0, 10 in /home/cyberfan/htdocs/modules/views/includes/view.inc on line 765.

And was directed to this thread. I am using 6.13 and would love to fixx it. Any ides?

Aldus’s picture

I subscribe #20 , same (huge) error on last version

AntiNSA’s picture

Priority: Normal » Critical
Status: Fixed » Active
vermario’s picture

What I meant was the node links. So if the message is "Bob created Awesome post ", does the link work right? does it redirect to the proper node? does the path prefix work?

Ok, I got what you mean. I'm currently unable to test this, the content type i used cannot be translated. I'll try to setup a sandbox situation to test this.

Scott Reynolds’s picture

Priority: Critical » Normal
Status: Active » Fixed

This issue is fixed. Please follow the instructions in #13 to update your site.

As this module is in Development currently and there is no stable release, we are not writing code to update your site. You will have to do it by hand. And in #13 I gave you all the instructions, just copy and paste into phpmyadmin, mysql terminal or whatever.

AntiNSA’s picture

Thank you . fixed now.

Status: Needs review » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chinabruce’s picture

Status: Closed (fixed) » Needs review

I hacked the file *activity.module* like this:

line 1032:
if ($pattern = variable_get($var, FALSE)) {
//added by bruce
$pattern = t($pattern);
// Invoke activityapi

Then i can translate the messages in the tokens.

Scott Reynolds’s picture

But why woudl you do that? Why didn't you use the tools that are already available? Why wouldn't you set up different messages for different languages?

Using t() will NOT be part of this module. tt() maybe just maybe. (http://drupal.org/project/i18n).

t() is reserved for mostly static strings. Because each message will be different there it is inappropriate. http://drupal.org/node/304002

chinabruce’s picture

I think setting up different messages is inconvenient, and i need to do more hacks.
After t() added, i can find the messages template in the translation interface.i.e. *[author] commented on [parent-node-link] saying [comment-subject]* can be translated to be *[author] 回复了 [parent-node-link] 说 [comment-subject]*.

I am not very clear why we should not use t(). Please explain it more clearly, Thanks.

Scott Reynolds’s picture

Status: Needs review » Closed (fixed)

t() is not for dynamic strings. Read up on 18n module. And the reason why this won't use tt() or t() is because every language has its own tricks and stuff. this issue is closed, please leave it as such.

I think of it as the following, "Use t() if you could potentially ship a .po file for the message." Given that everyone's message will be completely different, there is no way we could ship a .po file for all possible messages.

yosisays’s picture

I'm using the latest dev. version and I'm still seeing the error:

user warning: Table 'drupal.activity_messages' doesn't exist query: SELECT COUNT(*) FROM (SELECT activity.aid AS aid FROM activity activity LEFT JOIN node node_activity ON activity.nid = node_activity.nid INNER JOIN users users_activity ON activity.uid = users_activity.uid INNER JOIN activity_targets activity_targets ON activity.aid = activity_targets.aid AND (activity_targets.uid = 0 AND activity_targets.language = 'en') INNER JOIN activity_messages activity_messages ON activity_targets.amid = activity_messages.amid LEFT JOIN activity_targets activity_personal_targets ON activity.aid = activity_personal_targets.aid AND (activity_personal_targets.uid = 1 AND activity_personal_targets.language = 'en') LEFT JOIN activity_messages activity_personal_messages ON activity_personal_targets.amid = activity_personal_messages.amid ) count_alias in C:\wamp\www\drupal\sites\all\modules\views\includes\view.inc on line 739.

user warning: Table 'drupal.activity_messages' doesn't exist query: SELECT activity.aid AS aid, COALESCE(activity_personal_messages.message, activity_messages.message) AS activity_messages_message, activity.aid AS activity_aid FROM activity activity LEFT JOIN node node_activity ON activity.nid = node_activity.nid INNER JOIN users users_activity ON activity.uid = users_activity.uid INNER JOIN activity_targets activity_targets ON activity.aid = activity_targets.aid AND (activity_targets.uid = 0 AND activity_targets.language = 'en') INNER JOIN activity_messages activity_messages ON activity_targets.amid = activity_messages.amid LEFT JOIN activity_targets activity_personal_targets ON activity.aid = activity_personal_targets.aid AND (activity_personal_targets.uid = 1 AND activity_personal_targets.language = 'en') LEFT JOIN activity_messages activity_personal_messages ON activity_personal_targets.amid = activity_personal_messages.amid ORDER BY activity_aid DESC LIMIT 0, 25 in C:\wamp\www\drupal\sites\all\modules\views\includes\view.inc on line 765.

I checked the files from the patch and found they were already updated. what do i need to do?

(i'm using drupal v. 6.15 ,php v. 5.2.11, and MySQL v. 5.1.36)
Thanks

Scott Reynolds’s picture

This doesn't have anything todo with this issue, BUT it looks like your Activity module didn't install properly. This could be a number of reasons.
1.) you installed Activity 1.x first -> There is no upgrade path yet
2.) your install file is corrupted
3.) (THE LEAST LIKELY) activity.install has a bug in it.

So, how you can fix, is to reinstall activity module to check to see if it works now. if not, please open a NEW ISSUE with the errors that happen WHEN YOU REINSTALL the module. Don't post the errors from the View.

Reinstalling the module will delete any activity that you have recorded up to this point.

yosisays’s picture

your right. i didnt unistall activity 1.x properly. that fixed it. thanks