Skip to content

Instantly share code, notes, and snippets.

@kramapet
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kramapet/c1127438c10dd36e3aec to your computer and use it in GitHub Desktop.
Save kramapet/c1127438c10dd36e3aec to your computer and use it in GitHub Desktop.
Drupal API - How to add field translation for label
<?php
$entity = 'node';
$field_name = 'employee_first_name';
$bundle = 'employee';
$lang_code = 'fi';
$value = 'Nimi';
// get field instance
$instance = field_info_instance($entity, $field_name, $bundle);
// get instance of i18n_field_instance
$field_instance = i18n_object('field_instance', $instance);
// get textgroup and context
// field:$field_name:$bundle:label
list($textgroup, $context) = i18n_string_context('field:employee_first_name:employee:label');
i18n_string_textgroup($textgroup)->update_translation($context, $lang_code, $value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment