Esempio n. 1
0
def i18n(ctx, update=False):
    '''Extract translatable strings'''
    header('Extract translatable strings')

    info('Extract Python strings')
    lrun('python setup.py extract_messages')
    if update:
        lrun('python setup.py update_catalog')

    info('Extract JavaScript strings')
    keys = set()
    catalog = {}
    catalog_filename = join(ROOT, 'js', 'locales',
                            '{}.en.json'.format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding='utf8') as f:
            catalog = json.load(f)

    globs = '*.js', '*.vue', '*.hbs'
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'
                   ),  # JS _('trad')
        re.compile(r'v-i18n="(.*?)"'),  # Vue.js directive v-i18n="trad"
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'
                   ),  # Vue.js filter {{ 'trad'|i18n }}
        re.compile(r'{{_\s*"(.*?)"\s*}}'),  # Handlebars {{_ "trad" }}
        re.compile(r'{{_\s*\'(.*?)\'\s*}}'),  # Handlebars {{_ 'trad' }}
        re.compile(r'\:[a-z0-9_\-]+="\s*_\(\'(.*?)\'\)\s*"'
                   ),  # Vue.js binding :prop="_('trad')"
    ]

    for directory, _, _ in os.walk(join(ROOT, 'js')):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print('Extracting messages from {0}'.format(green(filename)))
            content = codecs.open(filename, encoding='utf8').read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    key = key.replace('\\n', '\n')
                    keys.add(key)
                    if key not in catalog:
                        catalog[key] = key

    # Remove old/not found translations
    for key in catalog.keys():
        if key not in keys:
            del catalog[key]

    with codecs.open(catalog_filename, 'w', encoding='utf8') as f:
        json.dump(catalog,
                  f,
                  sort_keys=True,
                  indent=4,
                  ensure_ascii=False,
                  encoding='utf8',
                  separators=(',', ': '))
Esempio n. 2
0
def qa(ctx):
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata --jobs 1', pty=True, warn=True)
    info('JavaScript static analysis')
    eslint_results = lrun('npm -s run lint', pty=True, warn=True)
    if flake8_results.failed or eslint_results.failed:
        exit(flake8_results.return_code or eslint_results.return_code)
    print(green('OK'))
Esempio n. 3
0
def qa():
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata', pty=True, warn=True)
    info('JavaScript static analysis')
    eslint_results = nrun('eslint js/ --ext .vue,.js', pty=True, warn=True)
    if flake8_results.failed or eslint_results.failed:
        exit(flake8_results.return_code or eslint_results.return_code)
    print(green('OK'))
Esempio n. 4
0
def qa():
    """Run a quality report"""
    header("Performing static analysis")
    info("Python static analysis")
    flake8_results = lrun("flake8 udata --jobs 1", pty=True, warn=True)
    info("JavaScript static analysis")
    eslint_results = lrun("npm -s run lint", pty=True, warn=True)
    if flake8_results.failed or eslint_results.failed:
        exit(flake8_results.return_code or eslint_results.return_code)
    print(green("OK"))
Esempio n. 5
0
def qa(ctx):
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata --jobs 1', pty=True, warn=True)
    info('JavaScript static analysis')
    eslint_results = lrun('npm -s run lint', pty=True, warn=True)
    if flake8_results.failed or eslint_results.failed:
        exit(flake8_results.return_code or eslint_results.return_code)
    print(green('OK'))
Esempio n. 6
0
def qa():
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata', warn=True)
    info('JavaScript static analysis')
    jshint_results = nrun('jshint js --extra-ext=.vue --extract=auto', warn=True)
    if flake8_results.failed or jshint_results.failed:
        exit(flake8_results.return_code or jshint_results.return_code)
    print(green('OK'))
Esempio n. 7
0
def qa():
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata', pty=True, warn=True)
    info('JavaScript static analysis')
    eslint_results = nrun('eslint js/ --ext .vue,.js', pty=True, warn=True)
    if flake8_results.failed or eslint_results.failed:
        exit(flake8_results.return_code or eslint_results.return_code)
    print(green('OK'))
