diff --git a/i18n.api.php b/i18n.api.php new file mode 100644 index 0000000000000000000000000000000000000000..5bd40e92e04ce09c49ed6eef3f45e39005ea7ba6 --- /dev/null +++ b/i18n.api.php @@ -0,0 +1,100 @@ + t('Node type'), + // Field to be used as key to index different node types + 'key' => 'type', + // Mapping object fields and menu place holders + 'placeholders' => array( + '%node_type' => 'type', + ), + // Path for automatically generated translation tabs. Note placeholders above are used here. + 'edit path' => 'admin/structure/types/manage/%node_type', + 'translate tab' => 'admin/structure/types/manage/%node_type/translate', + // We can easily list all these objects because they should be limited and manageable + // Only in this case we provide a 'list callback'. + 'list callback' => 'node_type_get_types', + // Metadata for string translation + // In this case we are defining fields and keys for string translation's string names + // String ids are of the form: [textgroup]:[type]:[key]:[property] + // Thus in this case we'll have string names like + // - node:type:story:name + // - node:type:story:description + 'string translation' => array( + 'textgroup' => 'node', + 'type' => 'type', + 'properties' => array( + 'name' => t('Name'), + 'title_label' => t('Title label'), + 'description' => t('Description'), + 'help' => t('Help text'), + ), + 'translate path' => 'admin/structure/types/manage/%node_type/translate/%language', + ) + ); + // Example information for taxonomy term object, see i18n_taxonomy_i18n_object_info(). + $info['taxonomy_term'] = array( + 'title' => t('Taxonomy term'), + 'class' => 'i18n_taxonomy_term', + 'entity' => 'taxonomy_term', + 'key' => 'tid', + 'placeholders' => array( + '%taxonomy_term' => 'tid', + ), + // Auto generate edit path + 'edit path' => 'taxonomy/term/%taxonomy_term/edit', + // Auto-generate translate tab + 'translate tab' => 'taxonomy/term/%taxonomy_term/translate', + 'translation set' => array( + 'class' => 'i18n_taxonomy_translation_set', + 'table' => 'taxonomy_term_data', + 'field' => 'i18n_tsid', + 'parent' => 'taxonomy_vocabulary', + 'placeholder' => '%i18n_taxonomy_translation_set', + 'list path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets', + 'edit path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets/edit/%i18n_taxonomy_translation_set', + 'delete path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets/delete/%i18n_taxonomy_translation_set', + 'page callback' => 'i18n_taxonomy_term_translation_page', + ), + 'string translation' => array( + 'textgroup' => 'taxonomy', + 'type' => 'term', + 'properties' => array( + 'name' => t('Name'), + 'description' => array( + 'title' => t('Description'), + 'format' => 'format', + ), + ), + ) + ); + return $info; +} + +/** + * Alter i18n object information provided by modules with the previous hook + * + * @see i18n_object_info() + */ +function hook_i18n_string_info_alter(&$info) { + +} \ No newline at end of file diff --git a/i18n_menu/i18n_menu.i18n.inc b/i18n_menu/i18n_menu.i18n.inc index 650ffb0d7fe68faa473fa52ed7e3b28ce61cfa20..35516d18daf0fc7165e9883b77fe078c1675da3d 100644 --- a/i18n_menu/i18n_menu.i18n.inc +++ b/i18n_menu/i18n_menu.i18n.inc @@ -85,7 +85,7 @@ function i18n_menu_i18n_string_info() { } /** - * Implements hook_i18n_string_list() + * Implements hook_i18n_string_objects() */ function i18n_menu_i18n_string_objects($type) { if ($type == 'menu_link') { diff --git a/i18n_string/i18n_string.api.php b/i18n_string/i18n_string.api.php new file mode 100644 index 0000000000000000000000000000000000000000..9381b6e5dff50dfbde8e27abd1dc84cf893fe54d --- /dev/null +++ b/i18n_string/i18n_string.api.php @@ -0,0 +1,88 @@ + t('Menu'), + 'description' => t('Translatable menu items: title and description.'), + 'format' => FALSE, // This group doesn't have strings with format + 'list' => TRUE, // This group can list all strings + ); + return $groups; +} + +/** + * Provide list of translatable strings for text group. + + * A module can provide a list of translatable strings using hook_i18n_string_list() or + * it can provide a list of objects using hook_i18n_string_objects() from which the string + * list will be produced automatically. + * + * @param $group + * Text group name. + */ +function hook_i18n_string_list($group) { + if ($group == 'mygroup') { + $strings['mygroup']['type1']['key1']['name'] = 'Name of object type1/key1'; + $strings['mygroup']['type1']['key1']['description'] = 'Description of object type1/key1'; + return $strings; + } +} + +/** + * Alter string list for objects of text group. + * + * @see i18n_menu_i18n_string_list_menu_alter() + * + * @param $strings + * Associative array with current string list indexed by textgroup, type, id, name + * @param $type + * Object type ad defined on i18n_object_info() + * @param $object + * Object defined on i18n_object_info() + */ +function hook_i18n_string_list_TEXTGROUP_alter(&$strings, $type = NULL, $object = NULL) { + if ($type == 'menu_link' && $object) { + if (isset($object['options']['attributes']['title'])) { + $strings['menu']['item'][$object['mlid']]['title']['string'] = $object['link_title']; + $strings['menu']['item'][$object['mlid']]['description']['string'] = $object['options']['attributes']['title']; + } + } +} + +/** + * List objects to collect translatable strings. + * + * A module can provide a list of translatable strings using hook_i18n_string_list() or + * it can provide a list of objects using hook_i18n_string_objects() from which the string + * list will be produced automatically. + * + * @see i18n_object_info() + * @see i18n_menu_i18n_string_objects() + * @see i18n_string_i18n_string_list() + * + * @param $type string + * Object type + * @return $objects array + * Associative array of objects indexed by object id + */ +function hook_i18n_string_objects($type) { + if ($type == 'menu_link') { + // All menu items that have no language and are customized. + return db_select('menu_links', 'm') + ->fields('m') + ->condition('language', LANGUAGE_NONE) + ->condition('customized', 1) + ->execute() + ->fetchAllAssoc('mlid', PDO::FETCH_ASSOC); + } +} \ No newline at end of file