Skip to main content

A small package to localise your python application

Project description

LocalLang

Installation

pip install local-lang

Example

test.py

from locallang import LangInit, getLocalisation
import datetime

localisation = LangInit()

local = getLocalisation(local="en_us")

print(local.hey())
print(local.hello_world())
print(local.toDay(date=datetime.datetime.now()))
print(local.thisTime(time=datetime.datetime.now().time()))
print(local.testStr(strText="Hello world!"))
print(local.testInt(intNum=1))
print(local.testFloat(floatNum=1.5))
print(local.testBool(boolValue=True))
print(local.test(test=1.5))

local = getLocalisation(local="fr")

print(local.hey())
print(local.hello_world())
print(local.toDay(date=datetime.datetime.now()))
print(local.thisTime(time=datetime.datetime.now().time()))
print(local.testStr(strText="Bonjour tout le monde !"))
print(local.testInt(intNum=2))
print(local.testFloat(floatNum=2.5))
print(local.testBool(boolValue=False))
print(local.test(test="coucou"))

en_us.json

{
    "hey": "Hey!",
    "hello_world": "Hello world!",
    "toDay": "Date: {date}",
    "@toDay": {
        "placeholders": {
            "date": {
                "type": "datetime",
                "format": "%Y/%m/%d %H:%M"
            }
        }
    },
    "thisTime": "Time: {time}",
    "@thisTime": {
        "placeholders": {
            "time": {
                "type": "time",
                "format": "%H:%M"
            }
        }
    },
    "testStr": "Test: {strText}",
    "@testStr": {
        "placeholders": {
            "strText": {
                "type": "str"
            }
        }
    },
    "testInt": "Test: {intNum}",
    "@testInt": {
        "placeholders": {
            "intNum": {
                "type": "int"
            }
        }
    },
    "testFloat": "Test: {floatNum}",
    "@testFloat": {
        "placeholders": {
            "floatNum": {
                "type": "float"
            }
        }
    },
    "testBool": "Test: {boolValue}",
    "@testBool": {
        "placeholders": {
            "boolValue": {
                "type": "bool"
            }
        }
    },
    "test": "Test: {test}"
}

fr.json

{
    "hey": "Coucou !",
    "hello_world": "Bonjour tout le monde!",
    "toDay": "Date: {date}",
    "thisTime": "Time: {time}",
    "testStr": "Test: {strText}",
    "testInt": "Test: {intNum}",
    "testFloat": "Test: {floatNum}",
    "testBool": "Test: {boolValue}",
    "test": "Test: {test}"
}

result in consol

Hey!
Hello world!
Date: 2023/05/07 00:15
Time: 00:15
Test: Hello world!
Test: 1
Test: 1.5
Test: True
Test: 1.5
Coucou !
Bonjour tout le monde!
Date: 2023/05/07 00:15
Time: 00:15
Test: Bonjour tout le monde !
Test: 2
Test: 2.5
Test: False
Test: coucou

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

local_lang-0.0.13.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

local_lang-0.0.13-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file local_lang-0.0.13.tar.gz.

File metadata

  • Download URL: local_lang-0.0.13.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for local_lang-0.0.13.tar.gz
Algorithm Hash digest
SHA256 3891834f4deb9feb40582654b2bd92b4b22c898d866bc91516c806a7444663ab
MD5 26323e734b8808c1f3278824266af9f6
BLAKE2b-256 69f6250f6f8d9127f7cb734e2f6693fe5b19fae01297633a774fda08e1c5e83c

See more details on using hashes here.

File details

Details for the file local_lang-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: local_lang-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for local_lang-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 d09ecda01c2ba0ab2ce677161832a4b75253214c8e5435c91c955514dd7bdc96
MD5 94039de1730cd7af604a7b6ee4a4ca21
BLAKE2b-256 a0954b1324310232697bfcbb4be64d266d56a301d4234d5c7df6843bd0b2f674

See more details on using hashes here.

Supported by

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