who translated it from Ruby from the Rails Inflector class
177209
private static function pluralize($string)
    {$plural = array(
        array('/(quiz)$/i', "$1zes"),
        array('/^(ox)$/i', "$1en"),
        array('/([m|l])ouse$/i', "$1ice"),
        array('/(matr|vert|ind)ix|ex$/i', "$1ices"),
        array('/(x|ch|ss|sh)$/i', "$1es"),
        array('/([^aeiouy]|qu)y$/i', "$1ies"),
        array('/([^aeiouy]|qu)ies$/i', "$1y"),
        array('/(hive)$/i', "$1s"),
        array('/(?:([^f])fe|([lr])f)$/i', "$1$2ves"),
        array('/sis$/i', "ses"),
        array('/([ti])um$/i', "$1a"),
        array('/(buffal|tomat)o$/i', "$1oes"),
        array('/(bu)s$/i', "$1ses"),
        array('/(alias|status)$/i', "$1es"),
        array('/(octop|vir)us$/i', "$1i"),
        array('/(ax|test)is$/i', "$1es"),
        array('/s$/i', "s"),
        array('/$/', "s"),
    );
        $irregular = array(
            array('move', 'moves'),
            array('sex', 'sexes'),
            array('child', 'children'),
            array('man', 'men'),
            array('person', 'people'),
        );
        $uncountable = array(
            'sheep',
            'fish',
            'series',
            'species',
            'money',
            'rice',
            'information',
            'equipment',
        );
        // save some time in the case that singular and plural are the same
        if (in_array(strtolower($string), $uncountable)) {
            return $string;
        }

        // check for irregular singular forms
        foreach ($irregular as $noun) {if (strtolower($string) == $noun[0]) {
            return $noun[1];
        }

        }
        // check for matches using regular expressions
        foreach ($plural as $pattern) {if (preg_match($pattern[0], $string)) {
            return preg_replace($pattern[0], $pattern[1], $string);
        }

        }
        return $string;
    }
243890
def to_hbs
      h = {:model => self.class.name.downcase}
      self.hbs_attributes.each do |attr|
        h[attr] = self.send(attr)

        ans = h[attr].class.ancestors
        if h[attr].class.respond_to?(:hbs_serializable) || ans.include?(Enumerable) || ans.include?(ActiveModel::Validations)
          h[attr] = h[attr].to_hbs
        else
        end
      end
      h
    end
390061
def method_missing(method, *args, &block)
      
      attribute = ActiveSupport::Inflector.camelize(method.to_s, false)
  
      if attribute =~ /=$/
        attribute = attribute.chop
        return super unless self.attributes.include?(attribute)
        self.changed_attributes[attribute] = args[0]
        self.attributes[attribute] = args[0]
      else
        return super unless self.attributes.include?(attribute)
        self.attributes[attribute]
      end 
            
    end
235870
def compile_translations(markup)
      syntax_tree = @parser.parse(markup, root: :translations)
      if(syntax_tree.nil?)
        raise Exception, "Parse error: #{@parser.failure_reason}"
      end
      syntax_tree.value
    end
237442
def localized_scope
      langs = ::I18n.available_locales.join('|')
      scope '(:locale)', locale: Regexp.new(langs) do
        yield
      end
    end
832173
def to_ruby_value
      bare_value = to_value
      case value_type
      when :utf8
        bare_value.to_utf8
      when Array
        value_type[1].wrap bare_value
      when Class
        value_type.wrap bare_value
      else
        bare_value
      end
    end
1042954
def title(controller_name, model_name = controller_name.singularize)
      string = ''
      unless ['page', 'routing_error', 'my_accounts'].include?(controller_name)
        string << t("activerecord.models.#{model_name}") + ' - '
      end
      if controller_name == 'routing_error'
        string << t("page.routing_error") + ' - '
      end
      string << LibraryGroup.system_name + ' - Next-L Enju Leaf'
      string.html_safe
    end
140719
def to_s
      ptr = CF.CFDataGetBytePtr(self)
      if CF::String::HAS_ENCODING
        ptr.read_string(CF.CFDataGetLength(self)).force_encoding(Encoding::ASCII_8BIT)
      else
        ptr.read_string(CF.CFDataGetLength(self))
      end
    end
