Skip to main content

dynamic-i18n

PyPI version

Introduction

dynamic-i18n is a python package that helps to flatten complex JSON files into a simple and accessible format. It also provides functionality to modify the text of specific properties and get an object that only contains properties of a specified language.

Installation

To install dynamic-i18n, run the following command:

pip install dynamic-i18n

Usage

To use dynamic-i18n, you need to pass either a file name or a dictionary to the I18NFlatten class. You can also specify a language prefix to limit the properties to a specific language.

import json

from dynamic_i18n.flatten import I18NFlatten



# Using a file

json_file = 'file.json'

i18n = I18NFlatten(json_file=json_file)



# Using a dictionary

json_dict = {...}

i18n = I18NFlatten(json_dict=json_dict)

The flattened properties can be accessed as attributes of the I18NFlatten object.

property_value = i18n.property_name

The modify_text method can be used to modify the text of a specified property by replacing placeholders with the provided parameters.

modified_text = i18n.modify_text('property_name', param1='value1', param2='value2')

The get_language_object method can be used to get a new I18NFlatten object that only contains properties of a specified language.

language_object = i18n.get_language_object('en')

Practical Example

from dynamic_i18n.flatten import I18NFlatten



data_json = {

    'i18n': {

        'welcome_message': {

            'en_us': "Hello World {name}",

            'pt_br': "Olá Mundo",

            'es': "Hola mundo"

        },

        'other_message': {

            'en_us': "{programming_language} programming language",

            'pt_br': "{programming_language} linguagem de programação",

            'es': "{programming_language} lenguaje de programación"

        }

    }

}



data = I18NFlatten(json_dict=data_json)

print(data._fields)

# {'i18n_welcome_message_en_us': 'Hello World {name}', 'i18n_welcome_message_pt_br': 'Olá Mundo', 'i18n_welcome_message_es': 'Hola mundo', 'i18n_other_message_en_us': '{programming_language} programming language', 'i18n_other_message_pt_br': '{programming_language} linguagem de programação', 'i18n_other_message_es': '{programming_language} lenguaje de programación'}



print(data.modify_text('i18n_welcome_message_en_us', name='Jeferson Peter'))

# IN: 'Hello World {name}'

# OUT: 'Hello World Jeferson Peter'



print(data.modify_text('i18n_other_message_pt_br', programming_language='Python'))

# IN: '{programming_language} linguagem de programação'

# OUT: 'Python linguagem de programação'



data_en = data.get_language_object(language_prefix='en_us')

print(data_en._fields)

# {'i18n_welcome_message_en_us': 'Hello World {name}', 'i18n_other_message_en_us': '{programming_language} programming language'}

Conclusion

dynamic-i18n provides a simple and convenient way to access and manipulate complex JSON files for internationalization purposes. Give it a try and see how it can help you in your next project.

Metadata

Release files for dynamic-i18n 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dynamic-i18n 0.0.7
File Size Uploaded Provenance Actions
dynamic_i18n-0.0.7.tar.gz 3.6 kB Without provenance Details for dynamic_i18n-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dynamic-i18n 0.0.7
File Interpreter ABI Platform Actions
dynamic_i18n-0.0.7-py3-none-any.whl Python 3 none any Details for dynamic_i18n-0.0.7-py3-none-any.whl

Total release size: 7.0 kB

Release files / dynamic_i18n-0.0.7.tar.gz

Download URL dynamic_i18n-0.0.7.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
48d0bdd5c3235fccaca7a0a9d4b07d319df5b32f45cd58229d46564ee3ba111e
BLAKE2b-256 checksum
How to use checksums
d5303d7ec2907093a2b352813cca5d3abb23b342704718c31098fd9630706d2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / dynamic_i18n-0.0.7-py3-none-any.whl

Download URL dynamic_i18n-0.0.7-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a693237fdde6072e57cfc24f4f23c34e883577bec8155c8cfd3ff7df287af328
BLAKE2b-256 checksum
How to use checksums
1cf4239ed13241156d2c2fa786654d4c945a545ef30ce81543c8a8daa12e512d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for dynamic-i18n 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page