Example #1
0
 def addWord(self, sLang, word, dLang, transWord):
     """
     Adds new word
     
     sLang - source language, string
     word - source word, string
     dLang - destination language, string
     transWord - translated work, string
     
     en - counter for english apparences
     fr - counter for french
     ro - counter for ro
     en,fr,ro - integer
     
     Checks if a word appears more than once
     
     validates the translation of given parameteres
     if not valid returns error list
     if valid then searches in translationList (from Repository) if the words already
     has a translation in given language
     returns messages if word already has translation, adds if not
     """
     translation = Translation(sLang, word, dLang, transWord)
     errorList = self.__transValidator.validateTranslation(translation)
     if len(errorList) != 0:
         return errorList
     en = 0
     fr = 0
     ro = 0
     for translation in self.__transRepository.translationList:
         if translation.getWord() == word and translation.getSLang(
         ) == sLang:
             if translation.getDLang() == "En":
                 en += 1
             elif translation.getDLang() == "Ro":
                 ro += 1
             elif translation.getDLang() == "Fr":
                 fr += 1
     if en == 1 and dLang == "En":
         return "A word cannot have 2 translations in the same destination language"
     if fr == 1 and dLang == "Fr":
         return "A word cannot have 2 translations in the same destination language"
     if ro == 1 and dLang == "Ro":
         return "A word cannot have 2 translations in the same destination language"
     return self.__transRepository.storeTranslation(sLang, word, dLang,
                                                    transWord)
Example #2
0
 def addWord(self,sLang,word,dLang,transWord):
     """
     Adds new word
     
     sLang - source language, string
     word - source word, string
     dLang - destination language, string
     transWord - translated work, string
     
     en - counter for english apparences
     fr - counter for french
     ro - counter for ro
     en,fr,ro - integer
     
     Checks if a word appears more than once
     
     validates the translation of given parameteres
     if not valid returns error list
     if valid then searches in translationList (from Repository) if the words already
     has a translation in given language
     returns messages if word already has translation, adds if not
     """
     translation = Translation (sLang,word,dLang,transWord)
     errorList = self.__transValidator.validateTranslation(translation)
     if len(errorList) != 0:
         return errorList
     en = 0
     fr = 0
     ro = 0
     for translation in self.__transRepository.translationList:
         if translation.getWord() == word and translation.getSLang() == sLang:
             if translation.getDLang() == "En":
                 en += 1
             elif translation.getDLang() == "Ro":
                 ro += 1
             elif translation.getDLang() == "Fr":
                 fr += 1
     if en == 1 and dLang == "En":
         return "A word cannot have 2 translations in the same destination language"
     if fr == 1 and dLang == "Fr":
         return "A word cannot have 2 translations in the same destination language"
     if ro == 1 and dLang == "Ro":
         return "A word cannot have 2 translations in the same destination language"
     return self.__transRepository.storeTranslation(sLang,word,dLang,transWord)
Example #3
0
 def storeTranslation(self, sLang, word, dLang, transWord):
     """
     Stores translation of given parameters
     
     sLang - source language, string
     word - source word, string
     dLang - destination language, string
     transWord - translated word, string
     
     open file with writing capabilities
     write translations from memory to file, one on a row
     return message
     """
     trans = Translation(sLang, word, dLang, transWord)
     self.translationList.append(trans)
     self.__translationFile = open(self.__fileName, "w")
     for trans in self.translationList:
         self.__translationFile.write(
             str(trans.getSLang()) + "," + str(trans.getWord()) + "," +
             str(trans.getDLang()) + "," + str(trans.getTransWord()) + "\n")
     self.__translationFile.close()
     return "Translation added successfully!"
Example #4
0
 def storeTranslation(self,sLang,word,dLang,transWord):
     """
     Stores translation of given parameters
     
     sLang - source language, string
     word - source word, string
     dLang - destination language, string
     transWord - translated word, string
     
     open file with writing capabilities
     write translations from memory to file, one on a row
     return message
     """
     trans = Translation (sLang,word,dLang,transWord)
     self.translationList.append(trans)
     self.__translationFile = open (self.__fileName,"w")
     for trans in self.translationList:
         self.__translationFile.write(str(trans.getSLang()) + "," + str(trans.getWord()) + "," + str(trans.getDLang()) + "," + str(trans.getTransWord()) + "\n")
     self.__translationFile.close()
     return "Translation added successfully!"