def resume_translations(sentence_filename,
                        partial_translation_file,
                        sourceLang,
                        targetLang="en",
                        write_to_file=True):
    sentences = read_lines_from_file(sentence_filename)
    existing_translations = read_lines_from_file(partial_translation_file)
    translations = []
    for i, sentence in enumerate(sentences):
        translation = ''
        if i < len(existing_translations) and not existing_translations[
                i].startswith("No translation"):
            translation = existing_translations[i]
            print '.',
        else:
            try:
                translation = bingtrans.translate(sentence, sourceLang,
                                                  targetLang)
                print '+',
            except ValueError:
                translation = 'No translation for this segment'
                print '-',
        if i % 100 == 0:
            print ' '
        translations.append(translation)
        if (write_to_file):
            short_list = []
            short_list.append(translation)
            short_list = write_lines_to_file(
                sentence_filename + ".google_translate", short_list)
    return translations
def get_translations(sentence_filename,
                     sourceLang,
                     targetLang="en",
                     write_to_file=True):
    sentences = read_lines_from_file(sentence_filename)
    translations = []
    if sourceLang == "ur":
        for i in range(0, len(sentences)):
            translations.append(u"")
        translations = write_lines_to_file(
            sentence_filename + ".google_translate", translations)
    else:
        for sentence in sentences:
            translation = ''
            try:
                translation = bingtrans.translate(sentence, sourceLang,
                                                  targetLang)
            except ValueError:
                translation = 'No translation for this segment'
            translations.append(translation)
            if (write_to_file):
                short_list = []
                short_list.append(translation)
                short_list = write_lines_to_file(
                    sentence_filename + ".google_translate", short_list)
    return translations
Ejemplo n.º 3
0
 def snx_translate(self, speech, language):
     match = re.match(u"Translate (.*\D.*) from (english|spanish|french|italian|estonian|finnish|Greek|Arabic|czech|dutch|hebrew|russian|polish|portuguese|romanian|swedish|turkish|indonesian|hungarian) to (english|spanish|french|italian|estonian|finnish|greek|arabic|czech|dutch|hebrew|russian|polish|portuguese|romanian|swedish|turkish|indonesian|hungarian)", speech, re.IGNORECASE)
     text = match.group(1)
     lang1 = match.group(2).replace('english', 'en').replace('spanish', 'es').replace('french', 'fr').replace('italian','it').replace('estonian','et').replace('finnish','fi').replace('greek','el').replace('arabic','ar').replace('czech' ,'cs').replace('dutch' ,'nl').replace('hebrew' ,'he').replace('russian' ,'ru').replace('polish' ,'pl').replace('portuguese' ,'pt').replace('romanian' ,'ro').replace('swedish' ,'sv').replace('turkish' ,'tr').replace('indonesian' ,'id').replace('hungarian' ,'id')
     lang2 = match.group(3).replace('english', 'en').replace('spanish', 'es').replace('french', 'fr').replace('italian','it').replace('estonian','et').replace('finnish','fi').replace('greek','el').replace('arabic','ar').replace('czech' ,'cs').replace('dutch' ,'nl').replace('hebrew' ,'he').replace('russian' ,'ru').replace('polish' ,'pl').replace('portuguese' ,'pt').replace('romanian' ,'ro').replace('swedish' ,'sv').replace('turkish' ,'tr').replace('indonesian' ,'id').replace('hungarian' ,'id')
     self.say("Here is your translation:\n")
     self.say(bingtrans.translate(text, lang1, lang2), ' ')
     self.complete_request()
Ejemplo n.º 4
0
	def snx_translate(self, speech, language, matchedRegex):
		text = matchedRegex.group('transword')
		longlang1 = matchedRegex.group('fromlang').lower()
		longlang2 = matchedRegex.group('tolang').lower()
		try:
			lang1 = res['languageCodes'][language][longlang1]
		except KeyError:
			self.say(res['errors'][language].format(longlang1))
			raise
		try:
			lang2 = res['languageCodes'][language][longlang2]
		except KeyError:
			self.say(res['errors'][language].format(longlang2))
			raise
		self.say(res['answer'][language].format(longlang2, text))
		self.say(bingtrans.translate(text, lang1, lang2, ' '), ' ')
		self.complete_request()
