Do you know of a good solution for dealing with text entries of variable lengths lists with a fixed width?
I have an unordered list with a set number of items. Each item contains a title. The title can be variable length, not only in number of characters, but also number of characterset (korean, japanese, roman, etc.).
One option seems to be cutting the text length down with PHP and adding "..." at the end, but since character widths can be variable, the exact cutoff can also be variable. Another would be to make items fixed with and hide overflow, but this seems inelegant (because characters might get cutoff right in their centers...).
Do you know of a good tutorial or solution for something like this?
Using CSS: text-overflow: ellipsis. Doesn't work in all browsers though. More information: http://www.quirksmode.org/css/textoverflow.html.
Related
I'm working with PDFLib (9.0.4) with PHP 5.5 to create a very large table with a lot of very small cells.
I'm aware that PDFLib use a special algorithm to fit the table into a specified space. I would like to know how to prevent some cells to shrink.
My current problem is that some time to time, certain cells are not shrinked the same way as others while those cells are empty.
I tried to play with the column witdh, margins, ... nothing really worked.
I tried to play with horshrinking and vertshrinking options when I call the PDF_fit_table function. But those options are too general.
I'm looking for a way to prevent only certain cells to shrink.
Thank you for your time.
EDIT
This is not a problem of shrinking cell but stretching instead.
I've got the answer to my problem : you just have to specify vershrinklimit and horshrinklimit option into the PDF_fit_table function.
But I've post the wrong question. My problem is not a shrinking cell but un stretching one. My cell is empty and fit_table stretched it while it's not wanted.
I've found the solution to my problem.
by default, in case the parameter was not provided, I was pre-pending a colwidth for every cells ... even for colspaned cells.
So, if one of my table chunks were ending by colspaned cell with a colwidth specified, the colwidth were applied to every other cells above.
The solution was to test if the cell options string was containing the colspan parameter. If so, no colwidth parameter is prepend.
I'm starting to use poedit for PHP text translations. Now I'm confused what to do with long multiline texts, like a page with Terms and Conditions. I'm having a discussion about this with a colleague.
I see two options:
Per paragraph or line one poedit field
This keeps the text inside a echo _('lorem ipsum'); small.
Disadvantage: if you change the text and need to add lines, you would have to add lines in the code, which is not desirable. You probably wouldn't do this, and then use one identifier to add two paragraphs, which goes against this method.
All text in one poedit field
Disadvantage: This would result in a very long identifier. I'm not going to give an example - you know how long they can be. The identifier text could span more than a screen.
Identifier to describe what should be displayed
The identifier could be replaced by a short line describing what it is about, like this:
<?php _('Terms and conditions: complete text'); ?>
Disadvantage: if a new language is added, and this text is not translated, the identifier will show.
Advantage: if paragraphs are added or removed, you can do so without having to change the source code.
Advantage: sometimes one English word is translated into different meanings depending on context, like "bold":
Font weight: bold - translates to "fett" in German.
How are you feeling today: bold - translates to "mutig" in German.
NB: you should read this as a form field where you can select what font-weight you want: (1) normal, (2) bold, or (3) italic, not as one text "Font weight: bold".
In these two cases an identifier like "bold-font" and "bold-feeling" would provide context.
Questions
How do you handle long texts in poedit? What is best practise?
Gettext is not suitable for long free form texts at all. The correct answer is a third one you didn’t mention: just don’t. Use e.g. localized text files instead.
To comment on some of your ideas:
Per paragraph or line one poedit field
Chopping the text into individual lines is an extremely bad idea. It would loose important context.
Identifier to describe what should be displayed
...
Advantage: if paragraphs are added or removed, you can do so without having to change the source code.
Very bad idea as well (generally, not just for long text). If the source (English) text changes, there’s nothing to alert you to do the need to update the translation. Inevitably, the translations will get out of sync, undetectably. This is not an “advantage” at all.
There’s a reason why gettext uses source text as the key: it works.
Advantage: sometimes one English word is translated into different meanings depending on context, like "bold":
I don’t see how are different meanings of same words/short texts related to the question at all. That’s handled naturally by gettext with message contexts (msgctxt) as discussed in the manual.
We are having difficulties displaying LONG NAMES on our website and would need help urgently.
We actually need to place IMAGE NAMES under IMAGES that have a FIXED WIDTH. Because image names are sometimes longer than the image width, we don’t want to display the complete name on too many lines because it would not look nice.
We then either want to display the names on 1 (or 2) line(s) maximum (depending on the page).
When the NAME IS LONGER than 1 (or 2) line(s), we would like to CUT THE IMAGE NAME and place 3 DOTS (…) at the end of the line so that the third dot would reach the end of the image.
We have tried to find a solution, but defining a string length is not one of them, because if we define a limit of for example 10 characters then put the 3 dots afterwards, it will not solve the problem since all characters don’t have the same length:
Example 1: AAAAAAAAAA
Example 2: IIIIIIIIII
This solution is inappropriate since the 3 dots will never be placed at the same place (at the end of the image)
Does anyone have a solution?
We would really appreciate your help.
Thanks a lot.
PHP, being a server-side language, has no way to know how the browser will render the text. A CSS solution is way more feasible:
div.picture-name{
width: 100px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
See it in action.
P.S. Can't guarantee IE support for text-overflow: ellipsis.
I know this is not the best option but you can place each character within a div or span then you will probably have a control over length of the sting.
This is a very simple question, but embarrassingly enough I am not sure how to implement this :\
I have div elements with text boxes inside them for users to write comments,replies etc... Very standard concept. The div that contains the text is a certain width. If someone where to write something with out using any spaces, instead of breaking down a line when it hits the right edge of the div, it just keeps going and breaks the element.
I am just wanting to know how to make it line break when it hits the edge spaces provided by user or not.
thanks in advance
There is a word-wrap CSS property that will force long words to wrap:
word-wrap: break-word;
You might also want to look into overflow.
Hmmmm...This is an interesting problem. I'm thinking what I would do would be to implement a JavaScript function that would "read" the length of lines and if a single block of writing is longer than the max length, I would grab a substring of (max length - 1), append a dash (-) to the end of it, add in a line break, and proceed from there.
I'm trying to find a way to wrap a long headline after a specific number of words, based on the total character count of the headline. My purpose is to make the bottom line of the wrapped text longer than the top line to increase readability.
I'd like to use Smarty to find the character count of the headline, then decide how long to make the first line based on the default font size and the width of the containing element. But I'm not a coder and don't know the best way to make arrays, foreach loops, iteration counts, and other stuff that's probably necessary to pull this off.
I'm basically trying to:
Find the total character count of the headline using {$item.name|count_characters:true}
If the total character count is between 60 and 100 characters, add a br tag at the end of the first word that ends past 30 characters.
I believe that you can do this with register_modifier(). Basically, you write a php function to insert the tag, then register it as a modifier. After you've done that, use it in smarty like you would other modifiers, ie:
{$variable|break_title}
In general, it's better not to do complex formatting within smarty templates. Things are cleanest the closer your templates are to vanilla html.
Possible implementation:
function break_title($title) {
return wordwrap($title, 59, '<br />\n');
}
/* later */
$smarty->register_modifier('break_title', 'break_title');
If you want to take font size into account, you can set a global configuration variable indicating the number of characters to break after.
EDIT:
As the commentor mentions, if there is an existing php function that does what you want, you can access it without registering the function:
{$variable|wordwrap:59:"<br />\n"}