Esempio n. 8
0
def qa():
    '''Run a quality report'''
    header('Performing static analysis')
    info('Python static analysis')
    flake8_results = lrun('flake8 udata', warn=True)
    info('JavaScript static analysis')
    jshint_results = nrun('jshint js --extra-ext=.vue --extract=auto',
                          warn=True)
    if flake8_results.failed or jshint_results.failed:
        exit(flake8_results.return_code or jshint_results.return_code)
    print(green('OK'))
Esempio n. 9
0
def i18n():
    '''Extract translatable strings'''
    header('Extract translatable strings')

    info('Extract Python strings')
    lrun('python setup.py extract_messages')
    lrun('python setup.py update_catalog')

    info('Extract JavaScript strings')
    keys = []
    catalog = {}
    catalog_filename = join(ROOT, 'js', 'locales',
                            '{}.en.json'.format(I18N_DOMAIN))
    not_found = {}
    not_found_filename = join(ROOT, 'js', 'locales',
                            '{}.notfound.json'.format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding='utf8') as f:
            catalog = json.load(f)

    globs = '*.js', '*.vue', '*.hbs'
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'),
        # re.compile(r'this\._\(\s*(?:"|\')(.*?)(?:"|\')\s*\)'),
        re.compile(r'v-i18n="(.*?)"'),
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'),
        re.compile(r'{{_\s*"(.*?)"\s*}}'),
        re.compile(r'{{_\s*\'(.*?)\'\s*}}'),
    ]

    for directory, _, _ in os.walk(join(ROOT, 'js')):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print('Extracting messages from {0}'.format(green(filename)))
            content = codecs.open(filename, encoding='utf8').read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    keys.append(key)
                    if key not in catalog:
                        catalog[key] = key

    with codecs.open(catalog_filename, 'w', encoding='utf8') as f:
        json.dump(catalog, f, sort_keys=True, indent=4, ensure_ascii=False,
                  encoding='utf8', separators=(',', ': '))

    for key, value in catalog.items():
        if key not in keys:
            not_found[key] = value

    with codecs.open(not_found_filename, 'w', encoding='utf8') as f:
        json.dump(not_found, f, sort_keys=True, indent=4, ensure_ascii=False,
                  encoding='utf8', separators=(',', ': '))
Esempio n. 10
0
def i18n():
    '''Extract translatable strings'''
    header('Extract translatable strings')

    info('Extract Python strings')
    lrun('python setup.py extract_messages')
    lrun('python setup.py update_catalog')

    info('Extract JavaScript strings')
    keys = []
    catalog = {}
    catalog_filename = join(ROOT, 'js', 'locales',
                            '{}.en.json'.format(I18N_DOMAIN))
    not_found = {}
    not_found_filename = join(ROOT, 'js', 'locales',
                            '{}.notfound.json'.format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding='utf8') as f:
            catalog = json.load(f)

    globs = '*.js', '*.vue', '*.hbs'
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'),
        # re.compile(r'this\._\(\s*(?:"|\')(.*?)(?:"|\')\s*\)'),
        re.compile(r'v-i18n="(.*?)"'),
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'),
        re.compile(r'{{_\s*"(.*?)"\s*}}'),
        re.compile(r'{{_\s*\'(.*?)\'\s*}}'),
    ]

    for directory, _, _ in os.walk(join(ROOT, 'js')):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print('Extracting messages from {0}'.format(green(filename)))
            content = codecs.open(filename, encoding='utf8').read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    keys.append(key)
                    if key not in catalog:
                        catalog[key] = key

    with codecs.open(catalog_filename, 'w', encoding='utf8') as f:
        json.dump(catalog, f, sort_keys=True, indent=4, ensure_ascii=False,
                  encoding='utf8', separators=(',', ': '))

    for key, value in catalog.items():
        if key not in keys:
            not_found[key] = value

    with codecs.open(not_found_filename, 'w', encoding='utf8') as f:
        json.dump(not_found, f, sort_keys=True, indent=4, ensure_ascii=False,
                  encoding='utf8', separators=(',', ': '))
