Extract the translations into `.pot` files
197825
def _extract_translations(self, domains):
        """"""
        for domain, options in domains.items():
            # Create the extractor
            extractor = babel_frontend.extract_messages()
            extractor.initialize_options()
            # The temporary location to write the `.pot` file
            extractor.output_file = options['pot']
            # Add the comments marked with 'tn:' to the translation file for translators to read. Strip the marker.
            extractor.add_comments = ['tn:']
            extractor.strip_comments = True
            # The directory where the sources for this domain are located
            extractor.input_paths = [options['source']]
            # Pass the metadata to the translator
            extractor.msgid_bugs_address = self.manager.args.contact
            extractor.copyright_holder = self.manager.args.copyright
            extractor.version = self.manager.args.version
            extractor.project = self.manager.args.project
            extractor.finalize_options()
            # Add keywords for lazy translation functions, based on their non-lazy variants
            extractor.keywords.update({
                'gettext_lazy': extractor.keywords['gettext'],
                'ngettext_lazy': extractor.keywords['ngettext'],
                '__': extractor.keywords['gettext'],  # double underscore for lazy
            })
            # Do the extraction
            _run_babel_command(extractor)
977555
def translate(self, package, into=None):
    """"""
    if not package.local:
      raise ValueError('BinaryTranslator cannot translate remote packages.')
    if not isinstance(package, self._package_type):
      return None
    if not package.compatible(self._supported_tags):
      TRACER.log('Target package %s is not compatible with %s' % (
          package, self._supported_tags))
      return None
    into = into or safe_mkdtemp()
    target_path = os.path.join(into, package.filename)
    safe_copy(package.local_path, target_path)
    return DistributionHelper.distribution_from_path(target_path)
964421
def export_symbols(*path):
    
    lines = open(os.path.join(*path), 'r').readlines()[2:]
    return [s.strip() for s in lines if s.strip() != '']
79343
def _parse_programs(self, string, parent, filepath=None):
        """"""
        #First, get hold of the docstrings  for all the modules so that we can
        #attach them as we parse them.
        moddocs = self.docparser.parse_docs(string)
        #Now look for modules in the file and then match them to their decorators.
        matches = self.RE_PROGRAM.finditer(string)
        result = []
        for rmodule in matches:
            name = rmodule.group("name").lower()
            contents = re.sub("&[ ]*\n", "", rmodule.group("contents"))
            module = self._process_module(name, contents, parent, rmodule, filepath)
            #Check whether the docparser found docstrings for the module.
            if name in moddocs:                
                module.docstring = self.docparser.to_doc(moddocs[name][0], name)
                module.docstart, module.docend = module.absolute_charindex(string, moddocs[name][1],
                                                                           moddocs[name][2])
            result.append(module)
        return result
