User:Conrad.Irwin/ipa2sampa.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

var IPA2SAMPA = { // http://fr.wiktionary.org/w/index.php?title=MediaWiki:Monobook.js&oldid=3006324
'a':"a", 'b':"b", 'ɓ':"b_<", 'c':"c", 'd':"d", 'ɖ':"d`", 'ɗ':"d_<",
'e':"e", 'f':"f", 'ɡ':"g", 'ɠ':"g_<", 'h':"h", 'ɦ':"h\\", 'i':"i",
'j':"j", 'ʝ':"j\\", 'k':"k", 'l':"l", 'ɭ':"l`", 'ɺ':"l\\", 'm':"m",
'n':"n", 'ɳ':"n`", 'o':"o", 'p':"p", 'ɸ':"p\\", 'q':"q", 'ʠ':"q_<",
'r':"r", 'ɽ':"r`", 'ɹ':"r\\", 'ɻ':"r\\`", 'ɼ':"r\\_r", 's':"s",
'ʂ':"s`", 'ɕ':"s\\", 't':"t", 'ʈ':"t`", 'u':"u", 'v':"v", 'ʋ':"P",
'w':"w", 'x':"x", 'ɧ':"x\\", 'y':"y", 'z':"z", 'ʐ':"z`", 'ʅ':"z`=",
'ʑ':"z\\", 'ɿ':"z=", 'ɑ':"A", 'β':"B", 'ʙ':"B\\", 'ç':"C", 'ð':"D",
'ɛ':"E", 'ɱ':"F", 'ɣ':"G", 'ɢ':"G\\", 'ʛ':"G\\_<", 'ɥ':"H",
'ʜ':"H\\", 'ɪ':"I", 'Ɨ':"I\\", 'ɲ':"J", 'ɟ':"J\\", 'ʄ':"J\\_<",
'ɬ':"K", 'ɮ':"K\\", 'ʎ':"L", 'ʟ':"L\\", 'ɯ':"M", 'ɰ':"M\\", 'ŋ':"N",
'ɴ':"N\\", 'ɔ':"O", 'ʘ':"O\\", 'ɒ':"Q", 'ʁ':"R", 'ʀ':"R\\", 'ʃ':"S",
'ʆ':"S_j", 'θ':"T", 'ʊ':"U", 'ɷ':"U", 'ʊ̵':"U\\", 'ʌ':"V", 'ʍ':"W",
'χ':"X", 'ħ':"X\\", 'ʏ':"Y", 'ʒ':"Z", 'ʓ':"Z_j", 'ˈ':"\"", 'ˌ':"%", //The apostrophe is something wierd
'ʲ':"_j", ' ̡':"_j", 'ː':":", 'ˑ':":\\", '&nbsp;':"-", ' ':"-",
'ə':"@", 'ɘ':"@\\", 'ɚ':"@`", 'æ':"{", 'ʉ':"}", 'ɨ':"1", 'ø':"2",
'ɜ':"3", 'ɝ':"3`", 'ɞ':"3\\", 'ɾ':"4", 'ɫ':"5", 'ɐ':"6", 'ɤ':"7",
'ɵ':"8", 'œ':"9", 'ɶ':"&", 'ʚ':"&\\", 'ʔ':"?", 'ʕ':"?\\", ' ':"*",
' ':"/", ' ':"<", 'ʢ':"<\\", ' ':">", 'ʡ':">\\", '↑':"^", 'ǃ':"!\\",
'ʗ':"!\\", '↓':"!", ' ':"|", 'ǀ':"|\\", ' ':"||", 'ǁ':"|\\|\\",
'ʖ':"|\\|\\", 'ǂ':"=\\", '‿':"-\\", 'ʇ':"|\\", '̈':"_\"", '̟':"_+",
'˖':"_+", '̠':"_-", '˗':"_-", 'ˇ':"_/", '̥':"_0", '˒':"_0",
'̊':"_0", '̩':"=", '̍':"=", 'ʼ':"_>", 'ˀ':"_>", 'ˤ':"_?\\",
'ˆ':"_\\", '̯':"_^", '̚':"_}", '˞':"`", '̢':"`", '̃':"~", '̨':"~",
'̘':"_A", '̺':"_a", '̏':"_B", 'ˏ':"_B_L", '̜':"_c", '˓':"_c",
'̪':"_d", '̴':"_e", '↘':"<F>", '̂':"_F", 'ˠ':"_G", '́':"_H",
'˥':"_T", 'ʰ':"_h", '̴':"_e", '̰':"_k", '̀':"_L", 'ˎ':"_L_B",
'ˡ':"_l", '̄':"_M", '̻':"_m", '̼':"_N", 'ⁿ':"_n", '̹':"_O",
'̞':"_o", '˕':"_o", '̙':"_q", '↗':"_R", '̌':"_R", '̝':"_r",
'˔':"_r", '̋':"_T", 'ˉ':"_T", '̤':"_t", 'ʱ':"_t", '̬':"_v",
'ʷ':"_w", '̫':"_w", '̆':"_X", '̽':"_x", 'ʤ':"dZ", 'ʣ':"dz",
'ʥ':"dz\\", 'ʧ':"tS", 'ʨ':"ts\\", 'ʦ':"ts", '͡':")", '˩':"_B",
'˦':"_H", '˨':"_L", '˧':"_M", '˩':"_B", 'ʳ':"_r", 'ʶ':"_R",
'ʴ':"_r\\", 'ʵ':"_r\\`", 'ˢ':"_s", 'ˣ':"_x", 'ʸ':"_y"}

/**
 * Simple minded Transliterator, more of a proof of concept than anything particularly useful atm
 *
**/
function convert(input, map){
  var output ='';
  for(var s=0;s<input.length;s++){      //Go from left to right
    for(var e=input.length;e>s;e--){    // Start longest possible to shortest possible
      var c = map[input.substr(s,e-s)]; //  Find out what the dictionary says it is
      if(typeof(c) != 'undefined'){     //  See if the dictionary knew what it was talking about
       output+=c; e=0;                  //  If so add the match and move forward a notch
      }
    }
  }
  return output;                        //we're done
}