Hi.
I'm the author of the localizer module : http://drupal.org/project/localizer
My module provided multilingual content support for Drupal.

I've implemented also an engine to translate user provided strings, such
as CCK forms items labels, or fields values.

I've received a request : http://drupal.org/node/117256 to provide
multilingual support to CCK created contents, but this would
require changes on CCK front using Localizer translation engine.

Do you think that this could be possible ?

Thanks

CommentFileSizeAuthor
#13 cck_t_labels.patch1.59 KByched

Comments

yched’s picture

Hi Roberto,

Localizer looks really appealing, integrating cck with it seems like a good idea, of course.
CCK already "integrates" with other contrib modules (Views, Pathauto), the preferred way when possible being the inclusion of an additional .inc file containing the relevant code, in order to ensure clean separation.

Can you provide more info on the changes you mention ?

Roberto Gerola’s picture

Thanks for your fast response.

> Can you provide more info on the changes you mention ?
Sure.
At now Localizer provide node translation support creating multiple nodes
and assigning a different language to every node.
Then the routing engine shows the wanted localized node.
This is already works, also if I have to provide a better integration with image
fields of CCK, but this is out of this request and I should be able to do in Localizer.

Well, what it should necessary to translate are the fields labels and the possible
values lists.
I have not found enough time to take a deep look to CCK sources, but what would
be necessary is :

- administration front : changes on the interface where the user can create its content type where
he can provide different translations of the fields titles and values lists.
I'll begin in the next days to work on a generic support for this using Ajax.
My idea is to provide a button near every field that is to translate, where a
layer popup will provide the language for the field and a field where to insert
the translation. This should be the less invasive solution for every interface
and could be easy integrated also in other modules, of course.
I think I should be able to prepare the patch necessary for this.
I don't know enough CCK to say that this can be implemented in an
external submodule

- presentation front : when a CCK content is rendered, the labels or the list of values
should be translated. This can be done using an API that Localizer provide : tobject
that permits the translation of an "object"
If needed I can implement other APIs, to simplify the use of Localizer from external modules.

Let me know what do you think and if a collaboration is possible.

Thanks

yojoe’s picture

Thank you for addressing this issue. Translation of CCK content types is one of the most important issues on my list.

Will it also be possible to provide/store translations of the human-readable name of a content type?

The labels of select boxes/check boxes/radio buttons are currently setup as key|value pairs using one single textfield widget for all key|value pairs. I don't think that it will be possible to provide a user friendly way to translate those labels using this approach. We probably need a new interface for defining the key|value pairs. We probably need a separate widget for each key|value|label pair of an option widget. The key and value of an option are certainly the same for all translations, but just the label needs to be translatable.

Roberto Gerola’s picture

> Will it also be possible to provide/store translations of the human-readable name of a content type?
Sure.

>The labels of select boxes/check boxes/radio buttons are currently setup
>as key|value pairs using one single textfield widget for all key|value pairs
>I don't think that it will be possible to provide a user friendly way to translate
>those labels using this approach

I'll try something but I think it is possible.
Localizer provides a table : localizertranslation where is possible to store
translations of everything. It has the following columns :
object_name
object_key
object_field
locale
translation

The first three fields compose the key with which a translation string can be retrieved.

About the interface translation :
the popup layer will need only to know this key to make the translation.
This translation interface will be separated from CCK module but would be more generic
because I am preparing it to translate also menu titles and descriptions, taxonomy dictionaries
and terms, variables, user profile and so on.
It will be an interface provided directly by Localizer, and it will be possible to launch it in a very simple
way.
Near every textfield that contains the title of the widget we could put a small button.
Clicking on it, and passing the translation key to it, a popup layer will appear where the user will
be able to insert the translation of the textfield.

On the other end, when a content is rendered, the titles should passed through a call
to localizer engine to translate it.
This perhaps could be done externally, I think, as I already do for menu and taxonomy interfaces.

karens’s picture

The tricky thing here is going to be interacting with the CCK cache. We can't cache translated values which is why many things don't use the t() function. Unfortunately, I have no solution, I just wanted to bring this up and keep it on the table.

Roberto Gerola’s picture

