summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2007-10-22 12:17:28 (GMT)
committer Jose Reyero2007-10-22 12:17:28 (GMT)
commitffe1b4698a965a953d9326109863bba34e4a5e70 (patch)
treebfdfce0f48321d4ec4d030837fd35df32581de43
parenta4ad86792f1112ad2b6cc6c932d06e8163048700 (diff)
New language icons module
-rw-r--r--languageicons/languageicons.info6
-rw-r--r--languageicons/languageicons.module160
2 files changed, 166 insertions, 0 deletions
diff --git a/languageicons/languageicons.info b/languageicons/languageicons.info
new file mode 100644
index 0000000..29c648d
--- /dev/null
+++ b/languageicons/languageicons.info
@@ -0,0 +1,6 @@
+name = Language Icons
+description = Adds icons to language links.
+dependencies = locale
+package = Multilanguage - i18n
+version = VERSION
+core = 6.x \ No newline at end of file
diff --git a/languageicons/languageicons.module b/languageicons/languageicons.module
new file mode 100644
index 0000000..c6c373d
--- /dev/null
+++ b/languageicons/languageicons.module
@@ -0,0 +1,160 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Language icons
+ *
+ * Internationalization (i18n) package
+ *
+ * @author Jose A. Reyero, 2007
+ *
+ */
+
+/**
+ * Implementation of hook_theme()
+ */
+function languageicons_theme() {
+ return array(
+ 'languageicons_icon' => array(
+ 'arguments' => array('language' => NULL, 'title' => NULL),
+ ),
+ 'languageicons_place' => array(
+ 'arguments' => array('text' => NULL, 'icon' => NULL, 'separator' => ' '),
+ ),
+ );
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function languageicons_help($section = 'admin/help#languageicons' ) {
+ switch ($section) {
+ case 'admin/help#languageicons' :
+ $output = '<p>'.t('This module manages language icons for multilingual sites:').'</p>';
+ $output .= '<ul>';
+ $output .= '<li>'.t('Automatically adds icons to language links').'</li>';
+ $output .= '<li>'.t('Provides related theme functions').'</li>';
+ $output .= '</ul>';
+ $output .= '<p>'. t('For more information please read the <a href="@i18n">on-line help pages</a>.', array('@i18n' =>'http://drupal.org/node/31631')) .'</p>';
+ return $output;
+ case 'admin/settings/languageicons':
+ $output .= '<p>'.t('To enable multilingual support for specific content types go to !configure_content_types.', array('!configure_content_types' => l(t('configure content types'), 'admin/content/types'), )).'</p>';
+ return $output;
+ }
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function languageicons_menu() {
+ $items['admin/settings/language/configure/options'] = array(
+ 'title' => 'Configure',
+ 'weight' => 10,
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ );
+
+ $items['admin/settings/language/configure/icons'] = array(
+ 'title' => 'Icons',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('languageicons_admin_settings'),
+ 'weight' => 10,
+ 'type' => MENU_LOCAL_TASK,
+ );
+ return $items;
+}
+
+/**
+ * Implementation of hook_alter_translation_link().
+ *
+ * Adds language icons to normal translation links.
+ */
+function languageicons_translation_link_alter(&$links, $path) {
+ foreach ($links as $langcode => $link) {
+ if ($icon = theme('languageicons_icon', $link['language'], $link['title'])) {
+ $links[$langcode]['title'] = theme('languageicons_place', $link['title'], $icon );
+ $links[$langcode]['html'] = TRUE;
+ }
+ }
+}
+
+/**
+ * Implementation of hook_link_alter().
+ *
+ * Adds language icons to node links.
+ */
+function languageicons_link_alter(&$links, $node) {
+ if ($node->tnid && $translations = module_invoke('translation', 'node_get_translations', $node->tnid)) {
+ $languages = language_list();
+ foreach ($translations as $langcode => $translation) {
+ $index = 'node_translation_'.$langcode;
+ if (!empty($links[$index]) && $icon = theme('languageicons_icon', $languages[$langcode], $links[$index]['title'])) {
+ $links[$index]['title'] = theme('languageicons_place', $links[$index]['title'], $icon);
+ $links[$index]['html'] = TRUE;
+ }
+ }
+ }
+}
+
+/**
+ * Form builder function.
+ *
+ */
+function languageicons_admin_settings() {
+
+ $form['languageicons_placement'] = array(
+ '#type' => 'radios',
+ '#title' => t('Icon placement'),
+ '#options' => array('before' => t('Before'), 'after' => t('After'), 'replace' => t('Replace')),
+ '#default_value' => variable_get('languageicons_placement', 'before'),
+ '#description' => t('Where to display the icon, relative to the link title.'),
+ );
+ $form['i18n_icon_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Icons file path'),
+ '#default_value' => variable_get('i18n_icon_path', drupal_get_path('module', 'i18n').'/flags/*.png'),
+ '#size' => 70,
+ '#maxlength' => 180,
+ '#description' => t('Path for language icons, relative to Drupal installation. \'*\' is a placeholder for language code.'),
+ );
+ $form['i18n_icon_size'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Image size'),
+ '#default_value' => variable_get('i18n_icon_size', '16x12'),
+ '#size' => 10,
+ '#maxlength' => 10,
+ '#description' => t('Image size for language icons, in the form "width x height".'),
+ );
+
+ return system_settings_form($form);
+}
+
+/**
+ * Theme language icon
+ *
+ * This function can be overridden for no language icons
+ */
+function theme_languageicons_icon($language, $title = NULL){
+ if ($path = variable_get('i18n_icon_path', drupal_get_path('module', 'i18n').'/flags/*.png')) {
+ $src = base_path().str_replace('*', $language->language, $path);
+ $title = $title ? $title : $language->native;
+ list($width, $height) = explode('x', variable_get('i18n_icon_size', '16x12'));
+ $attribs = array('class' => 'language-icon', 'width' => $width, 'height' => $height, 'alt' => $title);
+ return "<img src=\"$src\" ".drupal_attributes($attribs)." />";
+ }
+}
+
+/**
+ * Theme language icon and text
+ */
+function theme_languageicons_place($text, $icon, $separator = ' ') {
+ switch(variable_get('languageicons_placement', 'before')) {
+ case 'after':
+ return $text . $separator . $icon;
+ case 'replace':
+ return $icon;
+ case 'before':
+ default:
+ return $icon . $separator . $text;
+ }
+} \ No newline at end of file