{ "info": { "author": "Alex Milstead", "author_email": "alex@amilstead.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# gettext-anywhere #\n\nThis is a python library for registering arbitrary file handlers that can read gettext files from any source location, not just the local file system.\n\nBy default, gettext reads directly from the file system rather than providing extended functionality for reading from any type of file system.\n\nIn the web application world -- it can be advantageous to update your translation catalogs without requiring a full re-deploy, since they would likely have to be re-compiled and saved onto a deployed application instance's file system.\n\n## Installation ##\n\nInstall using pip and/or virtualenv:\n\n virtualenv /my-project\n pip install gettext-anywhere\n\nOr easy_install:\n\n easy_install gettext-anywhere\n\n### Optional Dependencies ###\nThis package includes an [S3FileHandler](gettext_anywhere/handlers/aws.py) out of the box, which relies on the [boto](https://pypi.python.org/pypi/boto) library.\n\nIf you want to use the S3FileHandler, you must install `boto` into your python runtime.\n\nTo install boto, use pip and/or virtualenv:\n\n pip install boto\n\nOr easy_install:\n\n easy_install boto\n\n## Usage ###\nThis package patches gettext's `translation` functionality in order to allow for discovering message catalogs that may not necessarily exist on a local file system.\n\nAs a result, after a registration command is performed, no additional usage of the library is necessary.\n\nSimply call the function that's right for you inside the [registry](gettext_anywhere/registry.py) module and go on about your business.\n\n### Handler Registration ###\nHandler registration is performed on a domain by domain basis.\n\nTo register a handler for the default domain (\"messages\") one would do the following:\n\n from gettext_anywhere import registry\n\n registry.register_default_handler(\n my_handler_class,\n options={'options': 'dict'}\n )\n\nTo register a handler for a custom domain, one would do the following:\n\n from gettext_anywhere import registry\n\n registry.register_domain_handler(\n 'my-translations-domain',\n my_handler_class,\n options={'options': 'dict'}\n )\n\n### Provided Handlers ###\n#### RegularFileHandler ####\n**NOTE**: The RegularFileHandler is the default file handler in the event that no other handlers have been registered.\n\nThe [RegularFileHandler](gettext_anywhere/handlers/file.py) mimics the default gettext behavior.\n\nIt uses the core [FileHandler](gettext_anywhere/handlers/core.py) interface to open a file object for reading as well as shadows its `find` command down to default gettext's `find` function.\n\n#### S3FileHandler ####\nThe [S3FileHandler](gettext_anywhere/handlers/aws.py) relies on the `boto` library to access contents inside an S3 bucket in AWS.\n\nThe options for an S3FileHandler are:\n\n* `bucket_name`: The name of the S3 bucket to access.\n* `default_localedir`: An optional locale directory inside the S3 bucket where translations are stored (it will look in the root of the bucket by default).\n* `aws_access_key_id`: AWS access key (defaults to `AWS_ACCESS_KEY_ID` environment variable).\n* `aws_secret_access_key`: AWS secret key (defaults to `AWS_SECRET_ACCESS_KEY` environment variable).\n\n### Writing a Handler ###\nWriting a handler is simple -- it is a class which must inherit the core [FileHandler](gettext_anywhere/handlers/core.py) and must implement four functions:\n\n* `open(self, filename)`: This function should open the provided file and cache its file pointer (or contents) on itself.\n* `find(self, localedir=None, languages=None, all=0)`: This function should return a single file path or list of file paths for use by `open` and `read` for gettext translation objects. **These file paths are your .mo files**.\n* `read(self)`: Read the file contents and return them as an iterable.\n* `close(self)`: Close the file that was opened (and probably read) using `open`.\n\nSee [S3FileHandler](gettext_anywhere/handlers/aws.py) for an example of a custom file handler implementation.\n\n## Examples ##\n\nCheckout the [examples](examples) directory.\n\nA quick one would be:\n\n from gettext_anywhere import registry\n from gettext_anywhere.handlers import aws\n registry.set_default_handler(\n aws.S3FileHandler,\n options={\n \"bucket_name\": \"my-bucket\",\n \"aws_access_key_id\": ,\n \"aws_secret_access_key\": \n }\n )\n\n ...\n\n import gettext\n spanish = gettext.translation(\"messages\", languages=[\"es_ES\"])\n print spanish.gettext(\"Some translated string!\")\n\n## Contributing ##\n* For the repository.\n* Make changes.\n* Submit a pull request.\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/amilstead/gettext-anywhere", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "gettext-anywhere", "package_url": "https://pypi.org/project/gettext-anywhere/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/gettext-anywhere/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/amilstead/gettext-anywhere" }, "release_url": "https://pypi.org/project/gettext-anywhere/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Register gettext catalog files from anywhere.", "version": "1.0.0" }, "last_serial": 1609592, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d04577d3662d5a4df2fb0f26d9b0fa58", "sha256": "283b11bdee0b1e832d3dcccbf3e78bfac3ddd6e5bd4da607b027742bf5d570d6" }, "downloads": -1, "filename": "gettext-anywhere-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d04577d3662d5a4df2fb0f26d9b0fa58", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6851, "upload_time": "2015-06-27T23:24:19", "url": "https://files.pythonhosted.org/packages/60/7e/7c6f23111b25698dfd4b9507b4bc81f4ae9cd7bfed45cf757ba3d4019061/gettext-anywhere-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d04577d3662d5a4df2fb0f26d9b0fa58", "sha256": "283b11bdee0b1e832d3dcccbf3e78bfac3ddd6e5bd4da607b027742bf5d570d6" }, "downloads": -1, "filename": "gettext-anywhere-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d04577d3662d5a4df2fb0f26d9b0fa58", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6851, "upload_time": "2015-06-27T23:24:19", "url": "https://files.pythonhosted.org/packages/60/7e/7c6f23111b25698dfd4b9507b4bc81f4ae9cd7bfed45cf757ba3d4019061/gettext-anywhere-1.0.0.tar.gz" } ] }