I am working on a project that is essentially a translation dictionary for conlangs , or constructed languages. It allows the user to enter English words and their translation in the conlang, to search for translations by English, and delete words from the dictionary.
Right now, I am working with Python 2.5 on Win32.
I am, naturally, using a Python dictionary {} as the method for doing this, as it makes the most sense. I am using the English word as the key, and the translated word as the value.
I want to include a reverse translation - that is, to go from the constructed language back to English. I have been using this function I created to do it:
Expand|Select|Wrap|Line Numbers
- def revSearch(d):
- target = raw_input("Enter the target language word to translate: ")
- for key in d:
- if target in d[key]:
- print "Possible translation for %s is: %s" % (target, key)
- print "Press ENTER to continue"
- raw_input()
I will use French as an example::
Expand|Select|Wrap|Line Numbers
- If the dictionary contains these values {'my' : 'mon', 'mister' : 'monsieur'}
- The program asks:
- Enter the target language word to translate: mon
- Output ->
- Possible translation for mon is: my
- Possible translation for mon is: mister
What would be ideal is for the search to respond only if it finds the *exact* value that I enter, and ignore the others. Or, if I'm going about it all wrong, and there's another method that would get me more precise output, I'd be happy to hear about that too. After 2 hours of fruitless web searching, I decided to come here and ask, hoping that a community might be able to come up with something. After all, isn't that the beauty of open-source? :D
Thanks in advance for any help you might be able to provide.