Skip to main content

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

  1. 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)

  1. 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.

  1. 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
  1. get_translation_files_extension()

This function return your selected extension for translation files. Default is ".lang".

  1. 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.

  1. 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.

  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradlib-0.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradlib-0.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file tradlib-0.3.tar.gz.

File metadata

  • Download URL: tradlib-0.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for tradlib-0.3.tar.gz
Algorithm Hash digest
SHA256 89507203aad31d62ebf5648f40f2f0d36317e799c2cc9f9861d1b62d656313a2
MD5 ca696e1a3bd966b827ce78ff892fb298
BLAKE2b-256 3f25099a2530db004eebf998463d02b235c7723d079ca5c1cea0315509ccc7e8

See more details on using hashes here.

File details

Details for the file tradlib-0.3-py3-none-any.whl.

File metadata

  • Download URL: tradlib-0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.0

File hashes

Hashes for tradlib-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 80d497d6b8d8219f91fe039d25feeab9a1d82f68dd1f68b229bc5193afa51001
MD5 0752e35367643d5d808e7b89ca20cabb
BLAKE2b-256 31ab29b68cb0ad6736d14779fd0499b4260729838bfafc4937698702a81f11d9

See more details on using hashes here.

Supported by

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