1093960
def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.talk=  _translate('MainWindow','You are using GeoPyTool ') + version +'\n'+ _translate('MainWindow','released on ') + date + '\n'

        self.menuFile.setTitle(_translate('MainWindow', u'Data File'))
        self.menuGeoChem.setTitle(_translate('MainWindow', u'Geochemistry'))
        self.menuGeoCalc.setTitle(_translate('MainWindow',u'Calculation'))
        self.menuStructure.setTitle(_translate('MainWindow', u'Structure'))
        self.menuSedimentary.setTitle(_translate('MainWindow', u'Sedimentary'))
        self.menuAdditional.setTitle(_translate('MainWindow', u'Additional Functions'))
        self.menuHelp.setTitle(_translate('MainWindow', u'Help'))
        self.menuLanguage.setTitle(_translate('MainWindow', u'Language'))


        self.actionCombine.setText(_translate('MainWindow', u'Combine'))
        self.actionCombine_transverse.setText(_translate('MainWindow', u'Combine_transverse'))

        self.actionFlatten.setText(_translate('MainWindow',u'Flatten'))

        self.actionTrans.setText(_translate('MainWindow',u'Trans'))

        self.actionReFormat.setText(_translate('MainWindow',u'ReFormat'))

        self.actionOpen.setText(_translate('MainWindow', u'Open Data'))
        self.actionClose.setText(_translate('MainWindow', u'Close Data'))
        self.actionSet.setText(_translate('MainWindow', u'Set Format'))
        self.actionSave.setText(_translate('MainWindow', u'Save Data'))
        self.actionQuit.setText(_translate('MainWindow', u'Quit App'))

        self.actionRemoveLOI.setText('1-0 '+_translate('MainWindow',u'Remove LOI'))
        self.actionAuto.setText('1-1 '+_translate('MainWindow', u'Auto'))
        self.actionTAS.setText('1-2 '+ _translate('MainWindow',u'TAS'))
        self.actionTrace.setText('1-3 '+_translate('MainWindow',u'Trace'))
        self.actionRee.setText('1-4 '+_translate('MainWindow',u'REE'))
        self.actionPearce.setText('1-5 '+_translate('MainWindow',u'Pearce'))
        self.actionHarker.setText('1-6 '+_translate('MainWindow',u'Harker'))
        self.actionCIPW.setText('1-7 '+_translate('MainWindow',u'CIPW'))
        self.actionQAPF.setText('1-8 '+_translate('MainWindow',u'QAPF'))
        self.actionSaccani.setText('1-9 '+_translate('MainWindow',u'Saccani Plot'))
        self.actionK2OSiO2.setText('1-10 '+_translate('MainWindow',u'K2O-SiO2'))
        self.actionRaman.setText('1-11 '+_translate('MainWindow',u'Raman Strength'))
        self.actionFluidInclusion.setText('1-12 '+_translate('MainWindow',u'Fluid Inclusion'))
        self.actionHarkerOld.setText('1-14 '+_translate('MainWindow',u'Harker Classical'))
        self.actionTraceNew.setText('1-15 '+_translate('MainWindow',u'TraceNew'))

        self.actionStereo.setText('2-1 '+_translate('MainWindow',u'Stereo'))
        self.actionRose.setText('2-2 '+_translate('MainWindow',u'Rose'))

        self.actionQFL.setText('3-1 '+_translate('MainWindow',u'QFL'))
        self.actionQmFLt.setText('3-2 '+_translate('MainWindow',u'QmFLt'))
        self.actionClastic.setText('3-3 '+_translate('MainWindow',u'Clastic'))
        self.actionCIA.setText('3-4 '+ _translate('MainWindow',u'CIA and ICV'))

        self.actionZirconCe.setText('4-1 '+ _translate('MainWindow',u'ZirconCe'))
        self.actionZirconCeOld.setText('4-2 '+ _translate('MainWindow', u'ZirconCeOld'))
        self.actionZirconTiTemp.setText('4-3 '+ _translate('MainWindow',u'ZirconTiTemp'))
        self.actionRutileZrTemp.setText('4-4 '+_translate('MainWindow',u'RutileZrTemp'))
        self.actionRbSrIsoTope.setText('4-5 '+_translate('MainWindow',u'Rb-Sr IsoTope'))
        self.actionSmNdIsoTope.setText('4-6 '+_translate('MainWindow',u'Sm-Nd IsoTope'))
        #self.actionKArIsoTope.setText(_translate('MainWindow',u'K-Ar IsoTope'))

        self.actionXY.setText('5-1 '+_translate('MainWindow',u'X-Y plot'))
        self.actionXYZ.setText('5-2 '+_translate('MainWindow',u'X-Y-Z plot'))
        self.actionCluster.setText('5-3 '+_translate('MainWindow',u'Cluster'))
        self.actionMultiDimension.setText('5-4 '+_translate('MainWindow',u'MultiDimension'))


        self.actionFA.setText('5-5 '+_translate('MainWindow',u'FA'))

        self.actionPCA.setText('5-6 '+_translate('MainWindow',u'PCA'))

        self.actionDist.setText('5-7 '+_translate('MainWindow',u'Distance'))

        self.actionStatistics.setText('5-8 '+_translate('MainWindow',u'Statistics'))


        self.actionThreeD.setText('5-9 '+_translate('MainWindow',u'ThreeD'))
        self.actionTwoD.setText('5-10 '+_translate('MainWindow',u'TwoD'))
        self.actionTwoD_Grey.setText('5-11 '+_translate('MainWindow',u'TwoD Grey'))

        self.actionMyHist.setText('5-12 '+_translate('MainWindow',u'Histogram + KDE Curve'))

        self.actionVersionCheck.setText(_translate('MainWindow', u'Check Update'))
        self.actionWeb.setText(_translate('MainWindow', u'English Forum'))
        self.actionGoGithub.setText(_translate('MainWindow', u'Github'))

        '''
        
        '''

        self.actionCnS.setText(u'简体中文')
        self.actionCnT.setText(u'繁體中文')
        self.actionEn.setText(u'English')
        self.actionLoadLanguage.setText(_translate('MainWindow',u'Load Language'))
