Name | easyjsonpy JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | Python library that allows you to easily load languages and settings into your project using JSON files |
upload_time | 2024-06-09 23:36:33 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | MIT License |
keywords |
language
settings
python
json
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# EasyJsonPy
EasyJsonPy is a Python library for loading and managing languages and settings in JSON format.
## Installation
To install EasyJsonPy, simply clone the repository and run:
```bash
pip install easyjsonpy
```
## Usage
### Simple use of language functions.
You need the language files in your project in their respective path
```py
from easyjsonpy import (
load_language,
load_languages,
set_language,
translate_message,
get_current_language,
get_languages
)
# Load a single language
load_language('en', 'path/to/en.json')
# Load multiple languages
languages = [
{'name': 'en', 'path': 'path/to/en.json'},
{'name': 'es', 'path': 'path/to/es.json'}
]
load_languages(languages)
# Set the current language
set_language('en')
# Translate a message
message = translate_message('greeting.hello')
print(message) # Output: Hello (if the translation exists in en.json)
# Get the current language
current_language = get_current_language()
print(current_language) # Output: en
# Get all loaded languages
loaded_languages = get_languages()
print(loaded_languages) # Output: {'en': {...}, 'es': {...}}
```
### You can load the language in the main file and get the translations in other files.
#### main.py
```py
from easyjsonpy import load_language, set_language
from test import example_function
load_language('en', 'en.json')
set_language('en')
example_function()
```
##### test.py
```py
from easyjsonpy import translate_message
def example_function():
print(translate_message('helloWorld')) # Output: Hello World
print(translate_message('messages.example')) # Output: Example Message
```
#### en.json
```json
{
"messages": {
"example": "Example Message"
},
"helloWorld": "Hello World"
}
```
#### Complete documentation of language features [here](./docs/language.md)
### Simple use of settings functions.
You need the setting file in your project in their respective path
```py
from easyjsonpy import (
load_configuration,
load_configurations,
get_config_value,
set_config_value,
get_configuration,
get_configurations,
remove_configuration,
remove_all_configurations
)
# Load a single configuration
load_configuration('config1', 'path/to/config1.json')
# Load multiple configurations
configs = [
{'name': 'config1', 'path': 'path/to/config1.json'},
{'name': 'config2', 'path': 'path/to/config2.json'}
]
load_configurations(configs)
# Get a value from a configuration
value = get_config_value('some.key', 'config1')
print(f"Value from config1: {value}")
# Set a value in a configuration
set_config_value('some.key', 'new_value', 'config1')
# Verify the value was set
updated_value = get_config_value('some.key', 'config1')
print(f"Updated value from config1: {updated_value}")
# Get the loaded configuration
config = get_configuration('config1')
print(f"Loaded config1: {config}")
# Get all loaded configurations
all_configs = get_configurations()
print(f"All loaded configurations: {all_configs}")
# Remove a specific configuration
remove_configuration('config1')
print(f"Configurations after removing config1: {get_configurations()}")
# Remove all configurations
remove_all_configurations()
print(f"Configurations after removing all: {get_configurations()}")
```
### Like the language, you can load the configuration in your main file and in the modules get the configuration directly
#### main.py
```py
from easyjsonpy import load_configuration
from test import example_function
load_configuration('default', 'config.json')
load_configuration('anotherConfig', 'anotherConfig.json')
example_function()
```
##### test.py
```py
from easyjsonpy import get_config_value
def example_function():
print(get_config_value('key1', 'default')) # Output: 'defaultValue'
print(get_config_value('key1')) # Default config_name is 'default'. Output: 'defaultValue'
print(get_config_value('key2', 'anotherConfig')) # Output: 'anotherValue'
```
#### config.json
```json
{
"key1": "defaultValue"
}
```
#### anotherConfig.json
```json
{
"key2": "anotherValue"
}
```
#### Complete documentation of language features [here](./docs/settings.md)
Raw data
{
"_id": null,
"home_page": null,
"name": "easyjsonpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "language, settings, python, json",
"author": null,
"author_email": "\"Pedro Agustin Vega (wrrulos)\" <vegapedroagustin2004@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ef/cb/284bdc07005845afa08be68fe3ae6b3e213b9dd0d020aeaf78cc72f5f890/easyjsonpy-1.0.0.tar.gz",
"platform": null,
"description": "# EasyJsonPy\r\nEasyJsonPy is a Python library for loading and managing languages \u200b\u200band settings in JSON format.\r\n\r\n## Installation\r\n\r\nTo install EasyJsonPy, simply clone the repository and run:\r\n\r\n```bash\r\npip install easyjsonpy\r\n```\r\n\r\n## Usage\r\n\r\n### Simple use of language functions.\r\nYou need the language files in your project in their respective path\r\n\r\n```py\r\nfrom easyjsonpy import (\r\n load_language,\r\n load_languages,\r\n set_language,\r\n translate_message,\r\n get_current_language,\r\n get_languages\r\n)\r\n\r\n# Load a single language\r\nload_language('en', 'path/to/en.json')\r\n\r\n# Load multiple languages\r\nlanguages = [\r\n {'name': 'en', 'path': 'path/to/en.json'},\r\n {'name': 'es', 'path': 'path/to/es.json'}\r\n]\r\nload_languages(languages)\r\n\r\n# Set the current language\r\nset_language('en')\r\n\r\n# Translate a message\r\nmessage = translate_message('greeting.hello')\r\nprint(message) # Output: Hello (if the translation exists in en.json)\r\n\r\n# Get the current language\r\ncurrent_language = get_current_language()\r\nprint(current_language) # Output: en\r\n\r\n# Get all loaded languages\r\nloaded_languages = get_languages()\r\nprint(loaded_languages) # Output: {'en': {...}, 'es': {...}}\r\n```\r\n\r\n### You can load the language in the main file and get the translations in other files.\r\n\r\n\r\n#### main.py\r\n\r\n```py\r\nfrom easyjsonpy import load_language, set_language\r\nfrom test import example_function\r\n\r\nload_language('en', 'en.json')\r\nset_language('en')\r\nexample_function()\r\n```\r\n\r\n##### test.py\r\n\r\n```py\r\nfrom easyjsonpy import translate_message\r\n\r\ndef example_function():\r\n print(translate_message('helloWorld')) # Output: Hello World\r\n print(translate_message('messages.example')) # Output: Example Message\r\n```\r\n\r\n#### en.json\r\n\r\n```json\r\n{\r\n \"messages\": {\r\n \"example\": \"Example Message\"\r\n },\r\n \"helloWorld\": \"Hello World\"\r\n}\r\n```\r\n\r\n#### Complete documentation of language features [here](./docs/language.md)\r\n\r\n### Simple use of settings functions.\r\nYou need the setting file in your project in their respective path\r\n\r\n```py\r\nfrom easyjsonpy import (\r\n load_configuration,\r\n load_configurations,\r\n get_config_value,\r\n set_config_value,\r\n get_configuration,\r\n get_configurations,\r\n remove_configuration,\r\n remove_all_configurations\r\n)\r\n\r\n# Load a single configuration\r\nload_configuration('config1', 'path/to/config1.json')\r\n\r\n# Load multiple configurations\r\nconfigs = [\r\n {'name': 'config1', 'path': 'path/to/config1.json'},\r\n {'name': 'config2', 'path': 'path/to/config2.json'}\r\n]\r\nload_configurations(configs)\r\n\r\n# Get a value from a configuration\r\nvalue = get_config_value('some.key', 'config1')\r\nprint(f\"Value from config1: {value}\")\r\n\r\n# Set a value in a configuration\r\nset_config_value('some.key', 'new_value', 'config1')\r\n\r\n# Verify the value was set\r\nupdated_value = get_config_value('some.key', 'config1')\r\nprint(f\"Updated value from config1: {updated_value}\")\r\n\r\n# Get the loaded configuration\r\nconfig = get_configuration('config1')\r\nprint(f\"Loaded config1: {config}\")\r\n\r\n# Get all loaded configurations\r\nall_configs = get_configurations()\r\nprint(f\"All loaded configurations: {all_configs}\")\r\n\r\n# Remove a specific configuration\r\nremove_configuration('config1')\r\nprint(f\"Configurations after removing config1: {get_configurations()}\")\r\n\r\n# Remove all configurations\r\nremove_all_configurations()\r\nprint(f\"Configurations after removing all: {get_configurations()}\")\r\n```\r\n\r\n### Like the language, you can load the configuration in your main file and in the modules get the configuration directly\r\n\r\n#### main.py\r\n\r\n```py\r\nfrom easyjsonpy import load_configuration\r\nfrom test import example_function\r\n\r\nload_configuration('default', 'config.json')\r\nload_configuration('anotherConfig', 'anotherConfig.json')\r\nexample_function()\r\n```\r\n\r\n##### test.py\r\n\r\n```py\r\nfrom easyjsonpy import get_config_value\r\n\r\n\r\ndef example_function():\r\n print(get_config_value('key1', 'default')) # Output: 'defaultValue'\r\n print(get_config_value('key1')) # Default config_name is 'default'. Output: 'defaultValue'\r\n print(get_config_value('key2', 'anotherConfig')) # Output: 'anotherValue'\r\n```\r\n\r\n#### config.json\r\n\r\n```json\r\n{\r\n \"key1\": \"defaultValue\"\r\n}\r\n```\r\n\r\n#### anotherConfig.json\r\n\r\n```json\r\n{\r\n \"key2\": \"anotherValue\"\r\n}\r\n```\r\n\r\n#### Complete documentation of language features [here](./docs/settings.md)\r\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Python library that allows you to easily load languages and settings \u200b\u200binto your project using JSON files",
"version": "1.0.0",
"project_urls": {
"documentation": "https://github.com/wrrulos/easyjsonpy",
"homepage": "https://github.com/wrrulos/easyjsonpy",
"repository": "https://github.com/wrrulos/easyjsonpy"
},
"split_keywords": [
"language",
" settings",
" python",
" json"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ff3f9a3c1a6476e0fcd2e7ef53939a3f9a3a877340186a80007c5af2cf6b69aa",
"md5": "b887dfb0e7116db15da2906ce326bc07",
"sha256": "03030a66e625ff0b00c48d6647c31007c2c7c2b4bf111856d4e375a3b11940e5"
},
"downloads": -1,
"filename": "easyjsonpy-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b887dfb0e7116db15da2906ce326bc07",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7202,
"upload_time": "2024-06-09T23:36:31",
"upload_time_iso_8601": "2024-06-09T23:36:31.711194Z",
"url": "https://files.pythonhosted.org/packages/ff/3f/9a3c1a6476e0fcd2e7ef53939a3f9a3a877340186a80007c5af2cf6b69aa/easyjsonpy-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "efcb284bdc07005845afa08be68fe3ae6b3e213b9dd0d020aeaf78cc72f5f890",
"md5": "27c1233d27a32d30734a933faff31cf0",
"sha256": "7497e5de4ab1cb012d3d683d0f0fe5bea77fe265cf0edd01532d907ccda489bf"
},
"downloads": -1,
"filename": "easyjsonpy-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "27c1233d27a32d30734a933faff31cf0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8674,
"upload_time": "2024-06-09T23:36:33",
"upload_time_iso_8601": "2024-06-09T23:36:33.462605Z",
"url": "https://files.pythonhosted.org/packages/ef/cb/284bdc07005845afa08be68fe3ae6b3e213b9dd0d020aeaf78cc72f5f890/easyjsonpy-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-09 23:36:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wrrulos",
"github_project": "easyjsonpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "easyjsonpy"
}