{"id":27734307,"url":"https://github.com/sqivea/pylocale","last_synced_at":"2025-04-28T13:05:40.996Z","repository":{"id":62581462,"uuid":"264433062","full_name":"sqivea/pylocale","owner":"sqivea","description":"A Python3 library without dependencies that provides static translations across your app","archived":false,"fork":false,"pushed_at":"2020-05-16T22:12:16.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T13:05:08.350Z","etag":null,"topics":["localization","pip","python","python-3","python-library","translation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sqivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-16T12:34:22.000Z","updated_at":"2020-07-04T20:20:14.000Z","dependencies_parsed_at":"2022-11-03T21:55:18.475Z","dependency_job_id":null,"html_url":"https://github.com/sqivea/pylocale","commit_stats":null,"previous_names":["sqivea/pylocale","mavedev/pylocale","imvq/pylocale"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqivea%2Fpylocale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqivea%2Fpylocale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqivea%2Fpylocale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sqivea%2Fpylocale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sqivea","download_url":"https://codeload.github.com/sqivea/pylocale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251319610,"owners_count":21570426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["localization","pip","python","python-3","python-library","translation"],"created_at":"2025-04-28T13:04:57.426Z","updated_at":"2025-04-28T13:05:40.971Z","avatar_url":"https://github.com/sqivea.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pylocale\nA Python 3 library that allows adding static files with translations to the application, and then apply them to dynamically change text in the application.\n\nInstalling\n----------\n\n**Python 3.6.9 or higher is recommended**\n\nTo install the library, you can just run the following command:\n\n```shell script\n# Linux/macOS\npython3 -m pip install pylocale\n\n# Windows\npip install pylocale\n```\n\nTranslation files\n--------------\nYou must provide a folder in your project directory where your translation files will be located.\n```\nyour-app-root\n|--translations\n   |----en-us\n   |----de-de\n   |----zh-cn\n   ...\n...\n```\nThe struture can be any, but the translation files must be accessible from the program.\nTranslation files must be text files of .env-like format ```\u003cKEY\u003e = \u003cTRANSLATION\u003e``` **(spaces are required or you will get a parsing error)**:\n\n```\n# en-us file example\nHELP = Get help\nSETTINGS = Settings\nEXIT = Exit\n```\n```\n# de-de file example\nHELP = Hilfe bekommen\nSETTINGS = Einstellungen\nEXIT = Ausfahrt\n```\nIt's recommended for the translation files to have the same keys, but it's not necessary.\n\nUsage\n--------------\nYou can use pylocal as follows:\n```python\nfrom pylocal import PyLocal\n\ntranslator = PyLocal(\n    at='translations/',  # Your translations directory path.\n    root='en',  # Default locale.\n    silent=True  # Tell PyLocal not to raise exceptions in case of errors.\n)\n```\nTo get translation:\n```python\ntranslator['HELP']  # \u003e\u003e\u003e Help\n```\nTo switch to another locale:\n```python\ntranslator.switch('de-de')\ntranslator['HELP']  # \u003e\u003e\u003e Hilfe bekommen\n```\nAny translation you switch to covers the root translation file. That means If there was no help key, it would be taken from the root translation file:\n```\n# en-us file example\nHELP = Get help\nSETTINGS = Settings\nEXIT = Exit\nCOLOR = Color\n```\n```\n# en-gb file example\nCOLOR = Colour\n```\n```python\ntranslator = PyLocale(at='transaltions/', root='en-us')\ntanslator['COLOR']  # \u003e\u003e\u003e Color\ntranslator.switch('en-gb')\ntanslator['COLOR']  # \u003e\u003e\u003e Colour\n# SETTINGS is not defined in en-gb. It will be taken from en-us, which is the root translation file.\ntanslator['SETTINGS']  # \u003e\u003e\u003e Settings\n```\n\nRaising exceptions\n--------------\nIf the silent mode is turned off (default) your app will break down with exceptions in case of errors. If you want the translator to try to return something, you may pass a True to silent parameter as shown above. In that case, the translator will return an empty string.\n```python\ntranslator = PyLocale(\n    at='transaltions/',\n    root='blablabla',\n    silent=True\n)\ntanslator['SETTINGS']  # \u003e\u003e\u003e ''\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqivea%2Fpylocale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsqivea%2Fpylocale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsqivea%2Fpylocale/lists"}