summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2011-12-24 15:05:40 (GMT)
committer Jose Reyero2011-12-24 15:05:40 (GMT)
commit97e22ec418ab03309a5559351b9d76e1788a92d5 (patch)
tree908eee77445abee7ca7b2c0e9f0680c72c4d7319
parent4054295bd91cba62e2ae1309aacad78ff7de048e (diff)
Some API documentation for i18n modules.
-rw-r--r--i18n.api.php100
-rw-r--r--i18n_menu/i18n_menu.i18n.inc2
-rw-r--r--i18n_string/i18n_string.api.php88
3 files changed, 189 insertions, 1 deletions
diff --git a/i18n.api.php b/i18n.api.php
new file mode 100644
index 0000000..5bd40e9
--- /dev/null
+++ b/i18n.api.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @file
+ * API documentation for Internationalization module
+ *
+ * Most i18n hooks can be placed on each module.i18n.inc file but in this case
+ * such file must be listed in the module.info file.
+ */
+
+
+/**
+ * Provide information about object types handled by i18n system.
+ *
+ * @see i18n_object_info()
+ *
+ * Other features like translation sets (i18n_translation) or string translation (i18n_string)
+ * rely on the information provided by this hook for automating string translation
+ */
+function hook_node_i18n_object_info() {
+ // Information for node type object, see i18n_node_i18n_object_info()
+ $info['node_type'] = array(
+ // Generic object properties, title, etc..
+ 'title' => 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 650ffb0..35516d1 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 0000000..9381b6e
--- /dev/null
+++ b/i18n_string/i18n_string.api.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * @file
+ * API documentation file for String translation module.
+ */
+
+/**
+ * List text groups for string translation.
+ *
+ * This information will be automatically produced later for hook_locale()
+ */
+function hook_i18n_string_info() {
+ $groups['menu'] = array(
+ 'title' => 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