# -*- ruby -*- RCSID = "$Id: albhed.rbx,v 1.6 2011/10/01 15:40:22 stephen Exp $" # # English to Al Bhed translation toy # # Copyright (c) 2005-2011 Stephen Williams, all rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the copyright holder may not be used to endorse or # promote products derived from this software without specific prior # written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ### BEGIN class definition class Translator ### BEGIN class constants # Maps English letters onto Al Bhed letters. (Inverting the map # thus maps Al Bhed letters onto English letters) E2A = { "a" => "y", "b" => "p", "c" => "l", "d" => "t", "e" => "a", "f" => "v", "g" => "k", "h" => "r", "i" => "e", "j" => "z", "k" => "g", "l" => "m", "m" => "s", "n" => "h", "o" => "u", "p" => "b", "q" => "x", "r" => "n", "s" => "c", "t" => "d", "u" => "i", "v" => "j", "w" => "f", "x" => "q", "y" => "o", "z" => "w" } ### END class constants ### BEGIN constructor def initialize @cgi = CGI.new @english = @cgi["english"] @albhed = @cgi["albhed"] end ### END constructor ### BEGIN private methods private # Character-by-character translation of a string. Any character # which is a key in the map gets replaced with the corresponding # value in the map; other characters are left unchanged. If a [ # character is encountered, translation is suspended until the # corresponding ] is encountered def translate_impl(map, source) dest_array = [] passthrough = false source.each_char do |c| passthrough = true if c == "[" passthrough = false if c == "]" unless passthrough if "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(c) c = c.downcase toupper = true else toupper = false end c = map[c] if map.has_key?(c) c = c.upcase if toupper end dest_array << c end dest_array.join end ### END private methods ### BEGIN public methods public def translate if @cgi.has_key?("submitenglish") @albhed = translate_impl(E2A, @english) else if @cgi.has_key?("submitalbhed") @english = translate_impl(E2A.invert, @albhed) end end end def output target = ENV["SCRIPT_URL"] area_rows = 8 @cgi.out("status" => "200 Ajanodrehk ec veha!") do < English <-> Al Bhed Translator

English <-> Al Bhed Translator

This is a simple Al Bhed translation thingy.

Just type either English or Al Bhed text into the appropriate box, then hit the appropriate button to make the translation happen. Any text enclosed in square brackets is left unaltered, so the translation of something like "My name is [Rikku], and I am an [Al Bhed]" comes out looking approximately right.

Do you like this translator? Leave a comment in my journal if you wish.

English


Al Bhed



The translator is written in ECMAScript, compiled with Google Closure Compiler, and runs in your browser. If your browser is not able to run scripts, the translator still works: the buttons submit the form to the server where a Ruby version of the translator does the work.

The code is open source:

Back to the home page

#{RCSID}

END end end ### END public methods end ### END class definition t = Translator.new t.translate t.output