Skip to main content

Python library that allows you to easily load languages and settings into your project using JSON files

Project description

TongoPy

TongoPy is a Python library for loading and managing languages and settings in JSON format.

Installation

To install tongopy, simply use the pip install command

pip install tongopy

Usage

Simple use of language functions.

You need the language files in your project in their respective path

from tongopy 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

from tongopy import load_language, set_language
from test import example_function

load_language('en', 'en.json')
set_language('en')
example_function()
test.py
from tongopy import translate_message

def example_function():
    print(translate_message('helloWorld'))  # Output: Hello World
    print(translate_message('messages.example'))  # Output: Example Message

en.json

{
    "messages": {
        "example": "Example Message"
    },
    "helloWorld": "Hello World"
}

Complete documentation of language features here

Simple use of settings functions.

You need the setting file in your project in their respective path

from tongopy 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

from tongopy import load_configuration
from test import example_function

load_configuration('default', 'config.json')
load_configuration('anotherConfig', 'anotherConfig.json')
example_function()
test.py
from tongopy 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

{
    "key1": "defaultValue"
}

anotherConfig.json

{
    "key2": "anotherValue"
}

Complete documentation of language features here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tongopy-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tongopy-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file tongopy-1.0.0.tar.gz.

File metadata

  • Download URL: tongopy-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for tongopy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a8752764268d4696816ad6eac54a49c0c19b4ec36d274a8e5423e6a3cba5e520
MD5 adbfff85d5a23218f183499df56f2dd6
BLAKE2b-256 3ef435006dcb32ec06c27b12e743431b5d431314d33f44fa2b9eacefb4efba24

See more details on using hashes here.

File details

Details for the file tongopy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tongopy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for tongopy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d314e96eaa960128d5375ccc6c82a7acd10e6f5e17466e491046f14418bc6adf
MD5 d66a2d5bbc22edd44692d61d9af0022a
BLAKE2b-256 95b5f6d475753a0d86467ce4c07056320ede29500eabee0b626080a1a4640c46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page