2

I'm using entity_metadata_wrapper with entity translation to print fields in a template, but it always prints the default language when using a langcode in the options.

$wrap = entity_metadata_wrapper('node', $node->nid, array('langcode' => 'zh-hans'));
print $wrap->field_main_subtitle->value(); // Returns English value

Printing out the $wrap array shows the following towards the end which might give some clue (langcode:protected => und):

[propertyInfoAltered:protected] => 
    [langcode:protected] => und
    [propertyInfoDefaults:protected] => Array
        (
            [type] => text
            [getter callback] => entity_property_verbatim_get
            [clear] => Array
                (
                )

        )

    [type:protected] => node
    [data:protected] => 
    [info:protected] => Array
        (
            [langcode] => zh-hans
            [type] => node
            [property defaults] => Array
                (
                )

        )

Any ideas?

0

Try this

print $wrap->language('zh-hans')->field_main_subtitle->value()
1
  • 1
    This works, but I thought one of the benefits of entity_metadata_wrapper was that you didn't need to hardcode the language when printing fields?
    – Chris
    Feb 17 '16 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.