Commit 3111d0f5 authored by Ana Rodríguez López's avatar Ana Rodríguez López

Import upstream version 1.0

parent 8c298d91
component_depth: 2
languages:
- python
# Configuration for probot-stale - https://github.com/probot/stale
# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 60
# Number of days of inactivity before a stale Issue or Pull Request is closed
daysUntilClose: 14
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- pinned
- security
# Label to use when marking as stale
staleLabel: wontfix
# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when removing the stale label. Set to `false` to disable
unmarkComment: false
# Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable
closeComment: false
# Limit to only `issues` or `pulls`
# only: issues
#
# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
pulls:
markComment: >
This pull request has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
issues:
daysUntilStale: 14
daysUntilClose: 7
exemptLabels:
- bug
- enhancement
- documentation
- security
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
[submodule "scripts/language-data"]
path = scripts/language-data
url = https://github.com/WeblateOrg/language-data.git
checks:
python:
code_rating: true
duplicate_code: true
classes_valid_slots: true
build:
environment:
python: 3.6
dependencies:
override:
- pip install -r requirements-test.txt
nodes:
analysis:
project_setup:
override:
- 'true'
tests:
override:
- py-scrutinizer-run
-
command: pylint-run
use_website_config: true
tests:
tests:
override:
-
command: py.test --cov=translation_finder translation_finder
coverage:
file: '.coverage'
format: 'py-cc'
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "pypy3"
matrix:
include:
- os: osx
language: sh
python: "3.7"
# Perform the manual steps on osx to install python3 and activate venv
before_install:
- brew update
- brew upgrade python3
- python3 -m pip install virtualenv
- virtualenv venv -p python3
- source venv/bin/activate
- os: windows
language: sh
python: "3.7"
before_install:
- choco install python3
- export PATH="/c/Python37:/c/Python37/Scripts:$PATH"
- python -m pip install --upgrade pip wheel
- os: windows
language: sh
python: "2.7"
before_install:
- choco install python2
- export PATH="/c/Python27:/c/Python27/Scripts:$PATH"
- python -m pip install --upgrade pip wheel
install:
# Get newer pip and whell for binary caching support
- pip install --upgrade pip wheel
- pip install -r requirements-test.txt
script:
- py.test --cov=translation_finder translation_finder
- ./setup.py sdist
- twine check dist/*
after_script:
- coverage xml
- codecov
- python-codacy-coverage
cache: pip
git:
depth: 10
submodules: false
Changelog
=========
1.0
---
* Released on 22th January 2019.
* Discover Joomla INI files.
0.3
---
* Released on 6th December 2018.
* Code restructuring.
* Better handling of multiple language codes in path.
* Extended test cases.
0.2
---
* Released on 30th November 2018.
* Added detection for monolingual Gettext, XLIFF and web extension.
* Detect new base for Gettext and Qt TS.
* Detect encoding of properties files.
* Automatically import Transifex configuration.
0.1
---
* Released on 19th October 2018.
* Initial release.
This diff is collapsed.
include README.rst
include LICENSE
include CHANGES.rst
include MANIFEST.in
include requirements.txt
include requirements-test.txt
include translation_finder/*.py
include translation_finder/discovery/*.py
recursive-include translation_finder/test_data *
# translation-finder
translation-finder
==================
A translation file finder for `Weblate`_, translation tool with tight version
control integration.
.. image:: https://travis-ci.com/WeblateOrg/translation-finder.svg?branch=master
:target: https://travis-ci.com/WeblateOrg/translation-finder
:alt: Build Status
.. image:: https://codecov.io/github/WeblateOrg/translation-finder/coverage.svg?branch=master
:target: https://codecov.io/github/WeblateOrg/translation-finder?branch=master
:alt: Code coverage
.. image:: https://scrutinizer-ci.com/g/WeblateOrg/translation-finder/badges/quality-score.png?b=master
:target: https://scrutinizer-ci.com/g/WeblateOrg/translation-finder/?branch=master
:alt: Scrutinizer Code Quality
.. image:: https://api.codacy.com/project/badge/Grade/9dba6b312da04123b3797cf6015ee012
:alt: Codacy Badge
:target: https://app.codacy.com/app/Weblate/translation-finder?utm_source=github.com&utm_medium=referral&utm_content=WeblateOrg/translation-finder&utm_campaign=Badge_Grade_Dashboard
.. image:: https://img.shields.io/pypi/v/translation-finder.svg
:target: https://pypi.org/project/translation-finder/
:alt: PyPI package
This library is used by `Weblate`_ to discover translation files in a cloned
repository.
Usage
-----
In can be used from Python:
.. code-block:: python
>>> from translation_finder import discover
>>> discover('.')
[
{
"filemask": "locales/*/messages.po",
"file_format": "po",
"template": None,
},
{
"filemask": "app/src/res/main/values-*/strings.xml",
"file_format": "aresource",
"template": "app/src/res/main/values/strings.xml",
}
]
Or command line:
.. code-block:: console
$ weblate-discovery translation_finder/test_data/
== Match 1 ==
file_format : po
filemask : locales/*.po
== Match 2 ==
file_format : aresource
filemask : app/src/res/main/values-*/strings.xml
template : app/src/res/main/values/strings.xml
.. _Weblate: https://weblate.org/
comment:
layout: reach, changes, diff, files
coverage:
status:
project:
default:
target: '99'
-r requirements.txt
codecov
codacy-coverage
pytest
pytest-cov
twine
pathlib2; python_version < '3.4'
six
chardet
#!/bin/sh
set -e
if [ "x$1" = "x--help" -o "x$1" = "x-h" ] ; then
echo "Usage: ./scripts/create-release [--tag]"
exit 1
fi
if ! git diff --exit-code --quiet ; then
echo "There are not committed changes!"
exit 1
fi
# Grab version
version=`python3 -c 'import translation_finder ; print(translation_finder.__version__)'`
# What are we going to build?
if [ "x$1" = "x--tag" ] ; then
git tag -s $version -m "Version $version"
fi
# PyPi archive
rm -f dist/translation-finder-$version*
fakeroot python3 ./setup.py sdist
fakeroot python3 ./setup.py bdist_wheel --universal
if [ "x$1" = "x--tag" ] ; then
twine upload --sign --identity 63CB1DF1EF12CF2AC0EE5A329C27B31342B7511D dist/translation-finder-$version*
twine upload --sign --identity 63CB1DF1EF12CF2AC0EE5A329C27B31342B7511D dist/translation_finder-$version*
fi
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
# Helper script to generate Python code from language-data repository
# see https://github.com/WeblateOrg/language-data
import csv
from itertools import chain
import json
import re
from textwrap import TextWrapper
SPLIT_RE = re.compile(
r"(?:\&(?:nbsp|rsaquo|lt|gt|amp|ldquo|rdquo|times|quot);|"
+ r'[() ,.^`"\'\\/_<>!?;:|{}*^@%#&~=+\r\n✓—‑…\[\]0-9-])+'
)
HEADER = '''# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
Language data definitions.
This is an automatically generated file, see scripts/generate-language-data
Do not edit, please adjust language definitions in following repository:
https://github.com/WeblateOrg/language-data
"""
from __future__ import unicode_literals
'''
WRAPPER = TextWrapper(width=79, initial_indent=" " * 4, subsequent_indent=" " * 4)
# Read languages
with open("scripts/language-data/languages.csv", "r") as csvfile:
reader = csv.reader(csvfile, delimiter=";")
LANGUAGES = list(reader)
# Read aliases
with open("scripts/language-data/aliases.csv", "r") as csvfile:
reader = csv.reader(csvfile, delimiter=";")
ALIASES = [alias for alias in reader if alias[0] != "#"]
CODES = set([item[0].lower() for item in chain(ALIASES, LANGUAGES)])
# Write same check blacklist
with open("translation_finder/languages.py", "w") as output:
output.write(HEADER)
output.write("\n\n")
output.write("# Known language codes\n")
output.write("LANGUAGES = frozenset(\n (\n")
for word in sorted(CODES):
output.write(' "{}",\n'.format(word.replace('"', '\\"')))
output.write(" )\n)\n")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Setup file for easy installation."""
from __future__ import unicode_literals
import os
import sys
from setuptools import setup, find_packages
VERSION = __import__("translation_finder").__version__
with open(os.path.join(os.path.dirname(__file__), "README.rst")) as readme:
LONG_DESCRIPTION = readme.read()
REQUIRES = [
line.split(";")[0]
for line in open("requirements.txt").read().splitlines()
if "python_version" not in line or sys.version_info < (3, 4)
]
REQUIRES_TEST = open("requirements-test.txt").read().splitlines()[1:]
setup(
name="translation-finder",
version=VERSION,
author="Michal Čihař",
author_email="michal@cihar.com",
description="A translation file finder for Weblate, translation tool with tight version control integration",
license="GPLv3+",
keywords="i18n l10n gettext translate",
url="https://weblate.org/",
download_url="https://github.com/WeblateOrg/translation-finder",
project_urls={
"Issue Tracker": "https://github.com/WeblateOrg/translation-finder/issues",
"Documentation": "https://docs.weblate.org/",
"Source Code": "https://github.com/WeblateOrg/translation-finder",
"Twitter": "https://twitter.com/WeblateOrg",
},
platforms=["any"],
packages=find_packages(),
long_description=LONG_DESCRIPTION,
install_requires=REQUIRES,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Internationalization",
"Topic :: Software Development :: Localization",
"Topic :: Utilities",
"License :: OSI Approved :: " "GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
],
setup_requires=["pytest-runner"],
tests_require=REQUIRES_TEST,
entry_points={"console_scripts": ["weblate-discover = translation_finder.api:cli"]},
)
# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
from __future__ import unicode_literals, absolute_import
from .finder import Finder
from .api import discover
__all__ = ("Finder", "discover")
__version__ = "1.0"
# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Highlevel API for translation-finder."""
from __future__ import unicode_literals, absolute_import, print_function
from argparse import ArgumentParser
import sys
from .finder import Finder
from .discovery.files import (
GettextDiscovery,
QtDiscovery,
AndroidDiscovery,
OSXDiscovery,
JavaDiscovery,
JoomlaDiscovery,
RESXDiscovery,
XliffDiscovery,
XliffDiscovery2,
WebExtensionDiscovery,
)
from .discovery.transifex import TransifexDiscovery
BACKENDS = [
TransifexDiscovery,
GettextDiscovery,
QtDiscovery,
AndroidDiscovery,
OSXDiscovery,
JavaDiscovery,
JoomlaDiscovery,
RESXDiscovery,
XliffDiscovery,
XliffDiscovery2,
WebExtensionDiscovery,
]
def discover(root, files=None, source_language="en"):
"""High level discovery interface."""
finder = Finder(root, files)
results = []
for backend in BACKENDS:
instance = backend(finder, source_language)
results.extend(instance.discover())
return results
def cli(stdout=None, args=None):
"""Execution entry point."""
stdout = stdout if stdout is not None else sys.stdout
parser = ArgumentParser(
description="Weblate translation discovery utility.",
epilog="This utility is developed at <{0}>.".format(
"https://github.com/WeblateOrg/translation-finder"
),
)
parser.add_argument("directory", help="Directory where to perform discovery")
params = parser.parse_args(args)
for pos, match in enumerate(discover(params.directory)):
print("== Match {} ==".format(pos + 1), file=stdout)
for key, value in sorted(match.items()):
print("{:15}: {}".format(key, value), file=stdout)
print("", file=stdout)
# -*- coding: utf-8 -*-
#
# Copyright © 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate translation-finder
# <https://github.com/WeblateOrg/translation-finder>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Base discovery code."""
from __future__ import unicode_literals, absolute_import
from itertools import chain
import re
from chardet.universaldetector import UniversalDetector
from ..languages import LANGUAGES
BLACKLIST = frozenset(("po", "ts"))
TOKEN_SPLIT = re.compile(r"([_-])")
class BaseDiscovery(object):
"""Abstract base class for discovery."""
file_format = "auto"
file_format_mono = None
mask = "*.*"
new_base_mask = None
def __init__(self, finder, source_language="en"):
self.finder = finder
self.source_language = source_language
@staticmethod
def is_language_code(code):
"""Analysis whether passed parameter looks like language code."""
if code.lower() in BLACKLIST:
return False
return code.lower().replace("-", "_") in LANGUAGES
def get_wildcard(self, part):
"""Generate language wilcard for a path part.
Retruns None if not possible."""
if self.is_language_code(part):
return "*"
if "." in part:
base, ext = part.rsplit(".", 1)