liblouis-rb

Ruby bindings for Liblouis, library allowing translating text to and from braille. Includes Liblouis and its translation tables.

Installation

gem install liblouis-rb

Or add to your Gemfile:

gem 'liblouis-rb'

From a Git checkout:

git submodule update --init --recursive
rake gem
gem install ./pkg/liblouis-rb-0.1.1.gem

The gem includes Liblouis and its tables.

Examples

Translate text to braille

require "liblouis"

table = LibLouis::BrailleTable.new("en-gb-g1.utb")
braille = table.translate("hello")
puts braille.to_s

Translate braille to text

require "liblouis"

table = LibLouis::BrailleTable.new("en-gb-comp8.ctb")
puts table.back_translate("\u2813\u2811\u2807\u2807\u2815") # hello

Inspect a braille cell

require "liblouis"

cell = LibLouis::BrailleCharacter.new([1, 4, 8])
p cell.dots    # [1, 4, 8]
p cell.dot1?   # true
p cell.mask    # 137

Find translation tables

require "liblouis"

puts LibLouis.find_tables("language:en grade:1")

Use computer braille at the cursor

Translate the word at the cursor as computer braille. Positions are zero-based.

require "liblouis"

table = LibLouis::BrailleTable.new("en-GB-g2.ctb")
braille = table.translate(
  "the cat", mode: :computer_braille_at_cursor, cursor_position: 1
)
puts braille.to_s
p braille.cursor_position  # Cursor index in braille.
p braille.output_positions # Braille index for each input character.

Translate emphasised text

Emphasis classes depend on the table. Supply one typeform entry per character.

require "liblouis"

table = LibLouis::BrailleTable.new("en-GB-g2.ctb")
p table.emphasis_classes # [:italic, :underline, :bold]
text = "Ruby"
forms = Array.new(text.length, i[italic bold])
puts table.translate(text, typeform: forms).to_s

Licence

GNU Lesser General Public License, version 2.1 or later