Adding translations using Javascript
Fragment of a discussion from User talk:Yair rand/LQT archive
No, I don't think there is one. If you already have the gloss, language code, and language name available, and don't have to deal with complicated situations (nesting, multiple translations for one language, etc), you're probably best off doing something like this:
JsMwApi().page(entryname).edit( function (text, save_function, r){ var p = text.indexOf("{"+"{trans-top|"+gloss+"}}"), b = text.indexOf("\n{"+"{trans-bottom}}", p), added_wikitext = "\n* " + languagename + ": {" + "{t|" + languagecode + "|" + translation + "}}"; while( p < b && p > -1 ){ p = text.indexOf("\n* ", p+1); if( text.substr( p ) > added_wikitext ) break; } if( p > b || p == -1) p = b; save_function( text.substr( 0, p ) + added_wikitext + text.substr( p ), {summary:"+trans: [["+translation+"]]"}, function( was_successful ) { // ... } ) } )
(^ Not intended for actual use.)
Thank you!
Dan Polansky (talk)