On Thu, May 12, 2016 at 08:49:03AM +0200, Lukas Ocilka wrote:
> # The problem
> 
> We often inform users in dialogs (e.g. warning pop-up, labels) about
> some current situation which contains a generated text based on, for
> instance, lists of disks or network interfaces. In many cases, the
> length of these lists/strings is unknown when we write the text in our
> code. Moreover, translations can change it quite a lot. Depending on the
> selected UI type, we might or might not fit.

For reference, Rails has word_wrap:
http://apidock.com/rails/ActionView/Helpers/TextHelper/word_wrap

word_wrap(text, options = {}) public

Wraps the text into lines no longer than line_width width. This
method breaks on the first whitespace character that does not exceed
line_width (which is 80 by default).

word_wrap('Once upon a time')
# => Once upon a time

word_wrap('Once upon a time, in a kingdom called Far Far Away, a
king fell ill, and finding a successor to the throne turned out to
be more trouble than anyone could have imagined...')
# => Once upon a time, in a kingdom called Far Far Away, a king fell
# ill, and finding\na successor to the throne turned out to be more
# trouble than anyone could have\nimagined...

word_wrap('Once upon a time', line_width: 8)
# => Once\nupon a\ntime

word_wrap('Once upon a time', line_width: 1)
# => Once\nupon\na\ntime
-- 
Martin Vidner, YaST Team
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu

Attachment: signature.asc
Description: Digital signature

Reply via email to