Esempio n. 11
0
def i18n():
    """Extract translatable strings"""
    header("Extract translatable strings")

    info("Extract Python strings")
    lrun("python setup.py extract_messages")
    lrun("python setup.py update_catalog")

    info("Extract JavaScript strings")
    keys = []
    catalog = {}
    catalog_filename = join(ROOT, "js", "locales", "{}.en.json".format(I18N_DOMAIN))
    not_found = {}
    not_found_filename = join(ROOT, "js", "locales", "{}.notfound.json".format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding="utf8") as f:
            catalog = json.load(f)

    globs = "*.js", "*.vue", "*.hbs"
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'),  # JS _('trad')
        re.compile(r'v-i18n="(.*?)"'),  # Vue.js directive v-i18n="trad"
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'),  # Vue.js filter {{ 'trad'|i18n }}
        re.compile(r'{{_\s*"(.*?)"\s*}}'),  # Handlebars {{_ "trad" }}
        re.compile(r"{{_\s*\'(.*?)\'\s*}}"),  # Handlebars {{_ 'trad' }}
        re.compile(r'\:[a-z0-9_\-]+="\s*_\(\'(.*?)\'\)\s*"'),  # Vue.js binding :prop="_('trad')"
    ]

    for directory, _, _ in os.walk(join(ROOT, "js")):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print("Extracting messages from {0}".format(green(filename)))
            content = codecs.open(filename, encoding="utf8").read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    keys.append(key)
                    if key not in catalog:
                        catalog[key] = key

    with codecs.open(catalog_filename, "w", encoding="utf8") as f:
        json.dump(catalog, f, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf8", separators=(",", ": "))

    for key, value in catalog.items():
        if key not in keys:
            not_found[key] = value

    with codecs.open(not_found_filename, "w", encoding="utf8") as f:
        json.dump(not_found, f, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf8", separators=(",", ": "))
Esempio n. 12
0
def i18n(ctx, update=False):
    '''Extract translatable strings'''
    header('Extract translatable strings')

    info('Extract Python strings')
    lrun('python setup.py extract_messages')

    # Fix crowdin requiring Language with `2-digit` iso code in potfile
    # to produce 2-digit iso code pofile
    # Opening the catalog also allows to set extra metadata
    potfile = join(ROOT, 'udata', 'translations', '{}.pot'.format(I18N_DOMAIN))
    with open(potfile, 'rb') as infile:
        catalog = read_po(infile, 'en')
    catalog.copyright_holder = 'Open Data Team'
    catalog.msgid_bugs_address = '*****@*****.**'
    catalog.language_team = 'Open Data Team <*****@*****.**>'
    catalog.last_translator = 'Open Data Team <*****@*****.**>'
    catalog.revision_date = datetime.now(LOCALTZ)
    with open(potfile, 'wb') as outfile:
        write_po(outfile, catalog, width=80)

    if update:
        lrun('python setup.py update_catalog')

    info('Extract JavaScript strings')
    keys = set()
    catalog = {}
    catalog_filename = join(ROOT, 'js', 'locales',
                            '{}.en.json'.format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding='utf8') as f:
            catalog = json.load(f)

    globs = '*.js', '*.vue', '*.hbs'
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'
                   ),  # JS _('trad')
        re.compile(r'v-i18n="(.*?)"'),  # Vue.js directive v-i18n="trad"
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'
                   ),  # Vue.js filter {{ 'trad'|i18n }}
        re.compile(r'{{_\s*"(.*?)"\s*}}'),  # Handlebars {{_ "trad" }}
        re.compile(r'{{_\s*\'(.*?)\'\s*}}'),  # Handlebars {{_ 'trad' }}
        re.compile(r'\:[a-z0-9_\-]+="\s*_\(\'(.*?)\'\)\s*"'
                   ),  # Vue.js binding :prop="_('trad')"
    ]

    for directory, _, _ in os.walk(join(ROOT, 'js')):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print('Extracting messages from {0}'.format(green(filename)))
            content = codecs.open(filename, encoding='utf8').read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    key = key.replace('\\n', '\n')
                    keys.add(key)
                    if key not in catalog:
                        catalog[key] = key

    # Remove old/not found translations
    for key in catalog.keys():
        if key not in keys:
            del catalog[key]

    with codecs.open(catalog_filename, 'w', encoding='utf8') as f:
        json.dump(catalog,
                  f,
                  sort_keys=True,
                  indent=4,
                  ensure_ascii=False,
                  encoding='utf8',
                  separators=(',', ': '))
