python-tmx


Namepython-tmx JSON
Version 0.2.0.2 PyPI version JSON
download
home_pageNone
SummaryPython library for manipulating, creating and editing tmx files
upload_time2024-08-02 14:38:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Overview

PythonTmx is a Python library that aims to make dealing with tmx files in Python
easier.

Every tmx element from the TMX 1.4b standard is represented (including the
deprecated <ut> element for compatibility).

To create a Tmx Element, you can either create it from scratch and set its
attributes using keyword arguments, or you can also give it a lxml element to
parse and use a base. If you give both an lxml element and keyword arguments
the values parsed from the element will take precedence and the keywords
argument values will be used as a fallback.

# Installing

Simply download from Pypi and install using pip:

```bash
pip install --upgrade PythonTmx
```

# Basic usage

You can create a `Tmx` object by reading a tmx file. From there, you can just
iterate over each tu, and further each tuv, do any processing needed and then
just export it back to another file.

```python
from datetime import UTC, datetime

from PythonTmx import from_tmx
from PythonTmx.inline import Ph

# Create Tmx object from a tmx file
tmx_file = from_tmx("tmx_file.tmx")
# Loop over all Tu
for tu in tmx_file:
    # Set the Tu's source language to English
    tu.srclang = "EN"
    # Loop over all Tuv and check the language
    for tuv in tu.tuvs:
        match tuv.xmllang:
            case "EN":
                # If Tuv is in English, add _English at the end
                tuv.segment.append("_English")
            case "FR":
                # If it's French, add a Ph that says "_French"
                # at the start
                tuv.segment.insert(0, Ph(content="_French"))
            case _:
                # Remove the Tuv otherwise
                tu.tuvs.remove(tuv)
        # Add a prop to the Tuv and set the changedate to today
        tuv.add_prop(type="x-confidential", text="True")
        tuv.changedate = datetime.now(UTC)
    # Remove all notes that don't start with "Hello"
    # and also add a new one and set the changedate to today
    for note in tu.notes:
        if not note.text.startswith("Hello"):
            tu.remove_note(note)
    tu.add_note(text="adding a note here, huge success")
    tu.changedate = datetime.now(UTC)
# Export Tmx to a tmx file and to a csv file
tmx_file.to_tmx("bilingual_tmx_file.tmx")
tmx_file.to_csv("bilingual.csv")
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-tmx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Enzo Agosta <agosta.enzowork@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b7/51/f4b436455d031ea0dd888bd111d3428d0040a8c2c8f518ffafa1d428fb5c/python_tmx-0.2.0.2.tar.gz",
    "platform": null,
    "description": "# Overview\r\n\r\nPythonTmx is a Python library that aims to make dealing with tmx files in Python\r\neasier.\r\n\r\nEvery tmx element from the TMX 1.4b standard is represented (including the\r\ndeprecated <ut> element for compatibility).\r\n\r\nTo create a Tmx Element, you can either create it from scratch and set its\r\nattributes using keyword arguments, or you can also give it a lxml element to\r\nparse and use a base. If you give both an lxml element and keyword arguments\r\nthe values parsed from the element will take precedence and the keywords\r\nargument values will be used as a fallback.\r\n\r\n# Installing\r\n\r\nSimply download from Pypi and install using pip:\r\n\r\n```bash\r\npip install --upgrade PythonTmx\r\n```\r\n\r\n# Basic usage\r\n\r\nYou can create a `Tmx` object by reading a tmx file. From there, you can just\r\niterate over each tu, and further each tuv, do any processing needed and then\r\njust export it back to another file.\r\n\r\n```python\r\nfrom datetime import UTC, datetime\r\n\r\nfrom PythonTmx import from_tmx\r\nfrom PythonTmx.inline import Ph\r\n\r\n# Create Tmx object from a tmx file\r\ntmx_file = from_tmx(\"tmx_file.tmx\")\r\n# Loop over all Tu\r\nfor tu in tmx_file:\r\n    # Set the Tu's source language to English\r\n    tu.srclang = \"EN\"\r\n    # Loop over all Tuv and check the language\r\n    for tuv in tu.tuvs:\r\n        match tuv.xmllang:\r\n            case \"EN\":\r\n                # If Tuv is in English, add _English at the end\r\n                tuv.segment.append(\"_English\")\r\n            case \"FR\":\r\n                # If it's French, add a Ph that says \"_French\"\r\n                # at the start\r\n                tuv.segment.insert(0, Ph(content=\"_French\"))\r\n            case _:\r\n                # Remove the Tuv otherwise\r\n                tu.tuvs.remove(tuv)\r\n        # Add a prop to the Tuv and set the changedate to today\r\n        tuv.add_prop(type=\"x-confidential\", text=\"True\")\r\n        tuv.changedate = datetime.now(UTC)\r\n    # Remove all notes that don't start with \"Hello\"\r\n    # and also add a new one and set the changedate to today\r\n    for note in tu.notes:\r\n        if not note.text.startswith(\"Hello\"):\r\n            tu.remove_note(note)\r\n    tu.add_note(text=\"adding a note here, huge success\")\r\n    tu.changedate = datetime.now(UTC)\r\n# Export Tmx to a tmx file and to a csv file\r\ntmx_file.to_tmx(\"bilingual_tmx_file.tmx\")\r\ntmx_file.to_csv(\"bilingual.csv\")\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for manipulating, creating and editing tmx files",
    "version": "0.2.0.2",
    "project_urls": {
        "Homepage": "https://github.com/ChonkyYoshi/python-tmx",
        "Issues": "https://github.com/ChonkyYoshi/python-tmx/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "355bf1d6a573850b5841d7b97c5991ac475f9343b5c58308da6f40e32f4059d2",
                "md5": "3d2969663bcf40afddc23261a0e2f11f",
                "sha256": "ff1ea561bf5c8e24fb74eea60476431937cff39056276e3f4bc4765f0c5c1021"
            },
            "downloads": -1,
            "filename": "python_tmx-0.2.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d2969663bcf40afddc23261a0e2f11f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14748,
            "upload_time": "2024-08-02T14:38:05",
            "upload_time_iso_8601": "2024-08-02T14:38:05.856909Z",
            "url": "https://files.pythonhosted.org/packages/35/5b/f1d6a573850b5841d7b97c5991ac475f9343b5c58308da6f40e32f4059d2/python_tmx-0.2.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b751f4b436455d031ea0dd888bd111d3428d0040a8c2c8f518ffafa1d428fb5c",
                "md5": "3c9180730e5ab7e631b7ce09901c5439",
                "sha256": "55c9287097c02e30af4c66e63268f93a0e09d539874552f1cf811ec1de99cb34"
            },
            "downloads": -1,
            "filename": "python_tmx-0.2.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3c9180730e5ab7e631b7ce09901c5439",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14662,
            "upload_time": "2024-08-02T14:38:06",
            "upload_time_iso_8601": "2024-08-02T14:38:06.885682Z",
            "url": "https://files.pythonhosted.org/packages/b7/51/f4b436455d031ea0dd888bd111d3428d0040a8c2c8f518ffafa1d428fb5c/python_tmx-0.2.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-02 14:38:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ChonkyYoshi",
    "github_project": "python-tmx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-tmx"
}
        
Elapsed time: 0.30219s