Ejemplo n.º 5
0
def translate_text(text, src='ar', tgt='en'):
    translation = text
    #===========================================================================
    # try:
    #    detected = parse_result(alchemyObj.TextGetLanguage(text), "iso-639-1")
    #    src = detected[0]['iso-639-1']
    # except Exception, e:
    #    print e
    #    src = 'en'
    #===========================================================================

    if src != 'en':
        try:
            translation = bingtrans.translate(text, src, tgt)
        except ValueError:
            pass
    return translation
Ejemplo n.º 6
0
def translate_text(text, src="ar", tgt="en"):
    translation = text
    # ===========================================================================
    # try:
    #    detected = parse_result(alchemyObj.TextGetLanguage(text), "iso-639-1")
    #    src = detected[0]['iso-639-1']
    # except Exception, e:
    #    print e
    #    src = 'en'
    # ===========================================================================

    if src != "en":
        try:
            translation = bingtrans.translate(text, src, tgt)
        except ValueError:
            pass
    return translation
def get_translations(sentence_filename, sourceLang, targetLang="en", write_to_file=True):
    sentences = read_lines_from_file(sentence_filename)
    translations = []
    if sourceLang == "ur":
        for i in range(0, len(sentences)): translations.append(u"")
        translations = write_lines_to_file(sentence_filename + ".google_translate", translations)
    else:
        for sentence in sentences:
            translation = ''
            try:
                translation = bingtrans.translate(sentence, sourceLang, targetLang)
            except ValueError:
                translation = 'No translation for this segment'
            translations.append(translation)
            if(write_to_file):
                short_list = []
                short_list.append(translation)
                short_list = write_lines_to_file(sentence_filename + ".google_translate", short_list)
    return translations
def resume_translations(sentence_filename, partial_translation_file, sourceLang, targetLang="en", write_to_file=True):
    sentences = read_lines_from_file(sentence_filename)
    existing_translations = read_lines_from_file(partial_translation_file)
    translations = []
    for i, sentence in enumerate(sentences):
       translation = ''
       if i < len(existing_translations) and not existing_translations[i].startswith("No translation"):
          translation = existing_translations[i]
          print '.',
       else:
          try:
             translation = bingtrans.translate(sentence, sourceLang, targetLang)
             print '+',
          except ValueError:
             translation = 'No translation for this segment'
             print '-',
       if i % 100 == 0:
           print ' '
       translations.append(translation)
       if(write_to_file):
          short_list = []
          short_list.append(translation)
          short_list = write_lines_to_file(sentence_filename + ".google_translate", short_list)
    return translations
Ejemplo n.º 9
0
 def testBingTranslate(self):   
     bingtrans.set_app_id('5521E4A630094D968D49B39B6511A0A76CB025E1')  # you can get your AppID at: http://www.bing.com/developers/
     result = bingtrans.translate("هذا هو الاختبار", 'ar', 'en') 
     self.assertEqual("This is a test", result)            
