Consider the simple following HTML code:
<input id="dict_field" type="text"/>
<button id="translate_btn" type="button" class="btn">translate</button>
The user inputs something and clicking the button triggers a function that returns a translation.
And the JQuery code:
$(document).ready(function(){
$('#translate_btn').click(function(){
var word = $('#dict_field').val();
var translation = "";
translation = translate(word (, dictionary?));
// For simplicity for now just display the result in the same input field
$('#dict_field').val(translation)
});
});
// pseudo code. How to implement this and build the dictionary I need?
function translate(word (, dictionary?)){
if word in dictionary.keys() -> return dictionary[word]
else return "no such word in dict"
}
Given the following:
- The translation needs only to be one way (key to value).
- The dictionary is custom made (meaning I have to build it, I cannot count on external API such as Google's).
- I estimate the size of the dictionary keys could be of the order of thousands, say between 1 and 5000.
- Not sure if related but eventually I'd like the translation to happen in real time (as soon as the user finishes the input without need of a button click). This for now is secondary.
What is a good way, "objectively", to build a map/dictionary {key:value} to implement a translation function/API? Any detail can be considered, such as speed, scalability, cost etc., keeping in view my above requirements.
I've little experience with this kind of things, but I have some thoughts, such as:
- Use a very long js file containing the dictionary (might not be a good idea)
- Store everything in a text file and read from there
- Look at some database (but won't that be overkill?)
Appreciate valuable suggestions. Thanks for any help.