Skip to content

Instantly share code, notes, and snippets.

@wilkie
Created April 22, 2014 00:41
Show Gist options
  • Save wilkie/11161543 to your computer and use it in GitHub Desktop.
Save wilkie/11161543 to your computer and use it in GitHub Desktop.
A dynamic natural language translation layer for ruby... an example:
require :spaES # <-- Select the stdlib locale
require 'stdlib' # <-- import the stdlib
# The above will be automatically done in practice, but it is just listed here
# as an illustration. This is because after this point, you need to use the term
# importar to import.
# As in: importar 'some-library'
# Only THIS file uses the function name table in español. Other files and existing libraries
# assuming the original or a different natural language are functionally unaffected. It is
# important to still have the means of collaboration regardless of primary natural language!
# File.open("todo.txt", "r+") <-- Error. Constant 'File' not found.
Archivo.abrir("todo.txt", "r+")
# puts "hola".start_with?("h") <-- Error.
ponerSarta "hola".comienzaCon?("h")
# puts "hola".start_with?("e")
ponerSarta "hola".comienzaCon?("e")
# s = String.new("hola") <-- Error. Constant 'String' not found.
s = Sarta.nuevo("hola")
ponerSarta s.comienzaCon?('ho')
# s.upcase!
s.mayúsculas!
# s.prepend '¡'
s = s.anexarAntes '¡'
s = s + "!"
ponerSarta s
# output:
#
# true
# false
# true
# ¡HOLA!
# There are also files for File, Integer, Fixnum, etc
# All of the __define, etc names can be generated randomly, so they don't have to be
# in English. This file would likely be machine generated via human-curated input elsewhere.
# Translations in español can be a little long as their original names rely on historical
# presence, such as 'printf' or 'puts' being already common abbreviations for 50 years. It is very
# practical that functions in español would have their own abbreviations, but I have longer
# names for ease of reading and more immediately comprehension by a less-familiar reader.
class String
include Aliaser
__define :spaES
__rename_class :Sarta
__rename_self :new, :nuevo
__rename :ascii_only?, :sóloASCII?
__rename :b, :ASCII
__rename :bytes, :bytes
__rename :bytesize, :longitudEnBytes
__rename :byteslice, :subsartaEnBytes
__rename :capitalize, :capitalizar
__rename :capitalize!, :capitalizar!
__rename :casecmp, :compararSinCaso
__rename :center, :centrar
__rename :chars, :letres
__rename :chomp, :eliminarNuevaLínea
__rename :chomp!, :eliminarNuevaLínea!
__rename :chop, :eliminarÚltimaLetra
__rename :chop!, :eliminarÚltimaLetra!
__rename :chr, :sacarPrimeroLetre
__rename :clear, :despejar
__rename :codepoints, :puntosDeCódigo
__rename :concat, :concatenar
__rename :count, :contarLetrasComunes
__rename :crypt, :aplicarCripto
__rename :delete, :eliminarLetrasComunes
__rename :delete!, :eliminarLetrasComunes!
__rename :downcase, :minúsculas
__rename :downcase!, :minúsculas!
__rename :dump, :escapar
__rename :each_byte, :cadaByte
__rename :each_char, :cadaLetre
__rename :each_codepoint, :cadaPuntoDeCódigo
__rename :each_line, :cadaLínea
__rename :empty?, :vacío?
__rename :encode, :codificar
__rename :encode!, :codificar!
__rename :encoding, :codificación
__rename :end_with?, :terminaCon?
__rename :eql?, :igual?
__rename :force_encoding, :forzarLaCodificación
__rename :getbyte, :sacarByte
__rename :gsub, :sustituirConPatrón
__rename :gsub!, :sustituirConPatrón!
__rename :hash, :hash
__rename :hex, :desdeHexadecimal
__rename :include?, :incluido?
__rename :index, :letraPosición
__rename :initialize_copy, :inicializarCopia
__rename :insert, :insertar
__rename :inspect, :inspeccionar
__rename :intern, :internar
__rename :length, :longitud
__rename :lines, :líneas
__rename :ljust, :justificaciónIzquierda
__rename :lstrip, :eliminarEspaciosIzquierda
__rename :lstrip!, :eliminarEspaciosIzquierda!
__rename :match, :igualar
__rename :next, :próximo
__rename :next!, :próximo!
__rename :oct, :desdeOctal
__rename :ord, :letraAEntero
__rename :partition, :dividir
__rename :prepend, :anexarAntes
__rename :replace, :sustituir
__rename :reverse, :trastrocar
__rename :reverse!, :trastrocar!
__rename :rindex, :letraPosiciónDesdeExtremo
__rename :rjust, :justificaciónDerecha
__rename :rpartition, :dividirDesdeExtremo
__rename :rstrip, :eliminarEspaciosDerecha
__rename :rstrip!, :eliminarEspaciosDerecha!
__rename :scan, :buscar
__rename :scrub, :sustituirLetrasNoVálidos
__rename :scrub!, :sustituirLetrasNoVálidos!
__rename :setbyte, :establecerByte
__rename :size, :magnitud
__rename :slice, :subsarta
__rename :slice!, :subsarta!
__rename :split, :divirse
__rename :squeeze, :eliminarRepetición
__rename :squeeze!, :eliminarRepetición!
__rename :start_with?, :comienzaCon?
__rename :strip, :eliminarEspacios
__rename :strip!, :eliminarEspacios!
__rename :sub, :sustituir
__rename :sub!, :sustituir!
__rename :succ, :sucesor
__rename :succ!, :sucesor!
__rename :sum, :sumar
__rename :swapcase, :intercambiarCaso
__rename :swapcase!, :intercambiarCaso!
__rename :to_c, :aLetra
__rename :to_f, :aPuntoFlotante
__rename :to_i, :aEntero
__rename :to_r, :aRacional
__rename :to_s, :aSarta
__rename :to_str, :aSartaEstricto
__rename :to_sym, :aSímbolo
__rename :tr, :sustituirLetras
__rename :tr!, :sustituirLetras!
__rename :tr_s, :sustituirTodasLetras
__rename :tr_s!, :sustituirTodasLetras!
__rename :unpack, :descodificar
__rename :upcase, :mayúsculas
__rename :upcase!, :mayúsculas!
__rename :upto, :hasta
__rename :valid_encoding?, :codificaciónVálida?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment