Difference between revisions of "Template:Decliner"

From Jonathan Gardner's Latin Notebook
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
<option>genitive</option>
 
<option>genitive</option>
 
<option>dative</option>
 
<option>dative</option>
<opion>ablative</option>
+
<option>ablative</option>
 
</select>
 
</select>
 
<select name="number">
 
<select name="number">
Line 21: Line 21:
 
Error: <span id="decline_error"/>
 
Error: <span id="decline_error"/>
 
</div>
 
</div>
<script type="text/javascript">
 
function decline_submit(form) {
 
    try {
 
        document.getElementById('decline_success').style.display = '';
 
        document.getElementById('decline_failure').style.display = 'none';
 
        document.getElementById('decline_result').innerHTML = decline(
 
            form.noun.value,
 
            form.case_.value,
 
            form.number.value);
 
    } catch(error) {
 
        document.getElementById('decline_failure').style.display = '';
 
        document.getElementById('decline_success').style.display = 'none';
 
        document.getElementById('decline_error').innerHTML = error.message;
 
    }
 
}
 
 
function decline(noun, case_, number) {
 
    var m;
 
    noun = noun.replace(/^\s+|\s+$/g, '');
 
 
    if (!noun) {
 
        throw new Error("You must specify a noun.");
 
    }
 
 
    if (m = /^(.*)(a|am|ae|as|arum|is)$/.exec(noun)) {
 
        return m[1]+{
 
              singular: {
 
                nominative: 'a',
 
                vocative:  'a',
 
                accusative: 'am',
 
                genitive:  'ae',
 
                dative:    'ae',
 
                ablative:  'a\u0304',
 
            },
 
            plural: {
 
                nominative: 'ae',
 
                vocative:  'ae',
 
                accusative: 'a\u0304s',
 
                genitive:  'a\u0304rum',
 
                dative:    'i\u0304s',
 
                ablative:  'i\u0304s',
 
            }
 
        }[number][case_];
 
    } else {   
 
        throw new Error("That doesn't look like a first declension noun.");
 
    }
 
}
 
</script>
 
 
</html>
 
</html>

Latest revision as of 16:47, 23 February 2012