Ejemplo n.º 10
0
def Andmed():
    linn = Linn_Entry.get()  # Kasutaja sisestab asukoha andmed
    # Kogu funktsioon on võetud try-excepti, kuna igal asukohal ei ole kõiki andmeid olemas ja selle tõttu võis tekkida
    # väga palju veateateid. Enamus asukohtadel on 70-90% ilmaandmetest olemas.

    try:
        lookup = pywapi.get_location_ids(linn)  # Sisestatud asukoht saab kõik sarnase nimega asukoha id'd.

        # Mitme id korral käib kõik id'd läbi ja kontrollib, kas nimi on sama kui kasutaja sisestatud.
        for i in lookup:
            if lookup[i].split(",")[0] == linn:
                asukoha_id = i

        # Asukoha id järgi leitakse kogu ilma informatsioon weather.com'ist. Tekib sõnastik.
        ilm = pywapi.get_weather_from_weather_com(asukoha_id)

        # Pealkiri
        Label0 = Label(gui, text="Ilmaandmed", bg="white", font="Verdana 16 bold").grid(row=3, sticky=W + E,
                                                                                        columnspan=6)

        # TÄNA


        # Vastava lühikokkuvõttele on vastav pilt.
        if "Rain" in ilm["current_conditions"]["text"] or "Light Rain Shower" == ilm["current_conditions"]["text"]:
            Labelooo = Label(gui, image=pic1, pady=5, bg="white").grid(row=4, column=1, sticky=W + E)
        elif "Sunny" in ilm["current_conditions"]["text"]:
            Labeloo1 = Label(gui, image=pic2, pady=5, bg="white").grid(row=4, column=1, sticky=W + E)
        elif "Snow" in ilm["current_conditions"]["text"]:
            Labeloo2 = Label(gui, image=pic3, pady=5).grid(row=4, column=1, sticky=W + E, columnspan=2)
        elif "Cloudy" == ilm["current_conditions"]["text"] or "Fog" in ilm["current_conditions"]["text"] or "Mostly" in \
                ilm["current_conditions"]["text"]:
            Labeloo3 = Label(gui, image=pic4, pady=5).grid(row=4, column=1, sticky=W + E)
        elif "Partly" in ilm["current_conditions"]["text"]:
            Labeloo4 = Label(gui, image=pic5, pady=5).grid(row=4, column=1, sticky=W + E)
        elif "Thunder" in ilm["current_conditions"]["text"]:
            Labeloo5 = Label(gui, image=pic6, pady=5).grid(row=4, column=1, sticky=W + E)

        # Asukoht inglise keeles/asukoha ilmajaama nimi inglise keeles.
        try:
            LabelO1 = Label(gui,
                            text=ilm["location"]["name"].split(",")[0] + "," + ilm["location"]["name"].split(",")[2],
                            width=15).grid(row=6, column=1, sticky=W)
        except:
            pass

        # Kuupäev.
        try:
            LabelO2 = Label(gui, text=time.strftime("%b %d"), width=15).grid(row=7, column=1,
                                                                             sticky=W)
        except:
            pass

        # Temperatuur celsius.
        try:
            LabelO3 = Label(gui, text=ilm["current_conditions"]["temperature"] + " °C",
                            width=15).grid(row=8, column=1, sticky=W)
        except:
            pass

        # Tajutud temperatuur celsius.
        try:
            LabelO4 = Label(gui, text=ilm["current_conditions"]["feels_like"] + " °C ",
                            width=15).grid(row=9, column=1, sticky=W)
        except:
            pass

        # Niiskustase.
        try:
            LabelO5 = Label(gui, text=ilm["current_conditions"]["humidity"] + "%",
                            width=15).grid(row=10, column=1, sticky=W)
            pass

        except:
            pass

        # Lühikokkuvõte, mis tõlgitakse eesti keelde. Lühikokkuvõtte järgi pannakse ilma olukorrale kõige sarnasem pilt.
        try:
            LabelO6 = Label(gui, text=translate(ilm["current_conditions"]["text"], 'en', 'et'),
                            width=15).grid(row=11, column=1, sticky=W)
        except:
            pass

        # Tuule kiirus m/s.
        try:
            LabelX7 = Label(gui, text=str(round((float(ilm["current_conditions"]["wind"]["speed"])) / 3.6, 1)) + " m/s",
                            width=15).grid(row=12, column=1, sticky=W)  # Tuulekiirus
        except:
            pass

        # Tuule suund.
        try:
            LabelO8 = Label(gui, text=ilm["current_conditions"]["wind"]["text"], width=15).grid(
                    row=13, column=1, sticky=W)  # Tuulesuund
        except:
            pass


        # HOMME


        if "Rain" in ilm["forecasts"][1]["day"]["text"] or "Shower" in ilm["forecasts"][1]["day"]["text"]:
            Labelooo00 = Label(gui, image=pic1, pady=5).grid(row=4, column=3, sticky=W + E)
        elif "Sunny" in ilm["forecasts"][1]["day"]["text"]:
            Labeloo001 = Label(gui, image=pic2, pady=5).grid(row=4, column=3, sticky=W + E)
        elif "Snow" in ilm["forecasts"][1]["day"]["text"]:
            Labeloo002 = Label(gui, image=pic3, pady=5).grid(row=4, column=3, sticky=W + E)
        elif "Cloudy" == ilm["forecasts"][1]["day"]["text"] or "Fog" in ilm["forecasts"][1]["day"][
            "text"] or "Mostly" in \
                ilm["current_conditions"]["text"]:
            Labeloo003 = Label(gui, image=pic4, pady=5).grid(row=4, column=3, sticky=W + E)
        elif "Partly" in ilm["forecasts"][1]["day"]["text"]:
            Labeloo004 = Label(gui, image=pic5, pady=5).grid(row=4, column=3, sticky=W + E)
        elif "Thunder" in ilm["forecasts"][1]["day"]["text"]:
            Labeloo005 = Label(gui, image=pic6, pady=5).grid(row=4, column=3, sticky=W + E)

        # Kuupäev.
        try:
            LabelO1 = Label(gui,
                            text=ilm["forecasts"][1]["date"], width=15).grid(row=6, column=3, sticky=W)
        except:
            pass

        # Kõrgeim temperatuur
        try:
            LabelO2 = Label(gui, text=ilm["forecasts"][1]["high"] + " °C", width=15).grid(row=7, column=3,
                                                                                          sticky=W)
        except:
            pass

        # Madalaim temperatuur celsius.
        try:
            LabelO3 = Label(gui, text=ilm["forecasts"][1]["low"] + " °C",
                            width=15).grid(row=8, column=3, sticky=W)
        except:
            pass

        # Change of Precipation, probapility of precipation --> Vihma tõenäosus.
        try:
            LabelO4 = Label(gui, text=ilm["forecasts"][1]["day"]["chance_precip"] + " %",
                            width=15).grid(row=9, column=3, sticky=W)
        except:
            pass

        # Niiskustase.
        try:
            LabelO5 = Label(gui, text=ilm["forecasts"][1]["day"]["humidity"] + "%",
                            width=15).grid(row=10, column=3, sticky=W)
            pass

        except:
            pass

        # Lühikokkuvõte, mis tõlgitakse eesti keelde. Lühikokkuvõtte järgi pannakse ilma olukorrale kõige sarnasem pilt.
        try:
            LabelO6 = Label(gui, text=translate(ilm["forecasts"][1]["day"]["text"], 'en', 'et'),
                            width=15).grid(row=11, column=3, sticky=W)
        except:
            pass

        # Tuule kiirus m/s.
        try:
            LabelX7 = Label(gui,
                            text=str(round((float(ilm["forecasts"][1]["day"]["wind"]["speed"])) / 3.6, 1)) + " m/s",
                            width=15).grid(row=12, column=3, sticky=W)  # Tuulekiirus
        except:
            pass

        # Tuule suund.
        try:
            LabelO8 = Label(gui, text=ilm["forecasts"][1]["day"]["wind"]["text"], width=15).grid(
                    row=13, column=3, sticky=W)  # Tuulesuund
        except:
            pass


        # ÜLEHOMME


        if "Rain" in ilm["forecasts"][2]["day"]["text"] or "Shower" in ilm["forecasts"][1]["day"]["text"]:
            Labelooo00 = Label(gui, image=pic1, pady=5).grid(row=4, column=4, sticky=W + E)
        elif "Sunny" in ilm["forecasts"][2]["day"]["text"]:
            Labeloo001 = Label(gui, image=pic2, pady=5).grid(row=4, column=4, sticky=W + E)
        elif "Snow" in ilm["forecasts"][2]["day"]["text"]:
            Labeloo002 = Label(gui, image=pic3, pady=5).grid(row=4, column=4, sticky=W + E)
        elif "Cloudy" == ilm["forecasts"][2]["day"]["text"] or "Fog" in ilm["forecasts"][1]["day"][
            "text"] or "Mostly" in \
                ilm["current_conditions"]["text"]:
            Labeloo003 = Label(gui, image=pic4, pady=5).grid(row=4, column=4, sticky=W + E)
        elif "Partly" in ilm["forecasts"][2]["day"]["text"]:
            Labeloo004 = Label(gui, image=pic5, pady=5).grid(row=4, column=4, sticky=W + E)
        elif "Thunder" in ilm["forecasts"][2]["day"]["text"]:
            Labeloo005 = Label(gui, image=pic6, pady=5).grid(row=4, column=4, sticky=W + E)

        # Kuupäev
        try:
            LabelO1 = Label(gui,
                            text=ilm["forecasts"][2]["date"], width=15).grid(row=6, column=4, sticky=W)
        except:
            pass

        # Kõrgeim temperatuur.
        try:
            LabelO2 = Label(gui, text=ilm["forecasts"][2]["high"] + " °C", width=15).grid(row=7, column=4, sticky=W)
        except:
            pass

        # Madalaim temperatuur.
        try:
            LabelO3 = Label(gui, text=ilm["forecasts"][2]["low"] + " °C", width=15).grid(row=8, column=4, sticky=W)
        except:
            pass

        # Vihma tõenäosus
        try:
            LabelO4 = Label(gui, text=ilm["forecasts"][2]["day"]["chance_precip"] + " %",
                            width=15).grid(row=9, column=4, sticky=W)
        except:
            pass

        # Niiskustase.
        try:
            LabelO5 = Label(gui, text=ilm["forecasts"][2]["day"]["humidity"] + " %",
                            width=15).grid(row=10, column=4, sticky=W)
            pass

        except:
            pass

        # Lühikokkuvõte, mis tõlgitakse eesti keelde. Lühikokkuvõtte järgi pannakse ilma olukorrale kõige sarnasem pilt.
        try:
            LabelO6 = Label(gui, text=translate(ilm["forecasts"][2]["day"]["text"], 'en', 'et'),
                            width=15).grid(row=11, column=4, sticky=W)
        except:
            pass

        # Tuule kiirus m/s.
        try:
            LabelX7 = Label(gui,
                            text=str(round((float(ilm["forecasts"][2]["day"]["wind"]["speed"])) / 3.6, 1)) + " m/s",
                            width=15).grid(row=12, column=4, sticky=W)  # Tuulekiirus
        except:
            pass

        # Tuule suund.
        try:
            LabelO8 = Label(gui, text=ilm["forecasts"][2]["day"]["wind"]["text"], width=15).grid(
                    row=13, column=4, sticky=W)  # Tuulesuund
        except:
            pass



        # 3 PÄEVA PÄRAST



        # Ilma olukorra pildid.
        if "Rain" in ilm["forecasts"][3]["day"]["text"] or "Shower" in ilm["forecasts"][3]["day"]["text"]:
            Labelooo00 = Label(gui, image=pic1, pady=5).grid(row=4, column=5, sticky=W + E)
        elif "Sunny" in ilm["forecasts"][3]["day"]["text"]:
            Labeloo001 = Label(gui, image=pic2, pady=5).grid(row=4, column=5, sticky=W + E)
        elif "Snow" in ilm["forecasts"][3]["day"]["text"]:
            Labeloo002 = Label(gui, image=pic3, pady=5).grid(row=4, column=5, sticky=W + E)
        elif "Cloudy" == ilm["forecasts"][3]["day"]["text"] or "Fog" in ilm["forecasts"][3]["day"][
            "text"] or "Mostly" in \
                ilm["current_conditions"]["text"]:
            Labeloo003 = Label(gui, image=pic4, pady=5).grid(row=4, column=5, sticky=W + E)
        elif "Partly" in ilm["forecasts"][3]["day"]["text"]:
            Labeloo004 = Label(gui, image=pic5, pady=5).grid(row=4, column=5, sticky=W + E)
        elif "Thunder" in ilm["forecasts"][3]["day"]["text"]:
            Labeloo005 = Label(gui, image=pic6, pady=5).grid(row=4, column=5, sticky=W + E)

        # Kuupäev.
        try:
            LabelO1 = Label(gui,
                            text=ilm["forecasts"][3]["date"], width=15).grid(row=6, column=5, sticky=W)
        except:
            pass

        # Kõrgeim temperatuur
        try:
            LabelO2 = LabelO2 = Label(gui, text=ilm["forecasts"][3]["high"] + " °C", width=15).grid(row=7, column=5,
                                                                                                    sticky=W)

        except:
            pass

        # Madalaim temperatuur.
        try:
            LabelO3 = Label(gui, text=ilm["forecasts"][3]["low"] + " °C",
                            width=15).grid(row=8, column=5, sticky=W)
        except:
            pass

        # Vihma tõenäosus.
        try:
            LabelO4 = Label(gui, text=ilm["forecasts"][3]["day"]["chance_precip"] + " %",
                            width=15).grid(row=9, column=5, sticky=W)
        except:
            pass

        # Niiskustase.
        try:
            LabelO5 = Label(gui, text=ilm["forecasts"][3]["day"]["humidity"] + "%",
                            width=15).grid(row=10, column=5, sticky=W)
            pass

        except:
            pass

        # Lühikokkuvõte, mis tõlgitakse eesti keelde. Lühikokkuvõtte järgi pannakse ilma olukorrale kõige sarnasem pilt.
        try:
            LabelO6 = Label(gui, text=translate(ilm["forecasts"][3]["day"]["text"], 'en', 'et'),
                            width=15).grid(row=11, column=5, sticky=W)
        except:
            pass

        # Tuule kiirus m/s.
        try:
            LabelX7 = Label(gui,
                            text=str(round((float(ilm["forecasts"][3]["day"]["wind"]["speed"])) / 3.6, 1)) + " m/s",
                            width=15).grid(row=12, column=5, sticky=W)  # Tuulekiirus
        except:
            pass

        # Tuule suund.
        try:
            LabelO8 = Label(gui, text=ilm["forecasts"][3]["day"]["wind"]["text"], width=15).grid(
                    row=13, column=5, sticky=W)  # Tuulesuund
        except:
            pass


        # Matplotlib


        f = Figure(figsize=(5, 4), dpi=100, facecolor="w")
        a = f.add_subplot(111)
        x = [1, 2, 3, 4, 5, 6]  # X - telje väärtused - *6 päeva, kuna matplotlib 5 päeva puhul ei suuda õigelt vormistada.

        #NB! Viimane päev on kahekordselt!
        y = [float(ilm["current_conditions"]["temperature"]),
             ((float(ilm["forecasts"][1]["low"]) + float(ilm["forecasts"][1]["high"])) / 2),
             ((float(ilm["forecasts"][2]["low"]) + float(ilm["forecasts"][2]["high"])) / 2),
             ((float(ilm["forecasts"][3]["low"]) + float(ilm["forecasts"][3]["high"])) / 2),
             ((float(ilm["forecasts"][4]["low"]) + float(ilm["forecasts"][4]["high"])) / 2),
             ((float(ilm["forecasts"][4]["low"]) + float(ilm["forecasts"][4]["high"])) / 2)]  # Keskmised temperatuurid.


        # X - telje väärtuste nimed on vastavad kuupäevad.
        Labels = [time.strftime("%b %d"),
                  ilm["forecasts"][1]["date"],
                  ilm["forecasts"][2]["date"],
                  ilm["forecasts"][3]["date"],
                  ilm["forecasts"][4]["date"]]

        # Graafiku joonistamine.
        a.plot(x, y)

        # Graafiku telgede pealkirjad ja joonise pealkiri.
        a.set_title(linn + ' 4 päeva prognoos')
        a.set_ylabel('Keskmine temperatuur °C')
        a.set_xlabel('Kuupäev')
        a.set_xticklabels(Labels)

        # Vormistamiseks, et mahuks tema jaoks loodud canvase piirdetesse.
        f.tight_layout()

        canvas = FigureCanvasTkAgg(f, master=gui)
        canvas.show()
        canvas.get_tk_widget().grid(row=0, column=2, rowspan=3, columnspan=4)
        canvas._tkcanvas.grid(row=0, column=2, rowspan=3, columnspan=4)

    # Olukorras, kus selle nimega asukohta ei eksisteeri. - Või suure vea korral.
    except:
        Label1 = Label(gui, text="Viga. Sisesta uuesti asukoht.", fg="red").grid(row=3, sticky=W + E,
                                                                                 columnspan=2)
    return
