A python library designed to allow an easy translation system for other projects
Project description
Tradlib
For the overview of the library check here.
Make translation files
Translation files must follow JSON formatting (which you can easily find on the internet). The name of the file is not important (it does not serve the identification of the language) on the other hand the extension of the file must correspond to that indicated with the function set_translation_files_extension or be ".lang" (by default). To identify the language, a specific key must be present and the name of the language must be associated with it. Here is the minimum configuration for detecting a translation file:
example.lang
{
"language": "english"
}
In the example above, after setting the path to the translation file and loading the file, the get_available_languages function will return ['english'].
/!\ If this key is missing, the translation file will be not detected!
Functions
- set_translations_files_path(full_path, flat_build, build_architecture)
This function is used to define the access path to the translation files
Args:
- full_path (required): The full path to the folder containing the uncompiled translation files:
full_path="C:\\Users\\some_user\\Desktop\\dev\\Tradlib"
/!\ I recommend putting the path with "\\" rather than "\" because with "\" python can believe that you are trying to put unicode characters. In addition, your paths may or may not end with "\\" or "\" it will not change anything ("C:\\Users\\some_user\\Desktop\\dev\\Tradlib" and "C:\\Users\\some_user\\Desktop\\dev\\Tradlib\\" are equal)
-
flat_build (optional): Put true if all your translation files are at the root of your project when compiling otherwise leave false.
-
build_architecture (optional): The full path for your translation files from the compiled project root:
If you have this structure (bellow) the right argument will be "resources\\lang"
your_project.exe
│ *.ddl
│ some_required_files
│
└───resources
│ some_picture.png
│ some_sounds.mp3
│
└───lang
│ english.lang
/!\ I recommend putting the path with "\\" rather than "\" because with "\" python can believe that you are trying to put unicode characters. In addition, your paths may or may not end with "\\" or "\" it will not change anything ("resources\\lang" and "resources\\lang\\" are equal)
- get_translations_files_path()
This function returns the path of your translation files. If you haven't setup this path with the set_translations_files_path function, this will return the current work directory.
- set_translation_files_extension(extension)
This function set the extension to use for translations files. The default extension is ".lang". Args:
- extension (required): The extension you want to set
- get_translation_files_extension()
This function return your selected extension for translation files. Default is ".lang".
- load_translations_files()
This function loads your translation files. If you don't have executed set_translations_files_path, translations files in the current work directory will be load.
- get_available_languages()
This function returns the list of available languages. If you don't have executed load_translations_files, this will return an empty list.
- get_translation(language, keys_list)
This function returns the translation associated with the list of keys given with arguments. To work, this function requires the execution of load_translations_files otherwise you are looking in an empty list.
Args:
-
language (required): The language (among the list of available languages) in which you want a translation.
-
keys_list (required): The list of keys (in order) allowing access to the desired translation.
For the example bellow:
for quit the right arg is ["text", 0, "quit"]
for title the right arg is ["text", 1, "title"]
for button_reduce the right arg is ["button", 0, "button_reduce"]
english.lang
{
"language": "english",
"text": [
{
"quit": "Quit"
},
{
"title": "Tradlib"
}
],
"button": [
{
"button_reduce": "Reduce"
}
]
}
License
All the files in this repository are completely free of rights (see the license) so you can grab the code and do whatever you want with them (just respect the license).
Thanks for reading and good development!
Disk_MTH
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tradlib-0.4.tar.gz.
File metadata
- Download URL: tradlib-0.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbc1fadd3cd2886d0813f42661a4449f83faaaa7d2190dd4a871da0a253b1945
|
|
| MD5 |
bb662ca7bb24bc0dfb01213178cbd386
|
|
| BLAKE2b-256 |
963e52c668ec746cc774c787181cd4c8b34b6a57839498295fb7f438032ffab7
|
File details
Details for the file tradlib-0.4-py3-none-any.whl.
File metadata
- Download URL: tradlib-0.4-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b327f0a591da2a4224df24878f368e0b9775846ac334541211ac180def5c371
|
|
| MD5 |
30b4db68a21774bbe37366d9ede8dbf9
|
|
| BLAKE2b-256 |
bc272019c988b2b2264611c7ca2c5e558dcd190b272efa7e8cd7d4d3931b5897
|