[BlueOnyx:23894] Re: tooltip hover blink bug at php options

Tomohiro Hosaka bokutin at bokut.in
Sat May 23 21:56:29 -05 2020


Hi Michael,

Thanks for the details.

I made a patch.

--- 
/usr/sausalito/ui/chorizo/ci/application/libraries/I18n.php-00	2019-10-11 
09:13:34.000000000 +0900
+++ 
/usr/sausalito/ui/chorizo/ci/application/libraries/I18n.php	2020-05-24 
11:35:25.874369119 +0900
@@ -204,7 +204,8 @@
      if ($ini_langs['locale'] == "ja_JP") {
        // We can't word wrap Japanese without creating some undesired 
results.
        // Se we simply don't word wrap it and just replace hard returns:
-      $transwebbed = str_replace("\n","<br>", $out_txt_clean);
+      $folded      = ja_wordwrap($out_txt_clean, 75);
+      $transwebbed = str_replace("\n","<br>", $folded);
        $transwebbed = str_replace('"', "'", $transwebbed);
        return $transwebbed;
      }
@@ -559,4 +560,4 @@
  nuclear facility.

  */


--- 
/usr/sausalito/ui/chorizo/ci/system/helpers/text_helper.php-00	2019-10-11 
09:13:35.000000000 +0900
+++ 
/usr/sausalito/ui/chorizo/ci/system/helpers/text_helper.php	2020-05-24 
11:45:28.371969968 +0900
@@ -478,6 +478,29 @@

  		return $output;
  	}
+
+	function ja_wordwrap($string, $charlim = '76') { // $charlim is 
treated as visualwidth.
+		$folded = "";
+		$room   = $charlim;
+		$chars  = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
+		foreach ($chars as $char) {
+			$vw = strlen( mb_convert_encoding($char, 'SJIS', 'UTF-8') );
+			if ( $char == "\n" ) {
+				$folded .= $char;
+				$room	 = $charlim;
+				continue;
+			}
+			if ( $room >= $vw ) {
+				$folded .= $char;
+				$room   -= $vw;
+			}
+			else {
+				$folded .= "\n".$char;
+				$room	 = $charlim-$vw;
+			}
+		}
+		return $folded;
+	}
  }

  // 
------------------------------------------------------------------------


It works fine in my environment.
http://bokut.in/blueonyx_tiptip_tip_left_blink_ja_fold.gif

For Perl there is a perfect implementation at 
https://metacpan.org/pod/Text::ANSI::Fold .
This is the author known by jcode.pl.

I looked for something similar for PHP, but I couldn't find anything 
that could be adopted as-is.

I also considered the multibyte version of 
https://www.php.net/manual/en/function.wordwrap.php in User Contributed 
Notes.

I chose to create something simple as a result.

If you want to consider importing the code, of course you can modify it 
to make it easier to handle.

Thanks,


On 2020-05-24 03:31, Michael Stauber wrote:
> Hi Tomohiro Hosaka,
> 
>> I think the tooltip text for PHP options is important to users, but
>> unfortunately I can't read it.
>> https://bokut.in/blueonyx_tiptip_tip_left_blink.gif
>> 
>> Is it possible to fix it?
> 
> Yes and this is actually something where I really would appreciate your
> help and expertise to get it fixed.
> 
> Here is the problem:
> 
> For these mouse-over help texts in all languages *but* Japanese we use
> word-wrap.
> 
> The function that does this for us is called getWrapped() and it can be
> found here in the base-alpine code:
> 
> https://devel.blueonyx.it/trac/browser/BlueOnyx/5209R/platform/alpine.mod/ci/application/libraries/I18n.php#L182
> 
> You feed it a "tag" (like "php_security"), a "domain" (which module has
> the language files (like "base-vsite") an (optionally) an array of
> replacement strings to populate certain placeholders in the locale
> files. It then *should* return a word wrapped text string that contains
> the desired text in the language which the person using the GUI has
> configured.
> 
> The critical part being this here:
> 
> 204	    if ($ini_langs['locale'] == "ja_JP") {
> 205	      // We can't word wrap Japanese without creating some
>               // undesired results.
> 206	      // So we simply don't word wrap it and just replace
>               // hard returns:
> 207	      $transwebbed = str_replace("\n","<br>", $out_txt_clean);
> 208	      $transwebbed = str_replace('"', "'", $transwebbed);
> 209	      return $transwebbed;
> 210	    }
> 211	    else {
> 212	      $out_txt_clean = str_replace('"', "'", $out_txt_clean);
> 213	      $translated = @htmlentities(html_entity_decode(
>                  htmlspecialchars_decode($out_txt_clean, ENT_QUOTES),
>                  ENT_QUOTES), ENT_QUOTES, $ini_langs['localecharset']);
> 214	      $transwebbed = 204	    if ($ini_langs['locale'] == "ja_JP") {
> 205	      // We can't word wrap Japanese without creating some 
> undesired
> results.
> 206	      // Se we simply don't word wrap it and just replace hard 
> returns:
> 207	      $transwebbed = str_replace("\n","<br>", $out_txt_clean);
> 208	      $transwebbed = str_replace('"', "'", $transwebbed);
> 209	      return $transwebbed;
> 210	    }
> 211	    else {
> 212	      $out_txt_clean = str_replace('"', "'", $out_txt_clean);
> 213	      $translated =
> @htmlentities(html_entity_decode(htmlspecialchars_decode($out_txt_clean,
> ENT_QUOTES), ENT_QUOTES), ENT_QUOTES, $ini_langs['localecharset']);
> 214	      $transwebbed = word_wrap($translated, 75);
> 215	      $transwrapped = str_replace("\n","<br>", $transwebbed);
> 216	      return $transwrapped;
> 217	    }($translated, 75);
> 215	      $transwrapped = str_replace("\n","<br>", $transwebbed);
> 216	      return $transwrapped;
> 217	    }
> 
> As you can see: Anything but Japanese is word_wrapped() at around 75
> characters. That turns a long single line help-text into something that
> has multiple lines if needed. That increases readability and makes sure
> the text is not wider than the screen either.
> 
> The blinking mouse-over text happens when a line is so long that the
> help text doesn't fit onto the screen.
> 
> However: I have no idea how I can do a sensible word-wrap of Japanese
> without hurting the readability or making it an eye sore.
> 
> Do you by chance have any recommendation how the above function could 
> be
> improved to allow us to do word-wrap for Japanese in a way that's
> actually useful?
> 
> Thank you!



More information about the Blueonyx mailing list