Categories > TinyButStrong general >

Howto short text in MuitiLanguage string?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: jiichen
Date: 2005-09-05
Time: 06:09

Howto short text in MuitiLanguage string?

I cannot short the message in chinese pc!

[blk_company.company_name;noerr;max=9]

It will show '台灣遊戲?...'
but source is '台灣遊戲網路'
I wash it is '台灣遊戲網...'

The word as two bytes, and the lastest byte is hidden.
By: Skrol29
Date: 2005-09-05
Time: 13:13

Re: Howto short text in MuitiLanguage string?

If the word has two bits, that's probably because data is stored unicode.
So if you put max=10 then it should keep 5 unicode chars. And words won't be cut.
By: jiichen
Date: 2005-09-06
Time: 16:07

Re: Howto short text in MuitiLanguage string?

but the string is dynamic.

It is mixed by chinese and english or numeric.
By: Skrol29
Date: 2005-09-07
Time: 01:11

Re: Howto short text in MuitiLanguage string?

The string is dynamic !?

If you data contains not yet converted characters, then TBS first cut them and then convert them to Html for the display. That is the default behavior for parameter "max".
If you data has not to be converted to Html (for example because you've set "htmlconv=no") then TBS will assume that the string may contains Html special chars yet, and then it will cut the string after having examinated the "&" and ";" chars in order to not cut such Html special chars.

If your data is not one of those two kinds, then instead of using parameter "max", you have to code you own formating (cutting) function and apply it to the field using  parameter "onformat".
By: jiichen
Date: 2005-09-07
Time: 08:32

Re: Howto short text in MuitiLanguage string?

Yes, I am use onformat now.

but every php must write a function, because it's length is not the same. It is hard.....

ex:
function tbs_short_text_news_title_001($FieldName,&$CurrVal) {
    $CurrVal=func_short_text($CurrVal, 45);
}
function tbs_short_text_news_title_002($FieldName,&$CurrVal) {
    $CurrVal=func_short_text($CurrVal, 39);
}
By: Skrol29
Date: 2005-09-07
Time: 10:33

Re: Howto short text in MuitiLanguage string?

Since TBS version 2.02, custom "onformat" functions accept an optional argument $CurrPrm. This give you an access to the array of parameters of the field.

You can use it like this:
function tbs_short_text_news_title($FieldName,&$CurrVal,&$CurrPrm) {
  if (isset($CurrPrm['xlen'])) {
    $xlen = inval($CurrPrm['xlen']);
  } else {
    $xlen = 10;
  }
  $CurrVal=func_short_text($CurrVal, $xlen);
}

"xlen" is a personnal parameter, example:
  [blk_company.company_name;noerr;xlen=45]
By: jiichen
Date: 2005-09-07
Time: 15:34

Re: Howto short text in MuitiLanguage string?

Oh!  that is right. It is I need.

thanks you very much!