示例#1
0
    def gettargetlanguage(self):
        """Return the target language based on information in the header.

        The target language is determined in the following sequence:
          1. Use the 'Language' entry in the header.
          2. Poedit's custom headers.
          3. Analysing the 'Language-Team' entry.
        """
        header = self.parseheader()
        lang = header.get('Language', None)
        if lang is not None:
            from translate.lang.data import langcode_ire
            if langcode_ire.match(lang):
                return lang
            else:
                lang = None
        if 'X-Poedit-Language' in header:
            from translate.lang import poedit
            language = header.get('X-Poedit-Language')
            country = header.get('X-Poedit-Country')
            return poedit.isocode(language, country)
        if 'Language-Code' in header:  # Used in Plone files
            return header.get('Language-Code')
        if 'Language-Team' in header:
            from translate.lang.team import guess_language
            return guess_language(header.get('Language-Team'))
        return None
示例#2
0
    def gettargetlanguage(self):
        """Return the target language based on information in the header.

        The target language is determined in the following sequence:
          1. Use the 'Language' entry in the header.
          2. Poedit's custom headers.
          3. Analysing the 'Language-Team' entry.
        """
        header = self.parseheader()
        lang = header.get('Language', None)
        if lang is not None:
            from translate.lang.data import langcode_ire
            if langcode_ire.match(lang):
                return lang
            else:
                lang = None
        if 'X-Poedit-Language' in header:
            from translate.lang import poedit
            language = header.get('X-Poedit-Language')
            country = header.get('X-Poedit-Country')
            return poedit.isocode(language, country)
        if 'Language-Code' in header:  # Used in Plone files
            return header.get('Language-Code')
        if 'Language-Team' in header:
            from translate.lang.team import guess_language
            return guess_language(header.get('Language-Team'))
        return None
示例#3
0
    def handlefile(self, filename, verbose):
        if verbose:
            print("Importing %s" % filename)

        try:
            store = factory.getobject(filename)
            source_lang = self.source_lang or store.getsourcelanguage()
            target_lang = self.target_lang or store.gettargetlanguage()
            project_style = self.project_style or store.getprojectstyle()

            if not target_lang:
                short = os.path.splitext(os.path.split(filename)[1])[0]
                if langcode_ire.match(short):
                    target_lang = short
                else:
                    long, short = os.path.split(os.path.split(filename)[0])
                    if langcode_ire.match(short) and short not in ('po', 'www', 'gtk'):
                        target_lang = short
                    else:
                        short = os.path.split(long)[1]
                        if langcode_ire.match(short) and short not in ('po', 'www', 'gtk'):
                            detected = LanguageIdentifier().identify_target_lang(store.units)
                            if short == detected:
                                target_lang = short
                                print('Guessing language "%s" for %s' % (short, filename))

            if not source_lang or not target_lang:
                logging.error("Missing source or target language. Won't "
                              "import %s", filename)
                return
        except ValueError as e:
            if "Unknown filetype" not in str(e):
                logging.exception("Error while handling: %s", filename)
            return
        except Exception:
            logging.exception("Error while processing: %s", filename)
            return

        # Do something useful with the store and the database.
        try:
            logging.info("Importing strings from: %s", filename)
            current_app.tmdb.add_store(store, source_lang, target_lang,
                                       project_style, commit=True)
        except Exception:
            logging.exception("Error importing strings from: %s", filename)
            raise
示例#4
0
文件: commands.py 项目: viperfx/GSOC
    def handlefile(self, filename, verbose):
        if verbose:
            print("Importing %s" % filename)

        try:
            store = factory.getobject(filename)
            source_lang = self.source_lang or store.getsourcelanguage()
            target_lang = self.target_lang or store.gettargetlanguage()
            project_style = self.project_style or store.getprojectstyle()

            if not target_lang:
                short = os.path.splitext(os.path.split(filename)[1])[0]
                if langcode_ire.match(short):
                    target_lang = short
                else:
                    short = os.path.split(os.path.split(filename)[0])[1]
                    if langcode_ire.match(short) and short != 'po':
                        target_lang = short

            if not source_lang or not target_lang:
                logging.error("Missing source or target language. Won't "
                              "import %s" % filename)
                return
        except ValueError as e:
            if not "Unknown filetype" in str(e):
                logging.exception("Error while handling: %s" % filename)
            return
        except Exception:
            logging.exception("Error while processing: %s" % filename)
            return

        # Do something useful with the store and the database.
        try:
            logging.info("Importing strings from: %s" % filename)
            current_app.tmdb.add_store(store, source_lang, target_lang,
                                       project_style, commit=True)
        except Exception:
            logging.exception("Error importing strings from: %s" % filename)
            raise
示例#5
0
    def handlefile(self, filename):
        try:
            store = factory.getobject(filename)
            source_lang = self.source_lang or store.getsourcelanguage()
            target_lang = self.target_lang or store.gettargetlanguage()
            project_style = self.project_style or store.getprojectstyle()

            if not target_lang:
                short = os.path.splitext(os.path.split(filename)[1])[0]
                if langcode_ire.match(short):
                    target_lang = short
                else:
                    short = os.path.split(os.path.split(filename)[0])[1]
                    if langcode_ire.match(short) and short != 'po':
                        target_lang = short

            if not source_lang or not target_lang:
                logging.error("Missing source or target language. Won't "
                              "import %s" % filename)
                return
        except ValueError as e:
            if not "Unknown filetype" in str(e):
                logging.exception("Error while handling: %s" % filename)
            return
        except Exception:
            logging.exception("Error while processing: %s" % filename)
            return

        # Do something useful with the store and the database.
        try:
            logging.info("Importing strings from: %s" % filename)
            current_app.tmdb.add_store(store,
                                       source_lang,
                                       target_lang,
                                       project_style,
                                       commit=True)
        except Exception:
            logging.exception("Error importing strings from: %s" % filename)
            raise
示例#6
0
    def handlefile(self, filename):
        try:
            store = factory.getobject(filename)
            source_lang = self.source_lang or store.getsourcelanguage()
            target_lang = self.target_lang or store.gettargetlanguage()
            project_style = self.project_style or store.getprojectstyle()

            if not target_lang:
               short = os.path.splitext(os.path.split(filename)[1])[0]
               if langcode_ire.match(short):
                   target_lang = short
               else:
                   short = os.path.split(os.path.split(filename)[0])[1]
                   if langcode_ire.match(short) and short != 'po':
                       target_lang = short

            if not source_lang or not target_lang:
                print >> sys.stderr, "Missing source or target language. Won't import", filename
                return
        except ValueError, e:
            if not "Unknown filetype" in str(e):
                print >> sys.stderr, str(e)
            return
示例#7
0
    def handlefile(self, filename):
        try:
            store = factory.getobject(filename)
            source_lang = self.source_lang or store.getsourcelanguage()
            target_lang = self.target_lang or store.gettargetlanguage()
            project_style = self.project_style or store.getprojectstyle()

            if not target_lang:
                short = os.path.splitext(os.path.split(filename)[1])[0]
                if langcode_ire.match(short):
                    target_lang = short
                else:
                    short = os.path.split(os.path.split(filename)[0])[1]
                    if langcode_ire.match(short) and short != 'po':
                        target_lang = short

            if not source_lang or not target_lang:
                print >> sys.stderr, "Missing source or target language. Won't import", filename
                return
        except ValueError, e:
            if not "Unknown filetype" in str(e):
                print >> sys.stderr, str(e)
            return