Skip to content

Instantly share code, notes, and snippets.

@fukata
Created May 22, 2011 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fukata/985276 to your computer and use it in GitHub Desktop.
Save fukata/985276 to your computer and use it in GitHub Desktop.
Google Ajax Translation implements display icon.
diff --git a/ajaxtranslation.php b/ajaxtranslation.php
index 1baf716..70f313e 100644
--- a/ajaxtranslation.php
+++ b/ajaxtranslation.php
@@ -723,6 +723,51 @@ if (!class_exists('GoogleTranslation')) {
return $translate_block;
}
+ /**
+ * get a translate button that can be used anywhere in a post or page as needed by a custom theme. This should be in the WordPress loop.
+ */
+ function get_google_ajax_translate_button_with_icon() {
+ $backtrace = debug_backtrace();
+ if ( !is_feed() && // ignore feeds
+ ( "the_excerpt" != $backtrace[7]["function"] ) && // ignore excerpts
+ ( ( !is_page() && $this -> options['postEnable'] ) || ( is_page() && $this -> options['pageEnable'] ) ) && // apply to posts or pages
+ ! ( in_array( get_the_ID(), $this -> options['excludePages'] ) ) && // exclude certain pages and posts
+ ! ( $this -> options['excludeHome'] && is_home() ) ) { // if option is set exclude home page
+ $translate_block = $this -> generate_translate_block_with_icon('post');
+ return '<div class="translate_block" style="display: none;">' . "\n" .
+ $translate_block .
+ "</div>\n";
+ }
+ }
+
+ /**
+ * echo a translate button for current post. This should be in the WordPress loop.
+ */
+ function google_ajax_translate_button_with_icon() {
+ echo $this -> get_google_ajax_translate_button_with_icon();
+ }
+
+
+ /**
+ * generate translate_block with icon
+ * @return $translate_block string
+ * @param $type string a 'post or 'comment'
+ */
+ function generate_translate_block_with_icon($type = 'post') {
+ if ( 'post' == $type ) {
+ $id = get_the_ID();
+ } elseif ( 'comment' == $type ) {
+ global $comment;
+ $id = $comment -> comment_ID;
+ } else {
+ return NULL;
+ }
+ $browser_lg = $this -> browser_lang;
+ $icon = "<img src='{$this -> pluginRoot}icon-64.png' alt='{$this->translate_message[$browser_lg]}' title='{$this->translate_message[$browser_lg]}' />";
+ $translate_block = '<a class="translate_translate" id="translate_button_' . $type . '-' . $id . '" lang="' . $browser_lg . '" xml:lang="' . $browser_lg . '" href="javascript:show_translate_popup(\'' . $browser_lg . '\', \'' . $type . '\', ' . $id . ');">' . $icon . '</a><img src="' . $this -> pluginRoot . 'transparent.gif" id="translate_loading_' . $type . '-' . $id . '" class="translate_loading" style="display: none;" width="16" height="16" alt="" />' . "\n";
+ return $translate_block;
+ }
+
/**
* echoes the language popup in the wp_footer
*/
diff --git a/icon-64.png b/icon-64.png
new file mode 100644
index 0000000..15995f6
Binary files /dev/null and b/icon-64.png differ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment