You are here

function i18nstrings_context in Internationalization 6

Convert context string in a context object.

Example: 'taxonomy:term:1:name'

will become a $context object where $context->textgroup = 'taxonomy'; $context->type = 'term'; $context->objectid = 1; $context->property = 'name';

Examples: 'taxonomy:title' -> (taxonomy, title, 0, 0) 'nodetype:type:[type]:name' 'nodetype:type:[type]:description' 'profile:category' 'profile:field:[fid]:title'

When we don't have 'objectid' or 'property', like for 'profile:category' we need to use the string itself as a search key, so we store it in $context->source

If the name has more than 4 elements glued by ':' we add the remaining ones into property

Parameters

$context: Context string or object.

$string: For some textgroups and objects that don't have ids we use the string itself as index.

Return value

Context object with textgroup, type, objectid, property and location names.

20 calls to i18nstrings_context()
i18ncontent_node_help_source in i18ncontent/i18ncontent.module
Fetch default source for node type help
i18nprofile_update_2 in i18nprofile/i18nprofile.install
Drop old table and fields.
i18nstrings_add_string in i18nstrings/i18nstrings.module
Add source string to the locale tables for translation.
i18nstrings_cache in i18nstrings/i18nstrings.module
Retrieves and stores translations in page (static variable) cache.
i18nstrings_get_source in i18nstrings/i18nstrings.module
Get source string provided a string context.

... See full list

File

i18nstrings/i18nstrings.module, line 763
Internationalization (i18n) package - translatable strings.

Code

function i18nstrings_context($context, $string = NULL, $format = 0) {

  // Context may be already an object.
  if (is_object($context)) {
    return $context;
  }
  else {

    // Split the name in four parts, remaining elements will be in the last one
    $parts = explode(':', $context);
    $context = new Stdclass();
    $context->textgroup = array_shift($parts);
    $context->type = array_shift($parts);
    $context->objectid = $parts ? array_shift($parts) : '';

    // Remaining elements glued again with ':'
    $context->property = $parts ? implode(':', $parts) : '';
    $context->format = $format;
    $context->location = i18nstrings_location($context);

    // The value may be zero so we check first with is_numeric()
    if (!is_numeric($context->objectid) && !$context->objectid && !$context->property && $string) {
      $context->source = $string;
    }
    return $context;
  }
}