Ejemplo n.º 11
0
 def testBingTranslate(self):
     bingtrans.set_app_id(
         '5521E4A630094D968D49B39B6511A0A76CB025E1'
     )  # you can get your AppID at: http://www.bing.com/developers/
     result = bingtrans.translate("هذا هو الاختبار", 'ar', 'en')
     self.assertEqual("This is a test", result)
Ejemplo n.º 12
0
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bingtrans
import polib
import os,sys

BING_KEY = 'AE4F2D9144A988C235A23DF694F664D9357B2916'
languages = {"arabic": "ar", "czech": "cs","danish": "da",
"german": "de","english": "en","estonian": "et","finnish": "fi",
"french": "fr","dutch": "nl","greek": "el","hebrew": "he","hungarian": "hu","indonesian": "id",
"italian": "it","japanese": "ja","korean": "ko","lithuanian":"lt",
"latvian": "lv","norwegian": "no","polish": "pl","portuguese": "pt","romanian": "ro","spanish": "es","russian": "ru",
"slovak": "sk","slovene": "sl","swedish": "sv","thai": "th","turkish": "tr","ukranian": "uk","vietnamese": "vi","simplified chinese": "zh-CHS"} #,"traditional chinese": "zh-CHT"}

#languages = {"simplified chinese": "zh-CHS"}
bingtrans.set_app_id(BING_KEY)

for lang in languages.values():
    lang = lang[:2]
    ##return false;os.system("pybabel init -D musicfilmcomedy -i locale/musicfilmcomedy.pot -d locale/ -l "+lang)

    #return False
    po = polib.pofile('locale/%s/LC_MESSAGES/musicfilmcomedy.po' % lang)
    for a in po.untranslated_entries():
        print a.msgid
        a.msgstr = bingtrans.translate(a.msgid, 'en', lang if lang != 'zh' else 'zh-CHS').replace("% s", "%s")
        print a.msgstr
    po.save('locale/%s/LC_MESSAGES/musicfilmcomedy.po' % lang)
    po.save_as_mofile('locale/%s/LC_MESSAGES/musicfilmcomedy.mo' % lang)