'Add a new language. Note that you generally only need to do
this once per language and that adding an existing language
will re-initialize all the random components to new permanent
values.
Args:
key (str, optional): The name of the language. This
will be used as an identifier for the language so it
should be short and unique.
phonemes (str, optional): Space-separated string of all allowed
phonemes in this language.
grammar (str): All allowed consonant (c) and vowel (v) combinations
allowed to build up words. For example cvv would be a consonant
followed by two vowels (would allow for a word like \'die\').
word_length_variance (real): The variation of length of words.
0 means a minimal variance, higher variance may mean words
have wildly varying length; this strongly affects how the
language "looks".
noun_prefix (str, optional): A prefix to go before every noun
in this language (if any).
noun_postfix (str, optuonal): A postfix to go after every noun
in this language (if any, usually best to avoid combining
with `noun_prefix` or language becomes very wordy).
vowels (str, optional): Every vowel allowed in this language.
manual_translations (dict, optional): This allows for custom-setting
certain words in the language to mean the same thing. It is
on the form `{real_word: fictional_word}`, for example
`{"the", "y\'e"}` .
auto_translations (str or list, optional): These are lists
words that should be auto-translated with a random, but
fixed, translation. If a path to a file, this file should
contain a list of words to produce translations for, one
word per line.  If a list, the list\'s elements should be
the words to translate.  The `manual_translations` will
always override overlapping translations created
automatically.
force (bool, optional): Unless true, will not allow the addition
of a language that is already created.
Raises:
LanguageExistsError: Raised if trying to adding a language
with a key that already exists, without `force` being set.
Notes:
The `word_file` is for example a word-frequency list for
the N most common words in the host language. The
translations will be random, but will be stored
persistently to always be the same. This allows for
building a quick, decently-sounding fictive language that
tend to produce the same "translation" (mostly) with the
same input sentence.'

def add(self, key='default', phonemes=_PHONEMES, grammar=_GRAMMAR, word_length_variance=0, noun_prefix='', noun_postfix='', vowels=_VOWELS, manual_translations=None, auto_translations=None, force=False):

    if ((key in self.db.language_storage) and (not force)):
        raise LanguageExistsError
    gramdict = defaultdict(list)
    for gram in grammar.split():
        gramdict[len(gram)].append(gram)
    grammar = dict(gramdict)
    grammar2phonemes = defaultdict(list)
    for phoneme in phonemes.split():
        gram = ''.join([('v' if (char in vowels) else 'c') for char in phoneme])
        grammar2phonemes[gram].append(phoneme)
    translation = {}
    if auto_translations:
        if isinstance(auto_translations, basestring):
            with open(auto_translations, 'r') as f:
                auto_translations = f.readlines()
        for word in auto_translations:
            word = word.strip()
            lword = len(word)
            new_word = ''
            wlen = max(0, (lword + sum((randint((-1), 1) for i in range(word_length_variance)))))
            if (wlen not in grammar):
                structure = choice(grammar[choice(list(grammar))])
            else:
                structure = choice(grammar[wlen])
            for match in _RE_GRAMMAR.finditer(structure):
                new_word += choice(grammar2phonemes[match.group()])
            translation[word.lower()] = new_word.lower()
    if manual_translations:
        translation.update(dict(((key.lower(), value.lower()) for (key, value) in manual_translations.items())))
    storage = {'translation': translation, 'grammar': grammar, 'grammar2phonemes': dict(grammar2phonemes), 'word_length_variance': word_length_variance, 'noun_prefix': noun_prefix, 'noun_postfix': noun_postfix}
    self.db.language_storage[key] = storage
