A small package to localise your python application
Project description
LocalLang
Installation
pip install local-lang
Usage
python -m locallang --help # Show help
python -m locallang --default-lang en_us # Reload localisation
python -m locallang --version # Show version
Json file structure
placeholders
is optional
no_f_string
is optional
- This parameter is used to disable the use of f-string in the localization if you use {} in your translation.
format
is only for datetime
and time
type
{
"key": "value {placeholder_name}",
"@key": {
"no_f_string": "bool",
"placeholders": {
"placeholder_name": {
"type": "str|int|float|bool|datetime|time",
"format": "format"
}
}
}
}
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
Release history Release notifications | RSS feed
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.16.tar.gz
(17.6 kB
view details)
Built Distribution
File details
Details for the file local_lang-0.0.16.tar.gz
.
File metadata
- Download URL: local_lang-0.0.16.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e24d81a3c6f8ef103467dbaea192dc4adca46b51873cb678394d98ae065c40 |
|
MD5 | 8610136737c8fa4185b3819a27fa72dc |
|
BLAKE2b-256 | d6c7165e234cdfb34a41dbf934f2c4547d1af10731bc37d08f89c4c2edd99f85 |
File details
Details for the file local_lang-0.0.16-py3-none-any.whl
.
File metadata
- Download URL: local_lang-0.0.16-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f17c0f963c2922447556ed46012559745328d034c4ba9a146de668907c92458 |
|
MD5 | 970c836f9f5b6c998d14fdaec3de2908 |
|
BLAKE2b-256 | 0922635c7352778e6f8d7f2eebd8cbc620aedd4029b4e9dce860a0d579b97fa1 |