1182337
def translated_attributes
      @translated_attributes ||= translated_attribute_names.inject({}) do |attrs, name|
        attrs.merge(name.to_s => translation.send(name))
      end
    end
958637
def translate(self, exc):
        
        # Find actual class.
        for key in self.translations.keys():
            if isinstance(exc, key):
                # pylint: disable=unsubscriptable-object
                return self.translations[key](str(exc))

        return None
341915
def t(key, options = {})
      if (val = super) =~ /class.+?translation_missing/
        val = val.to_s.gsub(/<span[^>]*>/, 'i18n: ').gsub('</span>', '').gsub(', ', '.')
      end

      val
    end
304717
def tblNomenclator
      @headers = %w{NomenclatorID GenusNameID SubgenusNameID SpeciesNameID SubspeciesNameID LastUpdate ModifiedBy SuitableForGenus SuitableForSpecies InfrasubspeciesNameID InfrasubKind}
      sql = []   
      i = 1

      # Ugh, move build from here 
      @name_collection.nomenclators.keys.each do |i|
        name =  @name_collection.nomenclators[i]
        genus_id = @genus_names[name[0]]
        genus_id ||= 0
        subgenus_id = @genus_names[name[1]]
        subgenus_id ||= 0
        species_id = @species_names[name[2]]
        species_id ||= 0
        subspecies_id = @species_names[name[3]]
        subspecies_id ||= 0
        variety_id = @species_names[name[4]]
        variety_id ||= 0

        cols = {
          NomenclatorID: i,
          GenusNameID: genus_id, 
          SubgenusNameID: subgenus_id, 
          SpeciesNameID: species_id, 
          SubspeciesNameID: subspecies_id,
          InfrasubspeciesNameID: variety_id,
          InfrasubKind: (variety_id == 0 ? 0 : 2), 
          LastUpdate: @time,  
          ModifiedBy: @authorized_user_id, 
          SuitableForGenus: 0,                      # Set in SF w test
          SuitableForSpecies: 0                     # Set in SF w test
        }
        i += 1
        sql << sql_insert_statement('tblNomenclator', cols) 
      end

      sql.join("\n")
    end
584210
def index
      if defined?(ActiveRecord)
        @ar_error_messages = params[:app] ? RailsExceptionHandler::ActiveRecord::ErrorMessage.where(app_name: params[:app]).order('created_at DESC') : RailsExceptionHandler::ActiveRecord::ErrorMessage.order('created_at DESC')
      end
      if defined?(Mongoid)
        @mg_error_messages = params[:app] ? RailsExceptionHandler::Mongoid::ErrorMessage.where(app_name: params[:app]).order(created_at: 'desc') : RailsExceptionHandler::Mongoid::ErrorMessage.order_by(created_at: 'desc')
      end
      if defined?(WillPaginate)
        @ar_error_messages = @ar_error_messages.paginate(page: params[:page] || 1, per_page: params[:per_page] || 100)
      elsif defined?(Kaminari)
        @ar_error_messages = @ar_error_messages.page(params[:page] || 1).per(params[:per_page] || 100)
      end

      respond_to do |format|
        format.html # index.html.erb
        format.json {
          if @ar_error_messages.present? && @mg_error_messages.present?
            json = {active_record: @ar_error_messages, mongoid: @mg_error_messages}
          elsif @ar_error_messages.present? && @mg_error_messages.blank?
            json = @ar_error_messages
          elsif @ar_error_messages.blank? && @mg_error_messages.present?
            json = @mg_error_messages
          end
          render json: json
        }
      end
    end
759532
def convert_to_local_type(edmx_type)
    return edm_to_ruby_type(edmx_type) if edmx_type =~ /^Edm/
    klass_name = qualify_class_name(edmx_type.split('.').last)
    klass_name.camelize.constantize
  end
134632
def to_ini
      string = @lines.to_a.map { |line| line.to_ini }.join($/)
      string = "#{ string }\n" unless string[-1] == "\n"

      string
    end