>The tricky thing here is going to be interacting with the CCK cache.
>We can't cache translated values

I don't know exactly how the CCK cache work, but I think it is possible to fix it.
Actually i have written some small patches to Drupal core that permit the cache
of the pages in different languages adding the page language in the key.
A similar solution perhaps is possible with CCK cache ?

yched’s picture

Cache : this could be possible.

More generally, we have to take these two facts into account :
- you probably don't want to have to ship localizer with patches the user should apply to cck (wich code is constantly moving anyway...)
- we probably don't want to sprinkle if(module_exists('localizer') { } branches all around cck code. And what you describe does not seem to be containable in a content_localizer.module...

For instance, I don't think the UI to translate field labels belongs to cck - it should be implemented through hook_form alter form another module - which would probably be localizer.
Intercepting fields on display to translate labels might not be easy too.

Roberto Gerola’s picture

> you probably don't want to have to ship localizer with patches
Absolutely no :-)

>we probably don't want to sprinkle if(module_exists('localizer') { }
I agree

Yes, the way to follow is to implement some hooks.

I'll proceed with the translation interface, make some experiments
and then we can see what we can do.

Thanks.

giorgosk’s picture

I just wanted to point out that "Text - text fields" as opposed to "Integer - text fields" get translated OK (using Localizer and as the CCK stands at this moment) but only when you "edit" the node not when you "view" it (??????)

I guess that is happening because not all strings are wrapped around "t()" function ? (as KarenS is pointing out)

What would happen if all "field label text" were wrapped around in "t()"s ? would I run into trouble with the CCK cache or the drupal cache ?

(In my setup the "limited" translation of "text text fields" labels is taking place OK - I do have drupal cache disabled though)

karens’s picture

The CCK cache is the issue. Each node's view is cached so you don't have to re-run all the field queries every time someone views the output, so nothing in the view can be wrapped in a t() unless we store a separate cached view for each language. Doing that would require code changes, so it has to be carefully thought through. There's no problem on the edit form since that's not cached, which is why wrapping form labels in t() works fine.

giorgosk’s picture

i finally managed to get a temporary solution http://drupal.org/node/119103#comment-205029

translates the CCK field labels
and apparently the field values are searchable (??)

karens’s picture

That's an interesting solution, and I think it could actually be done in the core version so you don't have to customize your theme. yched, you work with translations more than I do. Do you see any problem with making that change to field.tpl.php in CCK?

Just for reference, the change to field.tpl.php is to add the t() there, as:
if (!$field_empty) : $label = t($label);

yched’s picture

Status: Active » Needs review
StatusFileSize
new1.59 KB

Sure, we should have done that earlier
(I did not actually have to set up any multilingual site yet, so I type my labels directly in french :-) )

I guess I'd rather do that like in the attached patch, actually.

karens’s picture

Thinking about this more, will this still end up getting cached? It won't go into the CCK cache but would go into the regular page cache if caching is used, so might still be a problem if we do it in the content module itself. Sites that only have a single language could safely use it in their themes, though, so maybe we just need to document that.

Maybe it's really OK, just checking.

giorgosk’s picture

I have been using it with drupal cache ON all this time and it seem ok

yched’s picture

We're sort of hijacking the thread, which was much larger than just labels (which are harmless IMO)
My fault, I should have posted my followup #13 in the 'display translated labels on node view' thread : http://drupal.org/node/119103.

yched’s picture

Status: Needs review » Active

and the patch should not be reviewed here - I'm posting it to the other thread

yched’s picture

FYI, the 'translate label on node display' issue in http://drupal.org/node/119103 is now fixed

yojoe’s picture

Any progress on that, yet? Is it possible to translate the prefix/suffix strings of a field?
I have fields like 'Maximum Occupancy' where the English suffix is 'person|persons', but in another language this has to be translated.

yojoe’s picture

Will it be possible to translate CCK field labels with Drupal 6?

karens’s picture

Status: Active » Closed (won't fix)

This is an old thread from the D5 version and translation is handled differently in D6, plus there are more recent issues about it and the Localizer module seems not to have a D6 release. Unless there is some specific task that still applies to the D6 version, I'm going to close this issue as being outdated.