function _localize_fields_i18n_field_context in Localize Fields 7
Parameters
string $context:
string $source: Non-empty if copying to i18n_field.
boolean $to_foreign: Default: FALSE (~ copy from i18n_field to localize_fields). TRUE: copy from localize_fields to i18n_field.
Return value
string Empty: context can't be resolved or isnt usable.
1 call to _localize_fields_i18n_field_context()
- _localize_fields_copy_i18n_field_translations in ./
localize_fields.admin.inc - Batch callback.
File
- ./
localize_fields.admin.inc, line 450 - Drupal Localize Fields module
Code
function _localize_fields_i18n_field_context($context, $source = '', $to_foreign = FALSE) {
static $markers = array(
'base' => 'field',
'instance' => 'field_instance',
'delim' => LocalizeFields::CONTEXT_DELIMITER,
'delim_bundle' => LocalizeFields::CONTEXT_DELIMITER_BUNDLE,
);
if ($context !== '') {
if (!$to_foreign) {
$parts = explode(':', $context);
$le = count($parts);
if ($le == 3) {
// Instance.
if ($parts[2] === 'label' || $parts[2] === 'description') {
return $markers['instance'] . $markers['delim'] . $parts[1] . $markers['delim_bundle'] . $parts[0] . $markers['delim'] . $parts[2];
}
// Field.
if ($parts[1] === '#allowed_values') {
return $markers['base'] . $markers['delim'] . $parts[0] . $markers['delim'] . 'allowed_values';
}
// i18n offers translation of properties 'setting_add'/'setting_delete' which we don't know what's used for;
// they are _not_ multi-row field instance settings (like 'Add' another file)
}
}
else {
// Instance.
if (strpos($context, $markers['instance'] . $markers['delim']) === 0) {
return preg_replace('/^([^\\' . $markers['delim_bundle'] . ']+)\\' . $markers['delim_bundle'] . '([^\\' . $markers['delim'] . ']+)' . $markers['delim'] . '/', '$2:$1:', substr($context, strlen($markers['instance'] . $markers['delim'])));
}
// Field.
if ($source !== '' && strpos($context, $markers['base'] . $markers['delim']) === 0 && strpos($context, $markers['delim'] . 'allowed_values')) {
$field_name = str_replace($markers['delim'] . 'allowed_values', '', substr($context, strlen($markers['base'] . $markers['delim'])));
$field_info = field_info_field($field_name);
if (!empty($field_info['settings']['allowed_values_no_localization']) || empty($field_info['settings']['allowed_values'])) {
return '';
}
if (($value = array_search($source, $field_info['settings']['allowed_values'], TRUE)) !== '') {
return $field_name . ':#allowed_values:' . $value;
}
// localize_fields translates (numeric) prefix and suffix; i18n_field doesn't.
}
}
}
return '';
}