I think it would be fun to build the Pali Dictionary together. Yesterday I was doing some tests to figure out how to test for the existence of a file (this should be simple, easy and intuitive – it isn’t). At this point, I think I have all of the technical bits and pieces solved.
Building the dictionary like a tutorial
In my opinion, the best way to create the software is to build it step-by-step online like a tutorial. This way, the programmers in the Pali community (even if they don’t know html/css/ javascript/jQuery) will be able to follow along. They will be able to achieve a deep understanding and skills that they can use for modifying, adapting and improving the software.
Using the tutorial idea, I will post a blog post that shows the code used in each step and explain the code. I will also post a zip file for download so that people can download each step and try it out.
jQuery makes putting Tabs in Tabs easy
The software is modular. It will be very easy to add modules to the software and remove modules. JQuery makes it simple to add tabs to an application. A programmer can add their own tab and work on their own ideas while I post up the code.
Here is a screen shot of the current tabs. There is no user interface design here. I was just testing things like adding tabs, loading tabs, creating and modifying templates, the dictionary format, etc. What you are looking at will definitely change.

jQuery lets you put tabs in tabs - nice !
In the next few days, I hope to have Step 1 of the demo tutorial posted for download.
Ideas for files in the Pali dictionary definition
The dictionary content is also very important. If I can get a good pattern going for the dictionary entries then people will be able to create their own dictionary entries and share them easily.
For instance, to create a defintion for anicca you create a directory called anicca and put the following files into it (all files are optional! If you don’t have one right away, it doesn’t matter. You can still create a dictionary entry):
word.txt – a text file (UTF-8) for text related things (like the dhamma meaning – important for monastics!)
word.ogg – an audio file that speaks the word
sentence.ogg – an audio file that speaks the example sentence (that you put in word.txt with other things).
picture.jpeg – a picture (if available and useful)
video.ogv – a video (if available and useful)
defintion.png – an image of a dictionary definition for the word
defintion.ogg – an audio file that simply reads the defintion out loud to enhance the learning experience
definition.maff – a Firefox 4 maff file (for offline use of dictionary entry web pages)
The file formats may change but this gives an idea of the things that can be used for creating a nice dictionary entry. To share the dictionary entry, you can simply send it to someone as a compressed zip file. If you don’t like the picture or the accent of the sound files, you can just make your own and replace the existing files. Very easy.
The nice thing is that nothing is required in the dictionary folder and no complicated technology is required. If you have a picture – great. If you don’t have a picture – that’s fine, too. If you later get a picture from somewhere – just copy it into the dictionary entry directory like you copy any file on your computer. This offers completeness plus maximum flexibility while dictionary entries are being created.
Grammar in context
The way I have it set up right now, you can specify the grammar notes. For instance, if the word is a noun then you can simply state that in word.txt and the definition/explanation for a noun becomes part of the definition (at the bottom). This should make it much easier to learn Pali grammar while you are studying words.
Use javascript and jQuery to test for file exist
Here is the code that I have right now to test for a file using javascript and jQuery. It works in Firefox 4 but I am not certain that it is 100% optimized. In particular, I don’t know (right now) why the type : ‘HEAD’ is needed.
What I am doing here is checking if a file exists. If it does not exist then I replace the html for the span that shows the audio control. Firefox does not handle a missing audio file in a nice way. I puts a big box with a big letter x in the box. Proper behavior would be to create an image the same size as the audio control with a message on it that says ‘audio file not found’ (or something like that). Firefox 4 will mess up your web page display if it doesn’t find the audio file.
First, here is how I call the file existence test to see if sentence.ogg exists as a file :
Put this code Second in your javascript js file :
fileNameToTest = fileNameBasePath + "/sentence.ogg";
doesFileExist(
fileNameToTest,
"span#span_for_sentence_audio",
"<span'>no audio for " + fileNameBasePath + "/sentence.ogg</span>");
Note that the following function must appear before the code above ! I’m not sure, but it seems that Javascript needs to find the function definition before it is used in the code.? I’ll have to check on this.
Put this code First in your javascript js file.
function doesFileExist(urlToTest, idToReplace, replacmentHtml){
$.ajax({
url: urlToTest,
type:'HEAD',
error:
function(){
//alert("File not found.");
$(idToReplace).replaceWith(replacmentHtml);
},
success:
function(){
//alert("File found.");
}
});
}
If you just want to test for a file :
// this is the function that you need to add
function yourNameFor_doesFileExist(yourNameFor_urlToTest){
$.ajax({
url: yourNameFor_urlToTest,
type:'HEAD',
error:
function(){
alert("File not found.");
},
success:
function(){
alert("File found.");
}
});
}
// a bunch of code and functions later...
// now you can call it - it can test for many types (html, jpeg, ogg, etc)
yourNameFor_doesFileExist("yourfolder/yourfile.html");
New look for blog coming up
I’ll be changing the look of the blog in the next week or so. The blog looks nice but it is very clumsy to manage the look and it requires a lot of bandwidth for people using the blog.
I hope that you got a few ideas. I hope to start the tutorial soon. The code above is just stuff that I think might help out Papli javascript and jQuery programmers while I work at getting things for the tutorial ready.
That’s all for today.