Esempio n. 13
0
def i18n(ctx, update=False):
    '''Extract translatable strings'''
    header('Extract translatable strings')

    info('Extract Python strings')
    lrun('python setup.py extract_messages')

    # Fix crowdin requiring Language with `2-digit` iso code in potfile
    # to produce 2-digit iso code pofile
    # Opening the catalog also allows to set extra metadata
    potfile = join(ROOT, 'udata', 'translations', '{}.pot'.format(I18N_DOMAIN))
    with open(potfile, 'rb') as infile:
        catalog = read_po(infile, 'en')
    catalog.copyright_holder = 'Open Data Team'
    catalog.msgid_bugs_address = '*****@*****.**'
    catalog.language_team = 'Open Data Team <*****@*****.**>'
    catalog.last_translator = 'Open Data Team <*****@*****.**>'
    catalog.revision_date = datetime.now(LOCALTZ)
    with open(potfile, 'wb') as outfile:
        write_po(outfile, catalog, width=80)

    if update:
        lrun('python setup.py update_catalog')

    info('Extract JavaScript strings')
    keys = set()
    catalog = {}
    catalog_filename = join(ROOT, 'js', 'locales',
                            '{}.en.json'.format(I18N_DOMAIN))
    if exists(catalog_filename):
        with codecs.open(catalog_filename, encoding='utf8') as f:
            catalog = json.load(f)

    globs = '*.js', '*.vue', '*.hbs'
    regexps = [
        re.compile(r'(?:|\.|\s|\{)_\(\s*(?:"|\')(.*?)(?:"|\')\s*(?:\)|,)'),  # JS _('trad')
        re.compile(r'v-i18n="(.*?)"'),  # Vue.js directive v-i18n="trad"
        re.compile(r'"\{\{\{?\s*\'(.*?)\'\s*\|\s*i18n\}\}\}?"'),  # Vue.js filter {{ 'trad'|i18n }}
        re.compile(r'{{_\s*"(.*?)"\s*}}'),  # Handlebars {{_ "trad" }}
        re.compile(r'{{_\s*\'(.*?)\'\s*}}'),  # Handlebars {{_ 'trad' }}
        re.compile(r'\:[a-z0-9_\-]+="\s*_\(\'(.*?)\'\)\s*"'),  # Vue.js binding :prop="_('trad')"
    ]

    for directory, _, _ in os.walk(join(ROOT, 'js')):
        glob_patterns = (iglob(join(directory, g)) for g in globs)
        for filename in itertools.chain(*glob_patterns):
            print('Extracting messages from {0}'.format(green(filename)))
            content = codecs.open(filename, encoding='utf8').read()
            for regexp in regexps:
                for match in regexp.finditer(content):
                    key = match.group(1)
                    key = key.replace('\\n', '\n')
                    keys.add(key)
                    if key not in catalog:
                        catalog[key] = key

    # Remove old/not found translations
    for key in catalog.keys():
        if key not in keys:
            del catalog[key]

    with codecs.open(catalog_filename, 'w', encoding='utf8') as f:
        json.dump(catalog, f, sort_keys=True, indent=4, ensure_ascii=False,
                  encoding='utf8', separators=(',', ': '))