Twitter Tools
[resolved] Enable German Umlauts in sidebar widgets (solution) (3 posts)

  1. joachimschlosser
    Posted 4 years ago #

    I have patched the plugin to make Umlauts work in the sidebar widget. Please note that you must save the file using UTF-8 coding to make it work, since the Umlauts are included in the file now.

    --- twitter-tools.php.orig	2010-08-16 05:22:42.000000000 +0200
    +++ twitter-tools.php	2011-03-29 22:01:21.756399300 +0200
    @@ -826,7 +826,7 @@
     function aktt_tweet_display($tweet, $time = 'relative') {
     	global $aktt;
    -	$output = aktt_make_clickable(wp_specialchars($tweet->tw_text));
    +	$output = aktt_make_clickable(esc_html__($tweet->tw_text));
     	if (!empty($tweet->tw_reply_username)) {
     		$output .= 	' <a href="'.aktt_status_url($tweet->tw_reply_username, $tweet->tw_reply_tweet).'" class="aktt_tweet_reply">'.sprintf(__('in reply to %s', 'twitter-tools'), $tweet->tw_reply_username).'</a>';
    @@ -846,7 +846,7 @@
     function aktt_make_clickable($tweet) {
     	$tweet .= ' ';
     	$tweet = preg_replace_callback(
    -			'/(^|\s)@([a-zA-Z0-9_]{1,})(\W)/'
    +			'/(^|\s)@([a-zA-Z0-9_├ñ├ä├Â├û├╝├£├ƒ]{1,})(\W)/'
     			, create_function(
     				, 'return aktt_profile_link($matches[2], \' @\', $matches[3]);'
    @@ -854,7 +854,7 @@
     			, $tweet
     	$tweet = preg_replace_callback(
    -		'/(^|\s)#([a-zA-Z0-9_]{1,})(\W)/'
    +		'/(^|\s)#([a-zA-Z0-9_├ñ├ä├Â├û├╝├£├ƒ]{1,})(\W)/'
     		, create_function(
     			, 'return aktt_hashtag_link($matches[2], \' #\', \'\');'
    @@ -867,7 +867,7 @@
     	else {
     		return make_clickable($tweet);
    -	}
    +		}
     function aktt_tweet_form($type = 'input', $extra = '') {


  2. feedmeastraycat
    Posted 3 years ago #

    Ive been looking into this a bit as well. Didn't like the solution here which just adds a bunch of characters. It might only works for some and not for all characters. Maybe it is perfect for German special characters but not Swedish or Norwegian for example... So I did like this instead.

    In the preg_replace_callback() for hash tags I changed the regexp to this:
    It uses unicode to match any word character. So it should match a-z0-9 and for example åäö in Swedish and it also matches "_" which Twitter also approves in hash tags. Then it looks for any non word character after it. So it doesn't match #tag-tag but #tag_tag or #tåg_tåg for example.

    But I also noticed it has problems with two tags after each other. So if the tweet is "Wow, WordPress is really great! #wordpress #epic #stuff" it will make a link out of #wordpress and #stuff. But not #epic.

    I found a ugly solution for this is to change all white spaces to double white spaces before doing the match. And then changing them back. :)

    So the full code now looks like this (not the whole function, but the preg_replace_callback() part for hashtags):

    $tweet = preg_replace("/(\s)/", "  ", $tweet);
    	$tweet = preg_replace_callback(
    		, create_function(
    			, 'return aktt_hashtag_link($matches[2], \' #\', \'\');'
    		, $tweet
    	$tweet = preg_replace("/(\s\s)/", " ", $tweet);

    The only problem now with this is if you have a tag with a dash in it. Like #lol-cat for example. Twitter creates a tag out of #lol and leaves "-cat" as text. On their page. This function will do #lol as a tag, remove "-" and leave cat intact. So it looks like #lol cat instead of #lol-cat ... But it's better then nothing. :)

    It would be great though if this could be patched into the official plugin. Any solution that fixes åäö (and so on) in hash tags. So it finds the same tags as Twitter does.

  3. feedmeastraycat
    Posted 3 years ago #

    I solved it. :) Read more here: http://fmasc.net/31g

    I've e-mailed the plugin creator about it. Hopefully it can be added to the next version.
    In short, its two fixes.

    1) New regexp

    2) Removed a trailing whitespace before $suffix in aktt_hashtag_link()

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Twitter Tools
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic