summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--i18ncck/i18ncck.info8
-rw-r--r--i18ncck/i18ncck.install17
-rw-r--r--i18ncck/i18ncck.module103
3 files changed, 128 insertions, 0 deletions
diff --git a/i18ncck/i18ncck.info b/i18ncck/i18ncck.info
new file mode 100644
index 0000000..8f30c10
--- /dev/null
+++ b/i18ncck/i18ncck.info
@@ -0,0 +1,8 @@
+; $Id$
+name = CCK translation
+description = Supports translatable custom CCK fields and fieldgroups.
+dependencies[] = i18n
+dependencies[] = content
+dependencies[] = i18nstrings
+package = Multilanguage
+core = 6.x
diff --git a/i18ncck/i18ncck.install b/i18ncck/i18ncck.install
new file mode 100644
index 0000000..9858120
--- /dev/null
+++ b/i18ncck/i18ncck.install
@@ -0,0 +1,17 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Installation file for i18ncck module.
+ */
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Create all strings from CCK for translation.
+ */
+function i18ncck_enable() {
+ drupal_load('module', 'i18nstrings');
+ i18ncck_locale_refresh();
+} \ No newline at end of file
diff --git a/i18ncck/i18ncck.module b/i18ncck/i18ncck.module
new file mode 100644
index 0000000..8d0fe9e
--- /dev/null
+++ b/i18ncck/i18ncck.module
@@ -0,0 +1,103 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Internationalization (i18n) submodule: CCK.
+ */
+
+/**
+ * Implementation of hook_locale().
+ */
+function i18ncck_locale($op = 'groups', $group = NULL) {
+ switch ($op) {
+ case 'groups':
+ return array('cck' => t('CCK'));
+
+ case 'refresh':
+ if ($group == 'cck') {
+ return i18ncck_locale_refresh();
+ }
+ }
+}
+
+/**
+ * Makes safe keys for using in tt().
+ */
+function i18ncck_get_safe_value($value) {
+ return html_entity_decode(strip_tags($value), ENT_QUOTES);
+}
+
+/**
+ * Refresh locale strings.
+ */
+function i18ncck_locale_refresh() {
+ foreach (content_types() as $content_type => $type) {
+ // Localization of CCK fields.
+ if (isset($type['fields'])) {
+ foreach ($type['fields'] as $field_name => $field) {
+ // Localize field title and description per content type.
+ tt('cck:field:'. $content_type .'-'. $field_name .':widget_label', $field['widget']['label'], NULL, TRUE);
+ if (!empty($field['widget']['description'])) {
+ tt('cck:field:'. $content_type .'-'. $field_name .':widget_description', $field['widget']['description'], NULL, TRUE);
+ }
+
+ // Localize allowed values per field.
+ if (empty($field['allowed_values_php']) && !empty($field['allowed_values'])) {
+ $function = $field['module'] .'_allowed_values';
+ $allowed_values = function_exists($function) ? $function($field) : (array) content_allowed_values($field);
+ if (!empty($allowed_values)) {
+ foreach ($allowed_values as $key => $value) {
+ tt('cck:field:'. $field_name .':option_'. i18ncck_get_safe_value($key), $value, NULL, TRUE);
+ }
+ }
+ }
+ }
+ }
+
+ // Localization of CCK fieldgroups.
+ if (module_exists('fieldgroup')) {
+ foreach (fieldgroup_groups($content_type) as $group_name => $group) {
+ tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':label', $group['label'], NULL, TRUE);
+ if (!empty($group['settings']['form']['description'])) {
+ tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':form_description', $group['settings']['form']['description'], NULL, TRUE);
+ }
+ if (!empty($group['settings']['display']['description'])) {
+ tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':display_description', $group['settings']['display']['description'], NULL, TRUE);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Translate widget's labels and descriptions.
+ */
+function i18ncck_content_field_strings_alter(&$field_strings, $content_type, $field_name) {
+ $field_strings['widget_label'] = tt('cck:field:'. $content_type .'-'. $field_name .':widget_label', $field_strings['widget_label']);
+ if (!empty($field_strings['widget_description'])) {
+ $field_strings['widget_description'] = tt('cck:field:'. $content_type .'-'. $field_name .':widget_description', $field_strings['widget_description']);
+ }
+}
+
+/**
+ * Translate allowed values lists.
+ */
+function i18ncck_content_allowed_values_alter(&$allowed_values, $field) {
+ foreach ($allowed_values as $key => $value) {
+ $allowed_values[$key] = tt('cck:field:'. $field['field_name'] .':option_'. i18ncck_get_safe_value($key), $value);
+ }
+}
+
+/**
+ * Translate fieldgroup labels and descriptions.
+ */
+function i18ncck_content_fieldgroup_strings_alter(&$group_strings, $content_type, $group_name) {
+ $group_strings['label'] = tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':label', $group_strings['label']);
+ if (!empty($group_strings['form_description'])) {
+ $group_strings['form_description'] = tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':form_description', $group_strings['form_description']);
+ }
+ if (!empty($group_strings['display_description'])) {
+ $group_strings['display_description'] = tt('cck:fieldgroup:'. $content_type .'-'. $group_name .':display_description', $group_strings['display_description']);
+ }
+}