664767
def parse_gem(init_lib)
      # puts "Processing: #{init_lib}"
      # don't ask
      init_path = init_lib

      init_file = File.read(init_lib)
      current_file = ""

      init_file.each_line do |line|
        if line.strip =~ /^require/
          parser = RubyParser.new
          sexp = parser.parse(line)
          call = sexp[2]

          unless call == :require
            # WEIRD SHIT IS HAPPENING
            current_file += line
            next
          end

          require_type = sexp[3][1][0]
          library = sexp[3][1][1]
          #p library

          if require_type == :str && library.match(@gem_name)
            # fold in
            full_rb_path = File.join([@lib_folder, "#{library}.rb"])
            unless @require_libs.include?(full_rb_path)
              file_index = @require_libs.index(init_lib)
              insert_index = file_index
              @require_libs.insert insert_index, full_rb_path
              parse_gem(full_rb_path)
            end
          else
            current_file += "# FIXME: #require is not supported in RubyMotion\n"
            current_file += "# #{line}"
            next
          end
          # comment it out
          current_file += "# #{line}"
          next
        elsif line.strip =~ /^autoload/
          # same as require
          parser = RubyParser.new
          sexp = parser.parse(line)
          call = sexp[2]

          unless call == :autoload
            # WEIRD SHIT IS HAPPENING
            current_file += line
            next
          end

          require_type = sexp[3][2][0]
          library = sexp[3][2][1]

          full_rb_path = File.join([@lib_folder, "#{library}.rb"])
          unless @require_libs.include?(full_rb_path)
            file_index = @require_libs.index(init_lib)
            insert_index = file_index
            @require_libs.insert insert_index, full_rb_path
            parse_gem(full_rb_path)
          end
          # comment it out
          current_file += "# #{line}"
          next

        
        elsif line.strip =~ /^eval/
            # reprint as a block
            # parser = RubyParser.new
            # sexp = parser.parse(line)
            # code_str = sexp[3][1][1]
            # new_eval = "eval do\n  #{code_str}\nend\n"
            # current_file += "#{new_eval}"
            # next

            # produce a fixme

            current_file += "# FIXME: Cannot eval strings in RubyMotion. \n"
            current_file += "# Rewrite to use a block.. inbuilt hack will run \n"
            current_file += "# Change this: \n"
            current_file += "# eval %Q{ \n" 
            current_file += '# def #{c}(string = nil) ' + "\n"
            current_file += "# To this \n"
            current_file += "# eval do \n"
            current_file += "# define_method(c) do |string| \n"
            current_file += "#{line}"
            next
        elsif line.strip =~ /^binding/
            current_file += "# FIXME: binding is not supported in RubyMotion.\n"
            current_file += "#{line}"
            next
        end

        # dont intefere
        current_file += line
      end

      # replace file
      File.open(init_lib, 'w') {|f| f.write(current_file) } #unless TEST_MODE

    end
1320414
def to_md
      # Usually ruby is extremely readable, but I think "-1" means "give me all the 
      # trailing blank lines" is surprisingly opaque.  That's what the -1 does...
      lines = @text.split("\n", -1)
      lines.collect do |line|
        result = line
 
        # Leave lines that start with 4 spaces alone.  These are code blocks and
        # should pass through unchanged.
        unless result =~ /^\s{4,}/
 
          # Convert headers
          result.sub!(/^(=){1,6}/) { |s| "#" * s.length} unless result =~ /^={7,}/
 
          # Convert strong to have two stars
          # The matching pair of stars should start with a single star that is either at
          # the beginning of the line or not following a backslash, have at least one
          # non-star and non-backslash in between, then end in one star
          result.gsub!(/(\A|[^\\\*])\*([^\*]*[^\*\\])\*/, '\1**\2**')

          # Convert inline code spans to use backticks
          result.gsub!(/(\A|[^\\])\+([^\+]+)\+/, '\1`\2`')

          # Convert bare http:, mailto: and ftp: links
          result.gsub!(/(\A|\s)(http:|https:|mailto:|ftp:)(\S*)/, '\1[\2\3](\2\3)')

          # Convert bare www to an http: link
          result.gsub!(/(\A|\s)www\.(\S*)/, '\1[www.\2](http://www.\2)')

          # Convert link: links to refer to local files
          result.gsub!(/(\A|\s)link:(\S*)/, '\1[\2](\2)')

          # Convert multi word labels surrounded by {} with a url
          result.gsub!(/\{([^\}]*)\}\[(\S*)\]/, '[\1](\2)')

          # Convert one word labels with a url
          result.gsub!(/(\A|\s)([^\{\s]\S*)\[(\S*)\]/, '\1[\2](\3)')

        end
        
        result
      end.join("\n")
    end