You are here

i18ncontent.module in Internationalization 5.3

Same filename and directory in other branches
  1. 5 experimental/i18ncontent.module
  2. 5.2 experimental/i18ncontent.module

Internationalization (i18n) package - translatable content type parameters

@author Jose A. Reyero, 2007

File

experimental/i18ncontent.module
View source
<?php

/**
 * @file
 * Internationalization (i18n) package - translatable content type parameters
 * 
 * @author Jose A. Reyero, 2007
 *
 */

/**
 * Implementation of hook_node_info()
 * 
 * Returns node types with translated info
 */
function i18ncontent_node_info() {

  // No db rewrite sql here, so we don't need to worry about our own rewriting
  $type_result = db_query('SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC', 'nt', 'type');
  while ($type = db_fetch_object($type_result)) {
    $type->name = tt("nodetype:{$type->type}:name", $type->name);
    $type->description = tt("nodetype:{$type->type}:description", $type->description);
    $info[$type->type] = (array) $type;
  }
  return $info;
}

/**
 * Implementation of hook_content_type()
 * 
 * @todo More fine grained, just update the given node type (not possible when changing type name)
 */
function i18ncontent_node_type($op, $info) {
  switch ($op) {
    case 'update':
    case 'insert':
    case 'delete':
      i18ncontent_locale_refresh();
  }
}

/**
 * Blocks retrieving of normal content types
 */
function i18ncontent_db_rewrite_sql($query, $primary_table, $primary_key) {
  if (preg_match("/SELECT nt\\.type, nt\\.\\* FROM {node_type} nt/", $query)) {

    // Using FALSE here doesn't work with older mysql versions
    return array(
      'where' => '0 = 1',
    );
  }
}

/**
 * Implementation of hook_locale().
 */
function i18ncontent_locale($op = 'groups', $group = NULL) {
  switch ($op) {
    case 'groups':
      return array(
        'nodetype' => t('Content type'),
      );
    case 'refresh':
      if ($group == 'nodetype') {
        return i18ncontent_locale_refresh();
      }
  }
}

/**
 * Refresh content type strings.
 * 
 * @todo Clean up leftover strings
 */
function i18ncontent_locale_refresh() {
  foreach (node_get_types() as $type) {
    tt("nodetype:{$type->type}:name", $type->name, NULL, TRUE);
    tt("nodetype:{$type->type}:title", $type->title_label, NULL, TRUE);
    tt("nodetype:{$type->type}:body", $type->body_label, NULL, TRUE);

    /*
    if ($type->help) {
      ts("nodetype:$type->type:help", $type->help, NULL, TRUE);
      $type->help = '';
      node_type_save($type);
    }
    */
  }
}

Functions

Namesort descending Description
i18ncontent_db_rewrite_sql Blocks retrieving of normal content types
i18ncontent_locale Implementation of hook_locale().
i18ncontent_locale_refresh Refresh content type strings.
i18ncontent_node_info Implementation of hook_node_info()
i18ncontent_node_type Implementation of hook_content_type()