Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Using t()
inside hook_field_formatter_info()
apparently doesn't work, as seen in #1211728: Labels untranslated.
Comment | File | Size | Author |
---|---|---|---|
#6 | 873834.png | 62.73 KB | tim.plunkett |
#1 | field_collection-1246778-1.patch | 2.88 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettComment #2
fagoActually I'm not sure how this should be handled. One should not pass dynamic variables into t(), however I think this is how core handles node type translation too. Then there is the i18n API for this, e.g. http://drupal.org/node/1114010
Maybe we should try to get input from someone with i18n skills?
Comment #3
Dave ReidThe settings in formatter_info should probably be something like 'edit' => TRUE, 'delete' => TRUE rather than the labels as the key values.
Then in the formatter_view itself, declare an array of the labels for $op:
then output $op_labels[$op] where desired.
Comment #4
Dave ReidOr something like:
Comment #5
Dave ReidI rescind my suggestions - I wasn't completely aware of how this worked.
Comment #6
tim.plunkettHere is the screenshot. For those not familiar with the module, you can configure which operations are available, and what their labels are.
Comment #7
Gábor HojtsyI'm not sure what is the root of the problem here. Is it that hook_field_formatter_info() is called / cached in a different HTTP request and therefore might be cached in a different language? That could easily be a problem. Cached data where the cache key does not include the language code should not use t(). I'd produce the labels based on the keys when the UI is actually constructed, but with verbatim text like t('Edit'), so it is actually picked up by the translation engine properly.
Comment #8
tim.plunkettSo are you saying we should replace the textfields with checkboxes? That we can't have dynamic strings like that?
Comment #9
Gábor Hojtsy@tim.plunkett: Anything that is user editable (except if its a node or a path alias or date format in D7), Drupal core DOES NOT provide ANY solution for its translation. if you want to have user customizable text to be translated the only solution right now is the Drupal 7 i18n_strings module under the i18n module suite. This will not be solved in other ways likely before Drupal 8.
Comment #10
fagothanks Gabor - so it looks like we have to go with i18n for that.
Still, is it good practice to have translated defaults ala t('Edit') ?
Comment #11
tim.plunkettHonestly, I'm not sure that the links should be editable in the GUI. I think
hook_field_formatter_info_alter()
is enough to expose the setting.Comment #12
tim.plunkettIf someone wants to work on i18n integration, feel free.
Comment #13
dolilmao CreditAttribution: dolilmao commentedI'm trying to create a block to list all field collection items and "add" links to add the field collection item like following. I am very new to drupal can someone point me out to how i do this. I have tried to create a block and using the code that list add path in field collection module it does not work. Please help
Photo add
Video add
Comment #14
dolilmao CreditAttribution: dolilmao commentedI'm trying to use the following code to list links to add field collection item is a block but i get a bunch of error printed on the page.
Comment #15
RobW CreditAttribution: RobW commented@dolilmao, That's a support request; you should make a new issue with your problem instead of tacking it on here. This issue is just for adding translation to user created add/edit/delete links to the field collection module. You might also look for help in #drupal-support on IRC.
Good luck.
Comment #16
jmuzz CreditAttribution: jmuzz commentedI've made a start on this, and have some hooks that will store the values entered on the display settings form and allow translations to be added for them. I don't see a good way to have these translations be displayed. The problem is in the field_collection_field_formatter_view function where it should happen. It needs to use the name of the display mode as part of a string key for i18n_string(), since these links could potentially have different labels for each display mode. The hook does not have access to the name of the display mode as described here:
http://drupal.stackexchange.com/questions/39224/how-to-get-view-mode-fro...
This is what I have so far: