scrapy-translate: Scrapy pipeline to translate item fields
It's useful if you need to translate some text from parsed items into another language. But it is also suitable for other types of text processing.
Usage
1. Develop a translation service
The service should implement the following protocol to provide a mapping between the original and translated strings.
class TranslationProvider(Protocol):
async def translate(self, strings: Collection[str], /) -> dict[str, str]: ...
2. Develop a caching service (optionally)
This may help to reduce the number of strings that need to be translated. The service should implement the following protocol.
class CacheProvider(Protocol):
async def get(self, strings: Collection[str], /) -> dict[str, str]: ...
async def set(self, strings: dict[str, str], /) -> None: ...
3. Add metadata to the item's class fields
The pipeline will only process the specified fields. Strings and lists of strings are supported as field values.
class Item(scrapy.Item):
field = Field(translate=True) # type: Union[str, list[str]]
It's also possible to translate HTML markup text while preserving the structure.
class Item(scrapy.Item):
field = Field(translate=True, translate_html=True)
If you do want certain field values to be cached, you can specify that.
class Item(scrapy.Item):
field = Field(translate=True, translate_cache=True)
4. Adjust project settings
Set the translation service class to the following setting.
TRANSLATION_PROVIDER = "myproject.services.MyTranslationProvider"
You can optionally set the caching service class. By default, there is no caching.
TRANSLATION_CACHE_PROVIDER = "myproject.services.MyCacheProvider"
And activate the pipeline.
ITEM_PIPELINES = {
"scrapy_translate.pipeline.TranslatePipeline": 100,
}
Metadata
Release files for scrapy-translate 1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scrapy_translate-1.3.tar.gz | 6.8 kB | Without provenance | Details for scrapy_translate-1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrapy_translate-1.3-py3-none-any.whl | Python 3 | none | any | Details for scrapy_translate-1.3-py3-none-any.whl |
Total release size: 12.6 kB
Release files / scrapy_translate-1.3.tar.gz
| Download URL | scrapy_translate-1.3.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4cc8151d382efeedee9dc1a7d29ad8dce5b064f0422ddbd537e76aef25335c2
|
|
BLAKE2b-256 checksum How to use checksums |
a03fcd711111b4b734e75c4077a0142e50b765ab30322b8e931f3d3ac7d5a6e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / scrapy_translate-1.3-py3-none-any.whl
| Download URL | scrapy_translate-1.3-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
adb64142b9d8547d5d6bb4a894810d6cc7aae2b4050d8c96a5bc8c44fbca96ee
|
|
BLAKE2b-256 checksum How to use checksums |
50d97834dfc5a58959422580956a05521c994669ea8db6a03ff344cfb7fb4056
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for scrapy-translate 1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.