How to use the googletrans.constants.LANGCODES function in googletrans

To help you get started, we’ve selected a few googletrans examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github michaeldegroot / cats-blender-plugin / googletrans / client.py View on Github external
dest = dest.lower().split('_', 1)[0]
        src = src.lower().split('_', 1)[0]

        if src != 'auto' and src not in LANGUAGES:
            if src in SPECIAL_CASES:
                src = SPECIAL_CASES[src]
            elif src in LANGCODES:
                src = LANGCODES[src]
            else:
                raise ValueError('invalid source language')

        if dest not in LANGUAGES:
            if dest in SPECIAL_CASES:
                dest = SPECIAL_CASES[dest]
            elif dest in LANGCODES:
                dest = LANGCODES[dest]
            else:
                raise ValueError('invalid destination language')

        if isinstance(text, list):
            wm = bpy.context.window_manager
            current_step = 0
            wm.progress_begin(current_step, len(text))

            result = []
            for item in text:
                translated = self.translate(item, dest=dest, src=src)
                result.append(translated)
                current_step += 1
                wm.progress_update(current_step)
            wm.progress_end()
            return result
github suliveevil / AppleScript / App-BetterAndBetter / BAB-PopClip / PopClipExtensions / googletranslate.popclipext / googletrans / client.py View on Github external
"""
        dest = dest.lower().split('_', 1)[0]
        src = src.lower().split('_', 1)[0]

        if src != 'auto' and src not in LANGUAGES:
            if src in SPECIAL_CASES:
                src = SPECIAL_CASES[src]
            elif src in LANGCODES:
                src = LANGCODES[src]
            else:
                raise ValueError('invalid source language')

        if dest not in LANGUAGES:
            if dest in SPECIAL_CASES:
                dest = SPECIAL_CASES[dest]
            elif dest in LANGCODES:
                dest = LANGCODES[dest]
            else:
                raise ValueError('invalid destination language')

        if isinstance(text, list):
            result = []
            for item in text:
                translated = self.translate(item, dest=dest, src=src)
                result.append(translated)
            return result

        origin = text
        data = self._translate(text, dest, src)

        # this code will be updated when the format is changed.
        translated = ''.join([d[0] if d[0] else '' for d in data[0]])
github ssut / py-googletrans / googletrans / client.py View on Github external
Advanced usage:
            >>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
            >>> for translation in translations:
            ...    print(translation.origin, ' -> ', translation.text)
            The quick brown fox  ->  빠른 갈색 여우
            jumps over  ->  이상 점프
            the lazy dog  ->  게으른 개
        """
        dest = dest.lower().split('_', 1)[0]
        src = src.lower().split('_', 1)[0]

        if src != 'auto' and src not in LANGUAGES:
            if src in SPECIAL_CASES:
                src = SPECIAL_CASES[src]
            elif src in LANGCODES:
                src = LANGCODES[src]
            else:
                raise ValueError('invalid source language')

        if dest not in LANGUAGES:
            if dest in SPECIAL_CASES:
                dest = SPECIAL_CASES[dest]
            elif dest in LANGCODES:
                dest = LANGCODES[dest]
            else:
                raise ValueError('invalid destination language')

        if isinstance(text, list):
            result = []
            for item in text:
                translated = self.translate(item, dest=dest, src=src)
github sukeesh / Jarvis / jarviscli / plugins / translate.py View on Github external
"""
    Default function that is called when translate is entered alone or
    when input is not understood when translate is entered with additional parameters
    """
#   Get source language
    jarvis.say('\nEnter source language ')
    srcs = jarvis.input().lower().strip()
#   Check source language
    while (
        srcs not in LANGUAGES) and (
        srcs not in SPECIAL_CASES) and (
            srcs not in LANGCODES):
        if srcs in SPECIAL_CASES:
            srcs = SPECIAL_CASES[srcs]
        elif srcs in LANGCODES:
            srcs = LANGCODES[srcs]
        else:
            jarvis.say("\nInvalid source language\nEnter again")
            srcs = jarvis.input().lower()
#   Get destination language
    jarvis.say('\nEnter destination language ')
    des = jarvis.input().lower().strip()
#   Check destination language
    while (
        des not in LANGUAGES) and (
        des not in SPECIAL_CASES) and (
            des not in LANGCODES):
        if des in SPECIAL_CASES:
            des = SPECIAL_CASES[des]
        elif des in LANGCODES:
            des = LANGCODES[des]
        else:
github kokimame / joytan / gui / translate.py View on Github external
def _ui(self):
        self.form = gui.forms.translate.Ui_TranslateDialog()
        self.form.setupUi(self)
        # Setup combo box for languages
        self.form.langCombo.addItems(sorted([lang.title() for lang in LANGCODES.keys()]))
        self.form.langCombo.setCurrentText("Japanese")
        self.form.cancelBtn.clicked.connect(self._thread_stop)
        self.form.startBtn.clicked.connect(self._translate)

        _list = self.form.keyList
        # Add checkbox corresponding to each ewkey of Entry
        for ewkey in self.mw.entrylist.get_config('ewkeys'):
            check = QCheckBox(ewkey)
            lwi = QListWidgetItem()
            lwi.setSizeHint(check.sizeHint())
            _list.addItem(lwi)
            _list.setItemWidget(lwi, check)
github kokimame / joytan / gui / translate.py View on Github external
def _translate(self):
        if self.mw.entrylist.count() == 0:
            showCritical("No entries found in your entry list.", title="Error")
            return

        ewkeys = []
        # Get language code of target language to translate to from the library
        destcode = LANGCODES[self.form.langCombo.currentText().lower()]
        # Check which section to translate
        _list = self.form.keyList
        for i in range(_list.count()):
            ch = _list.itemWidget(_list.item(i))
            if ch.isChecked():
                ewkeys.append(ch.text())

        if self.form.onlyCheck.isChecked():
            targets = self.mw.entrylist.get_entry_selected()
        else:
            targets = self.mw.entrylist.get_entry_all()
        self.form.progressBar.setRange(0, len(targets))

        def _on_progress(name):
            self.form.pgMsg.setText("Translating %s." % name)
            val = self.form.progressBar.value()