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.14.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

local_lang-0.0.14-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: local_lang-0.0.14.tar.gz
  • Upload date:
  • Size: 18.7 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.14.tar.gz
Algorithm Hash digest
SHA256 34ef54d9c1f2828afb4ddb6689080c354daa1e28acd08480686cf682d35f2ba0
MD5 2982ce6861ddf8b8414debf055bba1ef
BLAKE2b-256 045698f1ea128a2135457085fd7fc1d68805cde7ddc02d479dd2f930e9d1b2a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: local_lang-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 19.7 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 04a8391c9da4d40dfbf1129da3a88fb7b13d0cf008efde2e5f7cf9b8307a647a
MD5 e1980ee81efbbd9a72f59aa915daac40
BLAKE2b-256 e67d4caafc48d8fadfc260aebaca8227762ba440ae1caecd1f144346e8d4ef4c

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