395045
def translated(structure, values, lang_spec):
    """"""
    # LANGUAGE SPECS
    indentation = '\t'
    endline = '\n'


    object_code = ""
    stack = []
    # define shortcuts to behavior
    push = lambda x: stack.append(x)
    pop  = lambda  : stack.pop()
    last = lambda  : stack[-1] if len(stack) > 0 else ' '
    def indented_code(s, level, end):
        return lang_spec[INDENTATION]*level + s + end

    # recreate python structure, and replace type by value
    level = 0
    CONDITIONS = [LEXEM_TYPE_PREDICAT, LEXEM_TYPE_CONDITION]
    ACTION = LEXEM_TYPE_ACTION
    DOWNLEVEL = LEXEM_TYPE_DOWNLEVEL
    for lexem_type in structure:
        if lexem_type is ACTION:
            # place previous conditions if necessary
            if last() in CONDITIONS:
                # construct conditions lines
                value, values = values[0:len(stack)], values[len(stack):]
                object_code += (indented_code(lang_spec[BEG_CONDITION] 
                    + lang_spec[LOGICAL_AND].join(value) 
                    + lang_spec[END_CONDITION], 
                    level, 
                    lang_spec[END_LINE]
                ))
                # if provided, print the begin block token on a new line
                if len(lang_spec[BEG_BLOCK]) > 0:
                    object_code += indented_code( 
                        lang_spec[BEG_BLOCK],
                        level, 
                        lang_spec[END_LINE]
                    )
                stack = []
                level += 1
            # and place the action
            object_code += indented_code(
                lang_spec[BEG_ACTION] + values[0], 
                level, 
                lang_spec[END_ACTION]+lang_spec[END_LINE]
            )
            values = values[1:]
        elif lexem_type in CONDITIONS:
            push(lexem_type)
        elif lexem_type is DOWNLEVEL:
            if last() not in CONDITIONS:
                # down level, and add a END_BLOCK only if needed
                level -= 1
                if level >= 0:
                    object_code += indented_code(
                        lang_spec[END_BLOCK], level,
                        lang_spec[END_LINE]
                    )
                else:
                    level = 0

    # add END_BLOCK while needed for reach level 0
    while level > 0:
        level -= 1
        if level >= 0:
            object_code += indented_code(
                lang_spec[END_BLOCK], level,
                lang_spec[END_LINE]
            )
        else:
            level = 0
    # Finished !
    return object_code
