With a static field, containing the text "Foo Bar EN", I cannot find a way to have that translated to, for example, "Foo Bar FR" when French is active.

The field label and help test is translatable, but this is the field contents that pose a challenge.

Maybe a t() call is missing somewhere,, any suggestions?

Comments

zeppelinstudios’s picture

@boran

Have you managed to find a solution?

boran’s picture

I didn't use this module, just used a node.tpl to solve the issue :-)

claudiu.cristea’s picture

Status: Active » Closed (works as designed)
StatusFileSize
new243.1 KB

Static field works as expected and it doesn't have to be translated. If you still need translation, you are free to use the PHP code filter.

  • Go, enable the core PHP filter module.
  • Select PHP code as input format when filling the Static field text.
  • Enter your text inside t() function and return it with return statement -- everything inside <?php ?> tags.

php-filter.jpg

boran’s picture

Er, enabling the php is a drastic measure. It increases the security risk. I would not recommend that as a workaround.

claudiu.cristea’s picture

@boran, I assume that users having access to configure fields know what they are doing. So, you should control who's able to use the PHP filter and who's able to administer fields.

claudiu.cristea’s picture

Issue summary: View changes

Updated issue summary.

stolzenhain’s picture

A good way to resolve this is to rely on the Language Sections module which can handle several languages in the same input text – given you have a multiline textfield. It's much safer and faster than the aforementioned solution.

I agree though that it would be cool if these fields could be registered for the i18n module.

jimmyko’s picture

Issue summary: View changes
Status: Closed (works as designed) » Needs review
StatusFileSize
new2.75 KB

PHP filter is a really bad practice. I patched the module to make it work with i18n_string(). Hope it may help someone who looking for the similar thing.

@claudiu.cristea Please consider to commit it for enhancing the module. Thanks

jimmyko’s picture

StatusFileSize
new3.06 KB

I added the missing quotes for string and handled the deletion of translation set.

jimmyko’s picture

StatusFileSize
new3.75 KB

I realized that adding translation in form submit is not a good idea. I changed it into a more robust way.

jackalope’s picture

Thanks for the patch, jimmyko! I've applied it but I still can't figure out how to translate the "Static field content;" it doesn't show up when I translate the interface (/admin/config/regional/translate/translate). Where does the actual translation take place with your patch applied?

jimmyko’s picture

@jackalope
It would show new item on translate interface, but you have to load the page which contains the static field, which will add the string to translate interface for translation.

adinac’s picture

StatusFileSize
new3.25 KB

Status: Needs review » Needs work

The last submitted patch, 12: static_field-translable-1952212-12.patch, failed testing.

Sriparna Khatua’s picture

Assigned: Unassigned » Sriparna Khatua
Sriparna Khatua’s picture

Assigned: Sriparna Khatua » Unassigned
noah’s picture

The patch here didn't work for me, it actually caused the static field to stop appearing entirely in any language. In case it's of use to anyone, I worked around the issue by preprocessing static fields in a custom module and wrapping the markup in t() there:

function example_module_preprocess_field(&$variables) {
  if (isset($variables['element']) && (isset($variables['element']['#field_type'])) && ($variables['element']['#field_type'] == 'static_field') && (isset($variables['items']))) {
    foreach ($variables['items'] as $index => $item) {
      if (is_numeric($index) && (isset($item['#markup']))) $variables['items'][$index]['#markup'] = t($item['#markup']);
    }
  }
}

Once this is in place, the contents of the static field should be translatable like any other string. The drawback of this approach is that if the text of the field is ever changes in the source language you'll have to go back into string translations and translate again, but it seems like the least heavy-handed workaround for this issue.