482608
def extract_chm (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return [cmd, os.path.abspath(archive), outdir]
519915
private function gatherTranslatableStrings()
    {
        $this->translatables = [];

        $this->scanTwigFiles();
        $this->scanPhpFiles();

        ksort($this->translatables);
    }
699829
def translate_book(translators=(HyperlinkStyleCorrector().translate, translate_line_footnotes),
                   book_dir=BOOK_PATH, dest=None, include_tags=None,
                   ext='.nlpiabak', skip_untitled=True):
    
    if callable(translators) or not hasattr(translators, '__len__'):
        translators = (translators,)

    sections = get_tagged_sections(book_dir=book_dir, include_tags=include_tags)
    file_line_maps = []

    for fileid, (filepath, tagged_lines) in enumerate(sections):
        logger.info('filepath={}'.format(filepath))
        destpath = filepath
        if not dest:
            copyfile(filepath, filepath + '.' + ext.lstrip('.'))
        elif os.path.sep in dest:
            destpath = os.path.join(dest, os.path.basename(filepath))
        else:
            destpath = os.path.join(os.path.dirname(filepath), dest, os.path.basename(filepath))
        ensure_dir_exists(os.path.dirname(destpath))
        with open(destpath, 'w') as fout:
            logger.info('destpath={}'.format(destpath))
            for lineno, (tag, line) in enumerate(tagged_lines):
                if (include_tags is None or tag in include_tags or
                        any((tag.startswith(t) for t in include_tags))):
                    for translate in translators:
                        new_line = translate(line)  # TODO: be smarter about writing to files in-place
                        if line != new_line:
                            file_line_maps.append((fileid, lineno, filepath, destpath, line, new_line))
                            line = new_line
                fout.write(line)
    return file_line_maps
751949
def clean_readme(fname):
    """"""
    with codecs.open(fname, 'r', 'utf-8') as f:
        return ''.join(
            re.sub(r':\w+:`([^`]+?)( <[^<>]+>)?`', r'``\1``', line)
            for line in f
            if not (line.startswith('.. currentmodule') or line.startswith('.. toctree'))
        )
1310476
def get_valid_commands():
    
    modules = [m.basename().split('.')[0] for m in Path(__file__).dirname().files('*.py')]
    commands = []
    for modname in modules:
        if modname == 'main':
            continue
        mod = importlib.import_module('i18n.%s' % modname)
        if hasattr(mod, 'main'):
            commands.append(modname)
    return commands
328229
def iter_format_modules(lang):
    
    if check_for_language(lang):
        format_locations = []
        for path in CUSTOM_FORMAT_MODULE_PATHS:
            format_locations.append(path + '.%s')
        format_locations.append('django.conf.locale.%s')
        locale = to_locale(lang)
        locales = [locale]
        if '_' in locale:
            locales.append(locale.split('_')[0])
        for location in format_locations:
            for loc in locales:
                try:
                    yield import_module('.formats', location % loc)
                except ImportError:
                    pass
295525
def lazy_translations(cls):
        """"""
        return {
            cloudfiles.errors.NoSuchContainer: errors.NoContainerException,
            cloudfiles.errors.NoSuchObject: errors.NoObjectException,
        }
451446
def to_array(self):
        
        stepdef = {'keep': self._keep,
                   'language': self._language,
                   'arg': self._arg}

        if self._language == 'javascript':
            if isinstance(self._function, list):
                stepdef['bucket'] = self._function[0]
                stepdef['key'] = self._function[1]
            elif isinstance(self._function, string_types):
                if ("{" in self._function):
                    stepdef['source'] = self._function
                else:
                    stepdef['name'] = self._function

        elif (self._language == 'erlang' and isinstance(self._function, list)):
            stepdef['module'] = self._function[0]
            stepdef['function'] = self._function[1]

        elif (self._language == 'erlang' and
              isinstance(self._function, string_types)):
            stepdef['source'] = self._function

        return {self._type: stepdef}
645512
def get_module_imports_on_top_of_file(source, import_line_index):
    
    def is_string_literal(line):
        if line[0] in 'uUbB':
            line = line[1:]
        if line and line[0] in 'rR':
            line = line[1:]
        return line and (line[0] == '"' or line[0] == "'")

    def is_future_import(line):
        nodes = ast.parse(line)
        for n in nodes.body:
            if isinstance(n, ast.ImportFrom) and n.module == '__future__':
                return True
        return False

    allowed_try_keywords = ('try', 'except', 'else', 'finally')
    in_docstring = False
    docstring_kind = '"""'
    for cnt, line in enumerate(source):
        if not in_docstring:
            m = DOCSTRING_START_REGEX.match(line.lstrip())
            if m is not None:
                in_docstring = True
                docstring_kind = m.group('kind')
                remain = line[m.end(): m.endpos].rstrip()
                if remain[-3:] == docstring_kind:  # one line doc
                    in_docstring = False
                continue
        if in_docstring:
            if line.rstrip()[-3:] == docstring_kind:
                in_docstring = False
            continue

        if not line.rstrip():
            continue
        elif line.startswith('#'):
            continue

        if line.startswith('import ') or line.startswith('from '):
            if cnt == import_line_index or is_future_import(line):
                continue
            return cnt
        elif pycodestyle.DUNDER_REGEX.match(line):
            continue
        elif any(line.startswith(kw) for kw in allowed_try_keywords):
            continue
        elif is_string_literal(line):
            return cnt
        else:
            return cnt
    return 0
94108
def _get_translate():
    
    translate = {}
    model_path = pkg_resources.resource_filename('hwrt', 'misc/')
    translation_csv = os.path.join(model_path, 'latex2writemathindex.csv')
    arguments = {'newline': '', 'encoding': 'utf8'}
    with open(translation_csv, 'rt', **arguments) as csvfile:
        contents = csvfile.read()
    lines = contents.split("\n")
    for csvrow in lines:
        csvrow = csvrow.split(',')
        if len(csvrow) == 1:
            writemathid = csvrow[0]
            latex = ""
        else:
            writemathid, latex = csvrow[0], csvrow[1:]
            latex = ','.join(latex)
        translate[latex] = writemathid
    return translate
334691
def main():
    """"""

    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('source', help="location of the downloaded repos")
    parser.add_argument('destination', help="location of the extracted files")
    parser.add_argument(
        '-t', '--nb-test-files', help="number of testing files per language",
        type=int, default=5000)
    parser.add_argument(
        '-l', '--nb-learn-files', help="number of learning files per language",
        type=int, default=10000)
    parser.add_argument(
        '-r', '--remove', help="remove repos that cannot be read",
        action='store_true', default=False)
    parser.add_argument(
        '-d', '--debug', default=False, action='store_true',
        help="show debug messages")

    args = parser.parse_args()
    config_logging(args.debug)

    source = Path(args.source)
    destination = Path(args.destination)
    nb_test = args.nb_test_files
    nb_learn = args.nb_learn_files
    remove = args.remove

    repos = _find_repos(source)
    split_repos = _split_repos(repos, nb_test, nb_learn)
    split_files = _find_files(*split_repos, nb_test, nb_learn, remove)
    _unzip_all(*split_files, destination)
    LOGGER.info("Files saved into %s", destination)
    LOGGER.debug("Exit OK")